List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE
int CPE_VARIABLE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE.
Click Source Link
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;//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.SearchpathEntry.java
License:Open Source License
/** * Read the entry in from the element.//from ww w.ja v a 2 s. c o m */ 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;// www . j a v a 2 s.co 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); }/*w w w .j a va 2s . c om*/ 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); }
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 ww . j a v a 2s.c o m*/ } else { addLocations(getClasspath(), JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject)); } } }
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 w ww . j a v a2s .co 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.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 ww w . j a v a 2 s . c om*/ 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.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;//from www. j a va 2 s . co m 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; }
From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java
License:Open Source License
/** * Updates the specified Java project so that only the specified classpath entries have * the WTP component dependency attribute. * @param javaProject Target Java project. * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry * to the IClasspathAttribute for the WTP classpath component dependency. * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute. * @throws CoreException Thrown if an error is encountered. *///from www . ja v a2s .c o m private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib, final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) { return; } final List updatedClasspath = new ArrayList(); final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean needToUpdateClasspath = false; IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute(); if (!modifyComponentDep) { attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); } for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry entry = rawClasspath[i]; final int kind = entry.getEntryKind(); boolean hasAttribute = ClasspathDependencyUtil .checkForComponentDependencyAttribute(entry, modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY, isLegacyJ2EE) != null; boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry); boolean updateAttributes = false; IClasspathAttribute[] updatedAttributes = null; if (shouldHaveAttribute) { if (!hasAttribute) { // should have the attribute and currently missing it attrib = (IClasspathAttribute) entriesWithAttrib.get(entry); updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true); needToUpdateClasspath = true; updateAttributes = true; } } else if (hasAttribute) { // should not have the attribute and currently has it updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false); needToUpdateClasspath = true; updateAttributes = true; } if (updateAttributes) { switch (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes); break; } } updatedClasspath.add(entry); } if (needToUpdateClasspath) { final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath .toArray(new IClasspathEntry[updatedClasspath.size()]); javaProject.setRawClasspath(updatedCPArray, null); } }
From source file:org.eclipse.jst.j2ee.internal.common.operations.UpdateJavaBuildPathOperation.java
License:Open Source License
protected void ensureClasspathEntryIsExported(List cp, IClasspathEntry entry) { if (entry.isExported()) return;/* w w w.ja v a 2 s. com*/ int index = getIndex(cp, entry); IClasspathEntry newEntry = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), true); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), true); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); } cp.set(index, newEntry); }