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:de.tobject.findbugs.builder.PDEClassPathGenerator.java
License:Open Source License
@SuppressWarnings("restriction") private static Set<String> createJavaClasspath(IJavaProject javaProject, Set<IProject> projectOnCp) { LinkedHashSet<String> classPath = new LinkedHashSet<String>(); try {/*www . j ava 2 s . com*/ // doesn't return jre libraries String[] defaultClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject); for (String classpathEntry : defaultClassPath) { IPath path = new Path(classpathEntry); if (isValidPath(path)) { classPath.add(path.toOSString()); } } // add CPE_CONTAINER classpathes IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (classpathContainer != null) { if (classpathContainer instanceof JREContainer) { IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry iClasspathEntry : classpathEntries) { IPath path = iClasspathEntry.getPath(); // smallest possible fix for #1228 Eclipse plugin always uses host VM to resolve JDK classes if (isValidPath(path) && "rt.jar".equals(path.lastSegment())) { classPath.add(path.toOSString()); break; } } } else { IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry classpathEntry : classpathEntries) { IPath path = classpathEntry.getPath(); // shortcut for real files if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && isValidPath(path)) { classPath.add(path.toOSString()); } else { resolveInWorkspace(classpathEntry, classPath, projectOnCp); } } } } } } } catch (CoreException e) { FindbugsPlugin.getDefault().logException(e, "Could not compute aux. classpath for project " + javaProject); } return classPath; }
From source file:distributed.plugin.ui.actions.ProcessActions.java
License:Open Source License
private ClassLoader getClassLoader() { ClassLoader loader = null;/*from ww w. j a v a 2 s .c o m*/ IJavaProject javaProject = this.getClientProject(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); List<URL> urls = new ArrayList<URL>(entries.length); for (int i = 0; i < entries.length; i++) { IPath classpathEntryPath = entries[i].getPath(); File classpathEntryFile = null; switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath out = root.getProject(classpathEntryPath.lastSegment()).getLocation(); if (out != null) classpathEntryFile = out.toFile(); else classpathEntryFile = root.getFolder(javaProject.getOutputLocation()).getLocation().toFile(); try { URI uri = classpathEntryFile.toURI(); urls.add(uri.toURL()); } catch (MalformedURLException e) { e.printStackTrace(); } break; case IClasspathEntry.CPE_CONTAINER: break; // FIXME Must handle 2 more cases to handle the location of // client source code } } // set default output (replay) file location w.r.t user bin location this.engine.setOutputLocation((URL) urls.get(0)); // create class loader loader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), ProcessActions.class.getClassLoader()); } catch (JavaModelException e) { e.printStackTrace(); } return loader; }
From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java
License:Eclipse Public License
private void calculateDependencies(IClasspathEntry[] cpe, IProject project) throws DependenciesResolverException { try {//from w w w .j av a 2s .c om IWorkspace workspace = project.getWorkspace(); IPath workspacePath = workspace.getRoot().getLocation(); String nombreWorkspace = workspacePath.toString(); IJavaProject jp = JavaCore.create(project); if (!dependencies.contains(project.getLocation().toString())) { // Aadimos la carpeta bin classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile()); classpath.add(jp.getOutputLocation().toString()); } for (IClasspathEntry cpEntry : cpe) { String path = cpEntry.getPath().toString(); String dependency = nombreWorkspace.concat(path); if (!dependencies.contains(dependency)) { RESClientPlugin.log("Adding dependency: " + dependency); dependencies.add(dependency); if (cpEntry.getOutputLocation() != null) { RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString()); classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString()); classpathFiles.add(cpEntry.getOutputLocation().toFile()); } int tipo = cpEntry.getEntryKind(); //Si la dependencia es de una libreria( if (tipo == IClasspathEntry.CPE_LIBRARY) { String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString(); //mgarcia: Optsicom res Evolution if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) { classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString())); //Aadimos las dependencias a las properties RESClientPlugin.log("Adding library: " + dep); classpath.add(cpEntry.getPath().toString()); } else { throw new DependenciesResolverException(); } } else if (tipo == IClasspathEntry.CPE_PROJECT) { // File[] files = new File(dependency).listFiles(); // for (File f : files){ // lista.add(f); // String dep = f.getPath(); // RESClientPlugin.log("Adding dependency: " + dep); // dependencies.add(dep); // } IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment()); IJavaProject projectDependency = JavaCore.create(p); IClasspathEntry[] cp = projectDependency.getRawClasspath(); classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile()); classpath.add(projectDependency.getOutputLocation().toString()); RESClientPlugin.log("Populating files from: " + p.getName()); calculateDependencies(cp, p); } else if (tipo == IClasspathEntry.CPE_SOURCE) { File f = new File(dependency); classpathFiles.add(f); RESClientPlugin.log("Adding source: " + dependency); } else if (tipo == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry[] clpe = new IClasspathEntry[1]; clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry); if (clpe[0] != null) { RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString()); calculateDependencies(clpe, project); } } else if (tipo == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER") || cpEntry.getPath().toOSString().contains("requiredPlugins")) { continue; } IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp); IClasspathEntry[] entradas = cc.getClasspathEntries(); RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString()); calculateDependencies(entradas, project); } } } } catch (JavaModelException e) { RESClientPlugin.log(e); } for (String path : classpath) { RESClientPlugin.log("Classpath: " + path); } for (File file : classpathFiles) { RESClientPlugin.log("Classpath file: " + file.getAbsolutePath()); } }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Decodes one XML element with the XML stream. * * @param element//from ww w . ja va 2s . com * - the considered element * @param projectName * - the name of project containing the .classpath file * @param projectRootAbsoluteFullPath * - he path to project containing the .classpath file * @param unknownElements * - map of unknown elements * @return the set of CLasspath ENtries extracted from the considered element */ @SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" }) public static IClasspathEntry elementDecode(Element element, String projectName, IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) { final IPath projectPath = projectRootAbsoluteFullPath; final NamedNodeMap attributes = element.getAttributes(); final NodeList children = element.getChildNodes(); final boolean[] foundChildren = new boolean[children.getLength()]; final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes); final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes); // ensure path is absolute IPath path = new Path(pathAttr); final int kind = kindFromString(kindAttr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) { path = projectPath.append(path); } } // source attachment info (optional) IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes)) : null; if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) { sourceAttachmentPath = projectPath.append(sourceAttachmentPath); } final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes)) : null; // exported flag (optional) final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$ // inclusion patterns (optional) IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING); if (inclusionPatterns == null) { inclusionPatterns = ClasspathEntry.INCLUDE_ALL; } // exclusion patterns (optional) IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING); if (exclusionPatterns == null) { exclusionPatterns = ClasspathEntry.EXCLUDE_NONE; } // access rules (optional) NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren); IAccessRule[] accessRules = decodeAccessRules(attributeList); // backward compatibility if (accessRules == null) { accessRules = getAccessRules(inclusionPatterns, exclusionPatterns); } // combine access rules (optional) final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES, attributes).equals("false"); //$NON-NLS-1$ // extra attributes (optional) attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren); final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList); // custom output location final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT) ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes)) : null; String[] unknownAttributes = null; ArrayList<String> unknownChildren = null; if (unknownElements != null) { // unknown attributes final int unknownAttributeLength = attributes.getLength(); if (unknownAttributeLength != 0) { unknownAttributes = new String[unknownAttributeLength * 2]; for (int i = 0; i < unknownAttributeLength; i++) { final Node attribute = attributes.item(i); unknownAttributes[i * 2] = attribute.getNodeName(); unknownAttributes[i * 2 + 1] = attribute.getNodeValue(); } } // unknown children for (int i = 0, length = foundChildren.length; i < length; i++) { if (!foundChildren[i]) { final Node node = children.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } if (unknownChildren == null) { unknownChildren = new ArrayList<>(); } final StringBuffer buffer = new StringBuffer(); decodeUnknownNode(node, buffer); unknownChildren.add(buffer.toString()); } } } // recreate the CP entry IClasspathEntry entry = null; switch (kind) { case IClasspathEntry.CPE_PROJECT: /* * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output * folder */ entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported, accessRules, combineAccessRestrictions, extraAttributes); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_SOURCE: // must be an entry in this project or specify another project final String projSegment = path.segment(0); if (projSegment != null && projSegment.equals(projectName)) { // this project entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } else { if (path.segmentCount() == 1) { // another project entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes, isExported); } else { // an invalid source folder entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } } break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported); break; case ClasspathEntry.K_OUTPUT: if (!path.isAbsolute()) { return null; } /* * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, // * no access rules false, // no accessible files to combine */ entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES); break; default: throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); } if (unknownAttributes != null || unknownChildren != null) { final UnknownXmlElements unknownXmlElements = new UnknownXmlElements(); unknownXmlElements.attributes = unknownAttributes; unknownXmlElements.children = unknownChildren; if (unknownElements != null) { unknownElements.put(path, unknownXmlElements); } } return entry; }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form. * * @param kindStr/* w ww.j a v a 2 s . co m*/ * - string to test * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc. */ @SuppressWarnings("checkstyle:equalsavoidnull") private static int kindFromString(String kindStr) { if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$ return IClasspathEntry.CPE_PROJECT; } if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; } if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; } 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("output")) { //$NON-NLS-1$ return ClasspathEntry.K_OUTPUT; } return -1; }
From source file:me.gladwell.eclipse.m2e.android.configuration.Classpaths.java
License:Open Source License
private static IClasspathEntry matchContainer(IClasspathDescriptor classpath, Predicate<IClasspathEntry> predicate) { return matchEntry(classpath.getEntries(), and(entryOfType(IClasspathEntry.CPE_CONTAINER), predicate)); }
From source file:me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.java
License:Open Source License
public void removeJreClasspathContainer(IClasspathDescriptor classpath) { for (IClasspathEntry entry : classpath.getEntries()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().toOSString().contains(JavaRuntime.JRE_CONTAINER)) { classpath.removeEntry(entry.getPath()); }/* w w w.j a va2 s. c o m*/ } } }
From source file:me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.java
License:Open Source License
public void markMavenContainerExported(IClasspathDescriptor classpath) { for (IClasspathEntry entry : classpath.getEntries()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().toOSString().equals(IClasspathManager.CONTAINER_ID)) { IClasspathEntry newEntry = JavaCore.newContainerEntry(entry.getPath(), true); classpath.removeEntry(entry.getPath()); classpath.addEntry(newEntry); }//from w w w .j a va2 s . c o m } } }
From source file:me.gladwell.eclipse.m2e.android.test.AndroidMavenPluginTestCase.java
License:Open Source License
protected void assertClasspathContains(IJavaProject javaProject, String path) throws JavaModelException { for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getPath().toOSString().contains(path)) { return; } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); for (IClasspathEntry e : container.getClasspathEntries()) { if (e.getPath().toOSString().contains(path)) { return; }//from ww w .ja va 2 s . com } } } fail(path + " should be in classpath"); }
From source file:me.gladwell.eclipse.m2e.android.test.AndroidMavenPluginTestCase.java
License:Open Source License
protected void assertClasspathDoesNotContain(IJavaProject javaProject, String path) throws JavaModelException { for (IClasspathEntry entry : javaProject.getRawClasspath()) { assertFalse(entry.getPath().toOSString().contains(path)); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); for (IClasspathEntry e : container.getClasspathEntries()) { assertFalse(path + " should not be in classpath", e.getPath().toOSString().contains(path)); }/*from w ww . ja va2s. co m*/ } } }