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.jdt.internal.core.JavaProject.java
License:Open Source License
public ResolvedClasspath resolveClasspath(IClasspathEntry[] rawClasspath, IClasspathEntry[] referencedEntries, boolean usePreviousSession, boolean resolveChainedLibraries) throws JavaModelException { JavaModelManager manager = JavaModelManager.getJavaModelManager(); ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager(); ResolvedClasspath result = new ResolvedClasspath(); Map knownDrives = new HashMap(); Map referencedEntriesMap = new HashMap(); List rawLibrariesPath = new ArrayList(); LinkedHashSet resolvedEntries = new LinkedHashSet(); if (resolveChainedLibraries) { for (int index = 0; index < rawClasspath.length; index++) { IClasspathEntry currentEntry = rawClasspath[index]; if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { rawLibrariesPath/*w ww . java 2s . co m*/ .add(ClasspathEntry.resolveDotDot(getProject().getLocation(), currentEntry.getPath())); } } if (referencedEntries != null) { // The Set is required to keep the order intact while the referencedEntriesMap (Map) // is used to map the referenced entries with path LinkedHashSet referencedEntriesSet = new LinkedHashSet(); for (int index = 0; index < referencedEntries.length; index++) { IPath path = referencedEntries[index].getPath(); if (!rawLibrariesPath.contains(path) && referencedEntriesMap.get(path) == null) { referencedEntriesMap.put(path, referencedEntries[index]); referencedEntriesSet.add(referencedEntries[index]); } } if (referencedEntriesSet.size() > 0) { result.referencedEntries = new IClasspathEntry[referencedEntriesSet.size()]; referencedEntriesSet.toArray(result.referencedEntries); } } } int length = rawClasspath.length; for (int i = 0; i < length; i++) { IClasspathEntry rawEntry = rawClasspath[i]; IClasspathEntry resolvedEntry = rawEntry; switch (rawEntry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: try { resolvedEntry = manager.resolveVariableEntry(rawEntry, usePreviousSession); } catch (ClasspathEntry.AssertionFailedException e) { // Catch the assertion failure and set status instead // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992 result.unresolvedEntryStatus = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage()); break; } if (resolvedEntry == null) { result.unresolvedEntryStatus = new JavaModelStatus( IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND, this, rawEntry.getPath()); } else { // If the entry is already present in the rawReversetMap, it means the entry and the chained libraries // have already been processed. So, skip it. if (resolveChainedLibraries && resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && result.rawReverseMap.get(resolvedEntry.getPath()) == null) { // resolve Class-Path: in manifest ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); for (int j = 0, length2 = extraEntries.length; j < length2; j++) { if (!rawLibrariesPath.contains(extraEntries[j].getPath())) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 // referenced entries for variable entries could also be persisted with extra attributes, so addAsChainedEntry = true addToResult(rawEntry, extraEntries[j], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, true, knownDrives); } } } addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false, knownDrives); } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = usePreviousSession ? manager.getPreviousSessionContainer(rawEntry.getPath(), this) : JavaCore.getClasspathContainer(rawEntry.getPath(), this); if (container == null) { result.unresolvedEntryStatus = new JavaModelStatus( IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND, this, rawEntry.getPath()); break; } IClasspathEntry[] containerEntries = container.getClasspathEntries(); if (containerEntries == null) { if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) { JavaModelManager.getJavaModelManager().verbose_missbehaving_container_null_entries(this, rawEntry.getPath()); } break; } // container was bound for (int j = 0, containerLength = containerEntries.length; j < containerLength; j++) { ClasspathEntry cEntry = (ClasspathEntry) containerEntries[j]; if (cEntry == null) { if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) { JavaModelManager.getJavaModelManager().verbose_missbehaving_container(this, rawEntry.getPath(), containerEntries); } break; } // if container is exported or restricted, then its nested entries must in turn be exported (21749) and/or propagate restrictions cEntry = cEntry.combineWith((ClasspathEntry) rawEntry); if (cEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // resolve ".." in library path cEntry = cEntry.resolvedDotDot(getProject().getLocation()); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=313965 // Do not resolve if the system attribute is set to false if (resolveChainedLibraries && JavaModelManager.getJavaModelManager().resolveReferencedLibrariesForContainers && result.rawReverseMap.get(cEntry.getPath()) == null) { // resolve Class-Path: in manifest ClasspathEntry[] extraEntries = cEntry.resolvedChainedLibraries(); for (int k = 0, length2 = extraEntries.length; k < length2; k++) { if (!rawLibrariesPath.contains(extraEntries[k].getPath())) { addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false, knownDrives); } } } } addToResult(rawEntry, cEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false, knownDrives); } break; case IClasspathEntry.CPE_LIBRARY: // resolve ".." in library path resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(getProject().getLocation()); if (resolveChainedLibraries && result.rawReverseMap.get(resolvedEntry.getPath()) == null) { // resolve Class-Path: in manifest ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); for (int k = 0, length2 = extraEntries.length; k < length2; k++) { if (!rawLibrariesPath.contains(extraEntries[k].getPath())) { addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, true, knownDrives); } } } addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false, knownDrives); break; default: addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false, knownDrives); break; } } result.resolvedClasspath = new IClasspathEntry[resolvedEntries.size()]; resolvedEntries.toArray(result.resolvedClasspath); return result; }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
static int kindFromString(String kindStr) { if (kindStr == null || kindStr.length() == 0) return BIE_PLUGIN; // Default to plugin. If coming from beaninfoconfig, there should always be kind. But if coming from plugin.xml there shouldn't be one. if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ return IClasspathEntry.CPE_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ return IClasspathEntry.CPE_LIBRARY; if (kindStr.equalsIgnoreCase("plugin")) //$NON-NLS-1$ return BIE_PLUGIN; return -1;// w w w . j a va 2s . c o m }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
static String kindToString(int kind) { switch (kind) { case IClasspathEntry.CPE_PROJECT: return "src"; // backward compatibility //$NON-NLS-1$ case IClasspathEntry.CPE_SOURCE: return "src"; //$NON-NLS-1$ case IClasspathEntry.CPE_LIBRARY: return "lib"; //$NON-NLS-1$ case IClasspathEntry.CPE_VARIABLE: return "var"; //$NON-NLS-1$ case IClasspathEntry.CPE_CONTAINER: return "con"; //$NON-NLS-1$ case BIE_PLUGIN: return "plugin"; //$NON-NLS-1$ default://from w w w .j a va 2 s .c o m return "unknown"; //$NON-NLS-1$ } }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
/** * Return the appropriate kind of entry when we know it is a classpath entry. *///from w w w . j a va 2 s . c o m public static IClasspathEntry createEntry(int kind, IPath path, IProject project, boolean isExported) { switch (kind) { case IClasspathEntry.CPE_LIBRARY: if (path.isAbsolute()) return JavaCore.newLibraryEntry(path, null, null, isExported); break; case IClasspathEntry.CPE_SOURCE: if (path.isAbsolute()) { // must be an entry in this project or specify another project String projSegment = path.segment(0); if (project != null && projSegment != null && projSegment.equals(project.getName())) { // this project return JavaCore.newSourceEntry(path); } else { // another project return JavaCore.newProjectEntry(path, isExported); } } break; case IClasspathEntry.CPE_VARIABLE: return JavaCore.newVariableEntry(path, null, null, isExported); case IClasspathEntry.CPE_CONTAINER: return JavaCore.newContainerEntry(path, isExported); } return null; }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
/** * Read the entry in from the element.//w w w. j a va 2 s. com */ public static BeaninfoEntry readEntry(IReader reader, Object element, IProject project) { String elementKind = reader.getAttribute(element, BeaninfosDoc.sKind); String pathStr = reader.getAttribute(element, BeaninfosDoc.sPath); // ensure path is absolute IPath path = new Path(pathStr); int kind = kindFromString(elementKind); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && kind != BIE_PLUGIN && !path.isAbsolute()) { path = project != null ? project.getFullPath().append(path) : path.makeAbsolute(); // Some folder/jar within this project } // exported flag String exportedString = reader.getAttribute(element, BeaninfosDoc.sExported); boolean isExported = "true".equalsIgnoreCase(exportedString); //$NON-NLS-1$ //$NON-NLS-1$ // recreate the entry IClasspathEntry cpEntry = null; IPath pluginPath = null; if (kind != BIE_PLUGIN) { cpEntry = createEntry(kind, path, project, isExported); } else { if (path.isAbsolute()) pluginPath = path; else { // Kludge This should only be a plugin type if from configuration element. So we will cast to that // and get the plugin id to create an absolute plugin path. if (element instanceof IConfigurationElement) { pluginPath = new Path('/' + ((IConfigurationElement) element).getDeclaringExtension().getContributor().getName()) .append(path); } else return null; // Not valid because can't have plugin from .beaninfoconfig file. } } ArrayList searchpaths = new ArrayList(); Object children = reader.getChildren(element); int childrenLength = reader.getLength(children); for (int i = 0; i < childrenLength; i++) { Object child = reader.getItem(children, i); if (reader.isNodeTypeElement(child)) { Object entry = null; if (reader.getNodeName(child).equalsIgnoreCase(SearchpathEntry.sSearchpath)) { entry = SearchpathEntry.readEntry(reader, child, project, true); } if (entry != null) searchpaths.add(entry); } } if (cpEntry != null) return new BeaninfoEntry(cpEntry, (SearchpathEntry[]) searchpaths.toArray(new SearchpathEntry[searchpaths.size()]), isExported); else return new BeaninfoEntry(pluginPath, (SearchpathEntry[]) searchpaths.toArray(new SearchpathEntry[searchpaths.size()]), isExported); }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
public Node writeEntry(Document doc, IProject project) { Element element = doc.createElement(sBeaninfo); IPath path = null;/*from w w w . j a v a 2 s. c o m*/ if (entry != null) { element.setAttribute(BeaninfosDoc.sKind, kindToString(entry.getEntryKind())); path = entry.getPath(); if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE && entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { // translate to project relative from absolute (unless a device path) if (path.isAbsolute()) { if (path.segment(0).equals(project.getFullPath().segment(0))) { path = path.removeFirstSegments(1); path = path.makeRelative(); } else { path = path.makeAbsolute(); } } } } else { element.setAttribute(BeaninfosDoc.sKind, kindToString(BIE_PLUGIN)); path = pluginPath; } element.setAttribute(BeaninfosDoc.sPath, path.toString()); //$NON-NLS-1$ if (isExported()) { element.setAttribute(BeaninfosDoc.sExported, "true"); //$NON-NLS-1$ } for (int i = 0; i < searchpaths.length; i++) { SearchpathEntry spe = searchpaths[i]; element.appendChild(spe.writeEntry(doc, project)); } return element; }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
private void resolveEntry(IWorkspaceRoot root, List paths, IClasspathEntry entry, IJavaProject javaProject) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IProject reqProject = (IProject) root.findMember(entry.getPath().lastSegment()); // Project entries only have one segment. if (reqProject != null && reqProject.isOpen()) paths.add(reqProject);/*from w ww . j a va 2s. co m*/ break; case IClasspathEntry.CPE_SOURCE: reqProject = (IProject) root.findMember(entry.getPath().segment(0)); // Find project from the first segment. IJavaProject jProject = JavaCore.create(reqProject); if (jProject != null) { try { IPath outputLocation = jProject.getOutputLocation(); IResource resource = root.findMember(outputLocation); if (resource != null) { paths.add(resource.getLocation().toString()); } } catch (JavaModelException e) { } } break; case IClasspathEntry.CPE_LIBRARY: IResource library = root.findMember(entry.getPath()); // can be external or in workspace paths.add((library != null) ? library.getLocation().toString() : entry.getPath().toString()); break; case IClasspathEntry.CPE_CONTAINER: try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { resolveEntry(root, paths, entries[i], javaProject); } } } catch (JavaModelException e) { BeaninfoPlugin.getPlugin().getLogger().log(e, Level.WARNING); } } }
From source file:org.eclipse.jem.internal.beaninfo.core.SearchpathEntry.java
License:Open Source License
/** * Read the entry in from the element.//from w w w. java2 s . c om */ public static SearchpathEntry readEntry(IReader reader, Object element, IProject project, boolean beaninfoChild) { String packageName = reader.getAttribute(element, sPackage); if (beaninfoChild) return new SearchpathEntry(packageName); // Kind/path aren't valid on beaninfo children. String elementKind = reader.getAttribute(element, BeaninfosDoc.sKind); String pathStr = reader.getAttribute(element, BeaninfosDoc.sPath); int kind = BeaninfoEntry.kindFromString(elementKind); IPath path = null; if (pathStr != null) { // ensure path is absolute path = new Path(pathStr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { path = project != null ? project.getFullPath().append(path) : path.makeAbsolute(); // Some folder/jar within this project } } // create the appropriate entry boolean valid = true; switch (kind) { case IClasspathEntry.CPE_LIBRARY: valid = path != null && path.isAbsolute(); break; case IClasspathEntry.CPE_SOURCE: if (path == null) valid = false; else if (path.isAbsolute()) { // must be an entry in this project or specify another project String projSegment = path.segment(0); if (project == null || projSegment == null || !projSegment.equals(project.getName())) { // another project kind = IClasspathEntry.CPE_PROJECT; } } break; case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: break; default: valid = false; break; } if (valid) return new SearchpathEntry(kind, path, packageName); else return null; }
From source file:org.eclipse.jem.internal.beaninfo.core.SearchpathEntry.java
License:Open Source License
public Node writeEntry(Document doc, IProject project) { Element element = doc.createElement(sSearchpath); if (kind != -1) { // A non-beaninfo child element.setAttribute(BeaninfosDoc.sKind, BeaninfoEntry.kindToString(kind)); IPath tPath = path;//from w w w. j av a 2 s .c o m if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER) { // translate to project relative from absolute (unless a device path) if (tPath.isAbsolute()) { if (tPath.segment(0).equals(project.getFullPath().segment(0))) { tPath = tPath.removeFirstSegments(1); tPath = tPath.makeRelative(); } else { tPath = tPath.makeAbsolute(); } } } element.setAttribute(BeaninfosDoc.sPath, tPath.toString()); } if (packageName != null) element.setAttribute(sPackage, packageName); return element; }
From source file:org.eclipse.jem.internal.proxy.core.ProxyPlugin.java
License:Open Source License
private void expandProject(IPath projectPath, FoundIDs foundIds, boolean visible, boolean first) throws JavaModelException { IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath.lastSegment()); if (res == null) return; // Not exist so don't delve into it. IJavaProject project = (IJavaProject) JavaCore.create(res); if (project == null || !project.exists() || !project.getProject().isOpen()) return; // Not exist as a java project or not open, so don't delve into it. IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; Boolean currentFlag = null; // Current setting value. boolean newFlag; // The new setting value. switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.projects.get(entry.getPath()); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.projects.put(entry.getPath(), newFlag ? Boolean.TRUE : Boolean.FALSE); if (currentFlag == null) expandProject(entry.getPath(), foundIds, visible && entry.isExported(), false); break; case IClasspathEntry.CPE_CONTAINER: if (!first && JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) //$NON-NLS-1$ break; // The first project determines the JRE, so any subsequent ones can be ignored. Map[] paths = (Map[]) foundIds.containerIds.get(entry.getPath().segment(0)); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(entry.getPath().segment(0), paths); }//from w ww . j a v a 2 s . co m currentFlag = null; if (paths[0].containsKey(entry.getPath())) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(entry.getPath())) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(entry.getPath()); paths[0].put(entry.getPath(), entry.getPath().toString()); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(entry.getPath()); paths[1].put(entry.getPath(), entry.getPath().toString()); } } IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.containers.get(container); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.containers.put(container, newFlag ? Boolean.TRUE : Boolean.FALSE); break; case IClasspathEntry.CPE_VARIABLE: // We only care about JRE_LIB. If we have that, then we will treat it as JRE_CONTAINER. Only // care about first project too, because the first project is the one that determines the JRE type. if (first && JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { //$NON-NLS-1$ paths = (Map[]) foundIds.containerIds.get(JavaRuntime.JRE_CONTAINER); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(JavaRuntime.JRE_CONTAINER, paths); } currentFlag = null; if (paths[0].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(JRE_CONTAINER_PATH); paths[0].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(JRE_CONTAINER_PATH); paths[1].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } } } break; default: break; } } findPlugins(foundIds, visible, first, project); }