List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:org.eclipse.jem.internal.proxy.remote.LocalFileConfigurationContributorController.java
License:Open Source License
public void contributeProject(IProject project) throws CoreException { IJavaProject jproject = JavaCore.create(project); IRuntimeClasspathEntry[] projPath = JavaRuntime.computeUnresolvedRuntimeClasspath(jproject); boolean jreContainerFound = false; for (int i = 0; i < projPath.length; i++) { IRuntimeClasspathEntry entry = projPath[i]; if (entry.getClasspathProperty() == IRuntimeClasspathEntry.BOOTSTRAP_CLASSES || entry.getClasspathProperty() == IRuntimeClasspathEntry.STANDARD_CLASSES) { int entryKind = entry.getClasspathEntry().getEntryKind(); String segment0 = entry.getPath().segment(0); if (entryKind == IClasspathEntry.CPE_CONTAINER && JavaRuntime.JRE_CONTAINER.equals(segment0) || entryKind == IClasspathEntry.CPE_VARIABLE && JavaRuntime.JRELIB_VARIABLE.equals(segment0)) { jreContainerFound = true; } else { if (jreContainerFound) addLocations(getAppendBootpath(), JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject)); else addLocations(getPrependBootpath(), JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject)); }//from w w w.ja v a 2 s . c o m } else { addLocations(getClasspath(), JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject)); } } }
From source file:org.eclipse.jem.workbench.utility.JavaModelListener.java
License:Open Source License
protected boolean isInClasspath(IJavaProject testProject, IJavaProject targetProject, boolean isFirstLevel, Set visited) {//from w w w . jav a 2s . com if (visited.contains(targetProject)) return false; visited.add(targetProject); IClasspathEntry[] entries = null; try { entries = targetProject.getRawClasspath(); } catch (JavaModelException e) { return false; } List projects = null; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry; entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IJavaProject entryProject = getVisibleJavaProject(entry, isFirstLevel); if (entryProject != null) { if (entryProject.equals(testProject)) { return true; } else { if (projects == null) { projects = new ArrayList(); } projects.add(entryProject); } } break; //A container may contain references to projects. case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = null; try { container = JavaCore.getClasspathContainer(entry.getPath(), targetProject); } catch (JavaModelException e) { JEMPlugin.getPlugin().getLogger().logError(e); } if (container == null || container.getKind() != IClasspathContainer.K_APPLICATION) break; //First see if we already resolved IClasspathEntry[] containerEntries = null; containerEntries = (IClasspathEntry[]) resolvedContainers.get(container); if (containerEntries == null) { containerEntries = container.getClasspathEntries(); resolvedContainers.put(container, containerEntries); } for (int j = 0; j < containerEntries.length; j++) { if (containerEntries[j].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject conEntryProject = getVisibleJavaProject(containerEntries[j], isFirstLevel); if (conEntryProject != null) { if (conEntryProject.equals(testProject)) { return true; } else { if (projects == null) { projects = new ArrayList(); } projects.add(conEntryProject); } } } } break; } } return isInClasspath(testProject, projects, false, visited); }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
private static void collectClasspathURLs(IJavaProject javaProject, List urls, Set visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;/*from ww w . j av a 2s. c o m*/ visited.add(javaProject); IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject()); outPath = outPath.addTrailingSeparator(); URL out = ProjectUtilities.createFileURL(outPath); urls.add(out); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return; } IClasspathEntry entry; for (int i = 0; i < entries.length; i++) { entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathURLs(getJavaProject(entry), urls, visited, false); break; } } } }
From source file:org.eclipse.jpt.jaxb.core.internal.gen.ClassesGenerator.java
License:Open Source License
private List<IRuntimeClasspathEntry> getContainersClasspathEntries() throws CoreException { ArrayList<IRuntimeClasspathEntry> classpathEntries = new ArrayList<IRuntimeClasspathEntry>(); for (IClasspathEntry classpathEntry : this.getJavaProject().getRawClasspath()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntry.getPath(), this.getJavaProject()); if (container != null && container.getKind() == IClasspathContainer.K_SYSTEM) { classpathEntries.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES, this.getJavaProject())); }//from ww w. ja v a2 s .com } } return classpathEntries; }
From source file:org.eclipse.jst.common.jdt.internal.classpath.ClasspathUtil.java
License:Open Source License
public static Set getResolvedClasspath(final IJavaProject jproj, final Set entriesToIgnore) { final Set resolved = new HashSet(); try {/*from w w w . j a v a 2 s. com*/ final IClasspathEntry[] entries = jproj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entriesToIgnore.contains(entry.getPath())) { continue; } switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_PROJECT: { resolved.add(entry.getPath()); break; } case IClasspathEntry.CPE_VARIABLE: { entry = JavaCore.getResolvedClasspathEntry(entry); if (entry != null) { resolved.add(entry.getPath()); } break; } case IClasspathEntry.CPE_CONTAINER: { final IClasspathContainer container; try { container = JavaCore.getClasspathContainer(entry.getPath(), jproj); } catch (JavaModelException e) { Logger.getLogger().logError(e); continue; } if (container != null) { final IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int j = 0; j < containerEntries.length; j++) { resolved.add(containerEntries[j].getPath()); } } } } } } catch (JavaModelException e) { Logger.getLogger().logError(e); } return resolved; }
From source file:org.eclipse.jst.common.project.facet.core.internal.JavaFacetUtil.java
License:Open Source License
private static void removeJreContainer(final IProject proj) throws CoreException { final IJavaProject jproj = JavaCore.create(proj); final IClasspathEntry[] cp = jproj.getRawClasspath(); int pos = -1; for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER && cpe.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)) { pos = i;// ww w . jav a 2s.co m break; } } if (pos == -1) { return; } final IClasspathEntry[] newcp = new IClasspathEntry[cp.length - 1]; System.arraycopy(cp, 0, newcp, 0, pos); System.arraycopy(cp, pos + 1, newcp, pos, newcp.length - pos); jproj.setRawClasspath(newcp, null); }
From source file:org.eclipse.jst.common.project.facet.core.libprov.user.UserLibraryProviderInstallOperationConfig.java
License:Open Source License
/** * Resets this operation config to its initial state (prior to any user changes). *//*from w w w . jav a 2 s .com*/ @Override public synchronized void reset() { final IProject project = getFacetedProject().getProject(); final IProjectFacet f = getProjectFacet(); final IProjectFacetVersion fv = getProjectFacetVersion(); List<String> newLibraryNames = null; if (project != null) { final ILibraryProvider currentProvider = LibraryProviderFramework.getCurrentProvider(project, f); if (currentProvider == getLibraryProvider()) { final List<IClasspathEntry> entries; try { entries = ClasspathUtil.getClasspathEntries(project, f); } catch (CoreException e) { throw new RuntimeException(e); } final List<String> libraryNamesList = new ArrayList<String>(); for (IClasspathEntry cpe : entries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { final IPath path = cpe.getPath(); if (path.segmentCount() >= 2 && path.segment(0).equals(JavaCore.USER_LIBRARY_CONTAINER_ID)) { libraryNamesList.add(path.segment(1)); } } } newLibraryNames = libraryNamesList; } } if (newLibraryNames == null) { newLibraryNames = new ArrayList<String>(); try { Preferences prefs = FacetedProjectFramework.getPreferences(f); if (prefs.nodeExists(PREFS_LAST_USED_LIBRARIES)) { prefs = prefs.node(PREFS_LAST_USED_LIBRARIES); if (prefs.nodeExists(fv.getVersionString())) { prefs = prefs.node(fv.getVersionString()); for (String libraryName : prefs.childrenNames()) { newLibraryNames.add(libraryName); } } } } catch (BackingStoreException e) { log(e); } } setLibraryNames(newLibraryNames); }
From source file:org.eclipse.jst.j2ee.application.internal.operations.ClassPathSelection.java
License:Open Source License
private ClasspathElement createClasspathElementForEntry(final IProject project, final IClasspathEntry entry) { final IPath entryPath = entry.getPath(); final URI archiveURI = URI.createURI(entryPath.toString()); final int kind = entry.getEntryKind(); String elementName = entryPath.toString(); if (kind == IClasspathEntry.CPE_CONTAINER) { try {//from w w w . j av a 2s. c om final IClasspathContainer container = JavaCore.getClasspathContainer(entryPath, JavaCore.create(project)); if (container != null) { elementName = container.getDescription(); } } catch (CoreException ce) { } } ClasspathElement element = createClasspathEntryElement(project, archiveURI, elementName, entry); return element; }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
/** * Returns all resolved classpath entries for the specified Java project that * have one of the special WTP classpath component dependency attributes. * /* w w w.j a v a 2s.c o m*/ * @param javaProject Java project whose component classpath dependencies are being retrieved. * @param isWebApp True if the target project is associated with a web project. * @param onlyValid If true, only valid dependencies will be returned. If false, the raw entry must be valid but the * resolved can be invalid. * @return Map from IClasspathEntry to IClasspathAttribute for classpath component dependencies. * @throws CoreException Thrown if an error is encountered accessing the unresolved classpath. */ public static Map<IClasspathEntry, IClasspathAttribute> getComponentClasspathDependencies( final IJavaProjectLite javaProjectLite, final boolean isLegacyJ2EE, final boolean onlyValid) throws CoreException { final ClasspathDependencyValidatorData data = new ClasspathDependencyValidatorData( javaProjectLite.getProject()); final boolean isWebApp = JavaEEProjectUtilities.isDynamicWebProject(javaProjectLite.getProject()); // get the raw entries final Map<IClasspathEntry, IClasspathAttribute> referencedRawEntries = getRawComponentClasspathDependencies( javaProjectLite, DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY, isLegacyJ2EE); final Map<IClasspathEntry, IClasspathAttribute> validRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>(); final Map<IClasspathEntry, IClasspathAttribute> validRawClassPathContainerEntries = new HashMap<IClasspathEntry, IClasspathAttribute>(); // filter out non-valid referenced raw entries final Iterator<IClasspathEntry> i = referencedRawEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = i.next(); final IClasspathAttribute attrib = referencedRawEntries.get(entry); if (isValid(entry, attrib, isWebApp, javaProjectLite.getProject(), data)) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { //Put in a separate map the classpath container entries, since they will be handled differently validRawClassPathContainerEntries.put(entry, attrib); } else { validRawEntries.put(entry, attrib); } } } // if we have no valid raw entries, return empty map if (validRawEntries.isEmpty() && validRawClassPathContainerEntries.isEmpty()) { return Collections.emptyMap(); } // XXX Would like to replace the code below with use of a public JDT API that returns // the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995) // The code must currently leverage IPackageFragmentRoot to determine this // mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior // call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to // support retrieval using the resolved IPackageFragmentRoot // retrieve the resolved classpath //TODO this call to javaProject needs to be removed. Need to figure out what exactly this is attempting to do. IJavaProject javaProject = JavaCore.create(javaProjectLite.getProject()); //TODO this call to javaProject needs to be removed. Need to figure out what exactly this is attempting to do. final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); final Map<IPath, IClasspathEntry> pathToResolvedEntry = new HashMap<IPath, IClasspathEntry>(); // store in a map from path to entry for (int j = 0; j < entries.length; j++) { pathToResolvedEntry.put(entries[j].getPath(), entries[j]); } //Gather all resolved entries from the package roots and the classpath containers final Map<IClasspathEntry, IClasspathAttribute> resolvedEntries = new LinkedHashMap<IClasspathEntry, IClasspathAttribute>(); // grab all IPackageFragmentRoots // TODO this ignores project cp entries; can easily add in the raw project cp entries, however, do not have a good way to // map project cp entries resolved from cp containers back to the corresponding raw entry (and thereby determine if the // entry has the publish/export attribute) //TODO this call to javaProject needs to be removed. Need to figure out what exactly this is attempting to do. final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { final IClasspathEntry rawEntry = root.getRawClasspathEntry(); // is the raw entry valid? IClasspathAttribute attrib = validRawEntries.get(rawEntry); if (attrib == null) { continue; } final IPath pkgFragPath = root.getPath(); final IClasspathEntry resolvedEntry = pathToResolvedEntry.get(pkgFragPath); resolvedEntries.put(resolvedEntry, attrib); } // Add entries coming from classpath containers to the list of resolved entries for (Map.Entry<IClasspathEntry, IClasspathAttribute> entry : validRawClassPathContainerEntries.entrySet()) { IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(entry.getKey().getPath(), javaProject); if (classpathContainer != null) { IClasspathEntry[] classpathContainerEntries = classpathContainer.getClasspathEntries(); if (classpathContainerEntries != null) { for (int j = 0; j < classpathContainerEntries.length; j++) { resolvedEntries.put(classpathContainerEntries[j], entry.getValue()); } } } } //Setup the final result final Map<IClasspathEntry, IClasspathAttribute> referencedEntries = new LinkedHashMap<IClasspathEntry, IClasspathAttribute>(); for (Map.Entry<IClasspathEntry, IClasspathAttribute> mapEntry : resolvedEntries.entrySet()) { final IClasspathEntry resolvedEntry = mapEntry.getKey(); IClasspathAttribute attrib = mapEntry.getValue(); final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry, DependencyAttributeType.DEPENDENCY_OR_NONDEPENDENCY, isLegacyJ2EE); // attribute for the resolved entry must either be unspecified or it must be the // dependency attribute for it to be included if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { // filter out resolved entry if it doesn't pass the validation rules if (!onlyValid || isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp, javaProjectLite.getProject(), data)) { if (resolvedAttrib != null) { // if there is an attribute on the sub-entry, use that attrib = resolvedAttrib; } referencedEntries.put(resolvedEntry, attrib); } } } return referencedEntries; }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;// www . j a v a 2s . c om IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }