List of usage examples for org.eclipse.jdt.internal.core JavaProject resolveClasspath
public void resolveClasspath(PerProjectInfo perProjectInfo, boolean usePreviousSession, boolean addClasspathChange) throws JavaModelException
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static List<IClasspathEntry> resolveDependentProjectClasspath(IClasspathEntry projEntry, IProject requiredProj) {// w w w . j a v a 2 s . com // add all output locations and exported classpath entities // AspectJ compiler doesn't understand the concept of a java project List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); try { JavaProject requiredJavaProj = (JavaProject) JavaCore.create(requiredProj); // bug 288395 Do not use the default mechanism for resolving classpath here // this will look into jar files at the Classpath header in the jar's manifest // and include jar files that are potentially missing, but have no effect on // the build. Object resolvedClasspath = requiredJavaProj.resolveClasspath(requiredJavaProj.getRawClasspath(), true, false); IClasspathEntry[] requiredEntries = extractRequiredEntries(resolvedClasspath); for (int i = 0; i < requiredEntries.length; i++) { IClasspathEntry requiredEntry = requiredEntries[i]; if (requiredEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // always add source entries even if not explicitly exported // don't add the source folder itself, but instead add the outfolder IPath outputLocation = requiredEntry.getOutputLocation(); if (outputLocation != null) { IAccessRule[] rules = projEntry.getAccessRules(); IClasspathAttribute[] attributes = projEntry.getExtraAttributes(); // only add the out folder if it already exists if (requiredProj.getFolder(outputLocation.removeFirstSegments(1)).exists()) { IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation, requiredEntry.getPath(), requiredProj.getFullPath(), rules, attributes, projEntry.isExported()); actualEntries.add(outFolder); } } } else if (requiredEntry.isExported()) { // must recur through this entry and add entries that it contains actualEntries.addAll(resolveClasspath(requiredEntry, requiredProj)); } } // for (int i = 0; i < requiredEntries.length; i++) IPath outputLocation = requiredJavaProj.getOutputLocation(); // Output location may not exist. Do not put output location of required project // on path unless it exists boolean exists = false; // bug 244330 check to see if the project folder is also the output folder if (outputLocation.segmentCount() == 1) { exists = true; } else { if (requiredProj.getWorkspace().getRoot().getFolder(outputLocation).exists()) { exists = true; } } if (exists) { IClasspathEntry outFolder = JavaCore.newLibraryEntry(outputLocation, null, requiredProj.getFullPath()); actualEntries.add(outFolder); } } catch (JavaModelException e) { } return actualEntries; }