List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT
int CPE_PROJECT
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.
Click Source Link
From source file:org.eclipse.acceleo.ide.ui.resources.AcceleoProject.java
License:Open Source License
/** * Computes the URIs of all the accessible output files (EMTL) in the dependencies of the current project. * It browses the resolved classpath of the java project, and keeps each entry of type * 'IClasspathEntry.CPE_PROJECT'.//w w w .j a v a2s. c om * * @param outputURIs * is an output parameter with all the URIs * @param aProject * is the current project */ private void computeAccessibleOutputFilesWithProjectDependencies(List<URI> outputURIs, IProject aProject) { final IJavaProject javaProject = JavaCore.create(aProject); IClasspathEntry[] entries; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e1) { AcceleoUIActivator.getDefault().getLog().log(e1.getStatus()); entries = new IClasspathEntry[] {}; } for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().toString()); if (requiredProject != null && requiredProject.exists()) { computeAccessibleOutputFilesInFolder(outputURIs, getOutputFolder(requiredProject)); } } } }
From source file:org.eclipse.acceleo.ide.ui.resources.AcceleoProject.java
License:Open Source License
/** * Computes all the accessible projects. * /* w ww . j a v a 2s. c om*/ * @param accessibleProjects * is the output list that will contain all the accessible projects * @param current * is the current project */ private void computeAccessibleProjects(List<IProject> accessibleProjects, IProject current) { if (!accessibleProjects.contains(current)) { accessibleProjects.add(current); IPluginModelBase plugin = PluginRegistry.findModel(current); if (plugin != null && plugin.getBundleDescription() != null) { BundleDescription[] requiredPlugins = plugin.getBundleDescription().getResolvedRequires(); for (int i = 0; i < requiredPlugins.length; i++) { String requiredSymbolicName = requiredPlugins[i].getSymbolicName(); IProject requiredProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(requiredSymbolicName); if (requiredProject != null && requiredProject.isAccessible()) { computeAccessibleProjects(accessibleProjects, requiredProject); } } } final IJavaProject javaProject = JavaCore.create(current); IClasspathEntry[] entries; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e1) { AcceleoUIActivator.getDefault().getLog().log(e1.getStatus()); entries = new IClasspathEntry[] {}; } for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().toString()); if (requiredProject != null && requiredProject.exists()) { computeAccessibleProjects(accessibleProjects, requiredProject); } } } } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the aspect path *//*from w ww. j a v a 2 s . co m*/ public static boolean isOnAspectpath(IProject project, String path) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(path)) { if (isOnAspectpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static List<IClasspathEntry> resolveClasspathContainer(IClasspathEntry classpathContainerEntry, IProject thisProject) throws JavaModelException { IJavaProject thisJavaProject = JavaCore.create(thisProject); IClasspathContainer container = JavaCore.getClasspathContainer(classpathContainerEntry.getPath(), thisJavaProject);//from w w w. j a va 2 s . c o m if (container != null) { List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int i = 0; i < containerEntries.length; i++) { // projects must be resolved specially since the AspectJ doesn't understand the // concept of project switch (containerEntries[i].getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IProject requiredProj = thisProject.getWorkspace().getRoot() .getProject(containerEntries[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(thisProject.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(containerEntries[i], requiredProj)); } break; case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore .getResolvedClasspathEntry(containerEntries[i]); if (resolvedClasspathEntry != null) { actualEntries.add(resolvedClasspathEntry); } break; case IClasspathEntry.CPE_CONTAINER: // not sure if we can have this, but try anyway actualEntries.addAll(resolveClasspathContainer(containerEntries[i], thisProject)); break; case IClasspathEntry.CPE_LIBRARY: actualEntries.add(containerEntries[i]); break; default: // do nothing } } return actualEntries; } else { return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Resolves a single classpath entry/*from w w w.j av a 2 s. c om*/ * @param entry the classpath entry to resolve * @param thisProject the java project that has this entry * @return the resolved list of classpath entries * @throws JavaModelException */ public static List<IClasspathEntry> resolveClasspath(IClasspathEntry entry, IProject thisProject) throws JavaModelException { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: return resolveClasspathContainer(entry, thisProject); case IClasspathEntry.CPE_LIBRARY: return Collections.singletonList(entry); case IClasspathEntry.CPE_PROJECT: IProject containedProj = thisProject.getWorkspace().getRoot() .getProject(entry.getPath().makeRelative().toPortableString()); if (!containedProj.getName().equals(thisProject.getName()) && containedProj.exists()) { return resolveDependentProjectClasspath(entry, containedProj); } else { return Collections.emptyList(); } case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(entry); if (resolvedClasspathEntry != null) { return Collections.singletonList(resolvedClasspathEntry); } else { return Collections.emptyList(); } default: return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the Inpath */// w w w. ja v a 2 s .co m public static boolean isOnInpath(IProject project, String jarPath) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(jarPath)) { if (isOnInpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project//w ww . j a va2 s . co m * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }
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]); }/*ww w.j a va 2 s .c om*/ 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 ww . ja v a 2 s . 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]; 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 {//from www. j a va 2 s .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) { } }