List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static String[] internalGetProjectPath(IProject project, IClasspathAttribute attribute, boolean useResolvedPath) { if (isAspectPathAttribute(attribute)) { if (shouldCheckOldStylePath(project, ASPECTPATH)) { String[] old = getOldProjectPath(project, true); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectAspectPath(project, old[0], old[1], old[2]); }//from w w w . ja v a 2 s . c o m markOldStylePathAsRead(project, ASPECTPATH); } } else { // INPATH_ATTRIBUTE if (shouldCheckOldStylePath(project, INPATH)) { String[] old = getOldProjectPath(project, false); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectInPath(project, old[0], old[1], old[2]); } markOldStylePathAsRead(project, INPATH); } } String pathString = ""; //$NON-NLS-1$ String contentString = ""; //$NON-NLS-1$ String entryString = ""; //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean attributeFound = false; for (int j = 0; j < attributes.length; j++) { if (attributes[j].getName().equals(attribute.getName())) { attributeFound = true; List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); if (useResolvedPath) { // this entry is on the path. must resolve it if (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); // Bug 273770 - look for the XXXPATH_RESTRICTION_ATTRIBUTE_NAME classpath attribute Set<String> extraPathElements = findContainerRestrictions(cp[i], isAspectPathAttribute(attribute)); if (extraPathElements != null && extraPathElements.size() > 0) { // must filter for (Iterator<IClasspathEntry> cpIter = containerEntries.iterator(); cpIter .hasNext();) { IClasspathEntry containerEntry = cpIter.next(); if (!containsAsPathFragment(extraPathElements, containerEntry)) { cpIter.remove(); } } } actualEntries.addAll(containerEntries); } else if (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProj = project.getWorkspace().getRoot() .getProject(cp[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(project.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(cp[i], requiredProj)); } } else { // resolve the classpath variable IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolved != null) { if (resolved.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // must resolve the project actualEntries.addAll( resolveDependentProjectClasspath(resolved, project.getWorkspace() .getRoot().getProject(resolved.getPath().toString()))); } else { actualEntries.add(resolved); } } } // cp[i].getEntryKind() } else { actualEntries.add(cp[i]); } // useResolvedEntry for (IClasspathEntry actualEntry : actualEntries) { // we can get null for actualEntry if the raw entry corresponds to // an unbound classpath variable if (actualEntry != null) { pathString += actualEntry.getPath().toPortableString() + File.pathSeparator; contentString += actualEntry.getContentKind() + File.pathSeparator; entryString += actualEntry.getEntryKind() + File.pathSeparator; } } } // attributes[j].equals(attribute) } // for (int j = 0; j < attributes.length; j++) // there is a special case that we must look inside the classpath container for entries with // attributes if we are returning the resolved path and the container itself isn't already // on the path. if (!attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); for (IClasspathEntry containerEntry : containerEntries) { if (isOnPath(containerEntry, isAspectPathAttribute(attribute))) { pathString += containerEntry.getPath().toPortableString() + File.pathSeparator; contentString += containerEntry.getContentKind() + File.pathSeparator; entryString += containerEntry.getEntryKind() + File.pathSeparator; } } // for (Iterator cpIter = containerEntries.iterator(); cpIter.hasNext(); ) } // !attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER } // for (int i = 0; i < cp.length; i++) } catch (JavaModelException e) { } return new String[] { pathString, contentString, entryString }; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static void addAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {/* w w w .j a va 2 s.c om*/ IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attr; switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static void removeAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {/* ww w .ja v a 2s.co m*/ IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attr.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Remove all occurrences of an attribute * @param javaProject/*from w w w . ja v a2s . co m*/ * @param attribute */ private static void removeAttribute(IJavaProject javaProject, IClasspathAttribute attribute) { try { IClasspathEntry[] cp = javaProject.getRawClasspath(); boolean changed = false; for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean found = false; for (int j = 0; !found && (j < attributes.length); j++) { if (attributes[j].getName().equals(attribute.getName())) { found = true; } } if (found) { changed = true; IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attribute.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } if (changed) { javaProject.setRawClasspath(cp, null); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static void addEntryToJavaBuildPath(IJavaProject jp, IClasspathAttribute attribute, String path, int eKind) { IClasspathAttribute[] attributes = new IClasspathAttribute[] { attribute }; try {// ww w . jav a 2 s . c om IClasspathEntry[] originalCP = jp.getRawClasspath(); IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; IClasspathEntry cp = null; if (eKind == IClasspathEntry.CPE_LIBRARY) { cp = JavaCore.newLibraryEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_VARIABLE) { cp = JavaCore.newVariableEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_CONTAINER) { cp = JavaCore.newContainerEntry(new Path(path), null, attributes, false); } else if (eKind == IClasspathEntry.CPE_PROJECT) { cp = JavaCore.newProjectEntry(new Path(path), null, true, attributes, false); } // Update the raw classpath with the new entry. if (cp != null) { System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); newCP[originalCP.length] = cp; jp.setRawClasspath(newCP, new NullProgressMonitor()); } } catch (JavaModelException e) { } catch (NumberFormatException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * If this classpath entry's path already exists on the classpath, then it is replaced * else it is added/*from www. ja va2 s. c o m*/ */ public static void updateClasspathEntry(IProject project, IClasspathEntry newEntry) { IJavaProject jProject = JavaCore.create(project); try { IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (newEntry.getPath().equals(entry.getPath())) { entries[i] = newEntry; jProject.setRawClasspath(entries, null); return; } } // entry not found on classpath...add it IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = newEntry; jProject.setRawClasspath(newEntries, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.BuildConfig.java
License:Open Source License
/** * Returns all of the currently included source files in a project * This list is cached and reset every build (or on request by calling flushIncludedSourceFileCache) * @param project/*from ww w .java2 s . co m*/ * @return a list of IFiles */ public static Set<IFile> getIncludedSourceFiles(IProject project) { if (projectsToIncludedSourceFiles.get(project) instanceof List) { return projectsToIncludedSourceFiles.get(project); } Set<IFile> sourceFiles = new HashSet<IFile>(); try { IJavaProject jp = JavaCore.create(project); IClasspathEntry[] cpes = jp.getRawClasspath(); for (int i = 0; i < cpes.length; i++) { if ((cpes[i] instanceof ClasspathEntry) && (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE)) { ClasspathEntry cp = (ClasspathEntry) cpes[i]; char[][] incl = cp.fullInclusionPatternChars(); char[][] excl = cp.fullExclusionPatternChars(); IPath path = cpes[i].getPath(); IResource res = project.findMember(path.removeFirstSegments(1)); if ((res != null) && (res instanceof IContainer)) { List<IFile> l = allFiles((IContainer) res); for (IFile file : l) { if (!Util.isExcluded(file, incl, excl)) { sourceFiles.add(file); } } } } } } catch (JavaModelException e) { } projectsToIncludedSourceFiles.put(project, sourceFiles); return sourceFiles; }
From source file:org.eclipse.ajdt.core.BuildConfig.java
License:Open Source License
/** * Experimental version of above that uses a set, not a list * @param project//from www. j a v a 2 s . c o m * @return */ public static Set<IFile> getIncludedSourceFilesSet(IProject project) { if (projectsToIncludedSourceFiles.get(project) instanceof List) { return projectsToIncludedSourceFiles.get(project); } Set<IFile> sourceFiles = new HashSet<IFile>(); try { IJavaProject jp = JavaCore.create(project); IClasspathEntry[] cpes = jp.getRawClasspath(); for (int i = 0; i < cpes.length; i++) { if ((cpes[i] instanceof ClasspathEntry) && (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE)) { ClasspathEntry cp = (ClasspathEntry) cpes[i]; char[][] incl = cp.fullInclusionPatternChars(); char[][] excl = cp.fullExclusionPatternChars(); IPath path = cpes[i].getPath(); IResource res = project.findMember(path.removeFirstSegments(1)); if ((res != null) && (res instanceof IContainer)) { List<IFile> l = allFiles((IContainer) res); for (IFile file : l) { if (!Util.isExcluded(file, incl, excl)) { sourceFiles.add(file); } } } } } } catch (JavaModelException e) { } projectsToIncludedSourceFiles.put(project, sourceFiles); return sourceFiles; }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * Returns the CPE_SOURCE classpath entries for the given IJavaProject * //from w w w. ja v a2s. c o m * @param IJavaProject */ private IClasspathEntry[] getSrcClasspathEntry(IJavaProject javaProject) throws JavaModelException { List<IClasspathEntry> srcEntries = new ArrayList<IClasspathEntry>(); if (javaProject == null) { return new IClasspathEntry[0]; } IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcEntries.add(entry); } } return (IClasspathEntry[]) srcEntries.toArray(new IClasspathEntry[srcEntries.size()]); }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
private void migrateToRTContainerIfNecessary(IJavaProject javaProject) { if (!AspectJRTInitializer.hasBeenUsed) { // if the old ASPECTJRT_LIB var hasn't been initialized // then there definitely won't be anything to migrate return;//from ww w .j av a 2s . c om } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String var = entries[i].getPath().segment(0); if (var.equals("ASPECTJRT_LIB")) { //$NON-NLS-1$ // replace with AspectJRT container entries[i] = JavaCore.newContainerEntry(new Path(AspectJPlugin.ASPECTJRT_CONTAINER), false); javaProject.setRawClasspath(entries, new NullProgressMonitor()); return; } } } } catch (JavaModelException e) { } }