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:repast.simphony.agents.designer.core.AgentBuilderPlugin.java
License:Open Source License
/** * Adds classpath entries to the supported list. * /* ww w . j a va 2s.c om*/ * @param projectName * @param pathEntries */ public static void getResolvedClasspath(String projectName, List pathEntries) { IJavaProject javaProject = AgentBuilderPlugin.getJavaProject(projectName); IPath path = null; try { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; path = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { path = getWorkspaceRoot().getLocation() .append(JavaCore.getResolvedClasspathEntry(entry).getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { path = JavaCore.getResolvedClasspathEntry(entry).getPath(); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { path = entry.getPath().makeAbsolute(); if (!path.toFile().getAbsoluteFile().exists()) { IPath location = getWorkspaceRoot().getProject(entry.getPath().segment(0)) .getFile(entry.getPath().removeFirstSegments(1)).getLocation(); if (location != null) { File tmpFile = location.toFile(); if (tmpFile.exists()) path = location; } } } if (path != null && !pathEntries.contains(path)) pathEntries.add(path); if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProject = getWorkspaceProject(entry.getPath()); // recurse into projects if (requiredProject != null) getResolvedClasspath(requiredProject, pathEntries); } } IPath outputPath = javaProject.getOutputLocation(); if (outputPath.segmentCount() == 1) outputPath = javaProject.getResource().getLocation(); else outputPath = javaProject.getProject().getFile(outputPath.removeFirstSegments(1)).getLocation(); if (outputPath != null && !pathEntries.contains(outputPath)) pathEntries.add(outputPath); } catch (JavaModelException e) { AgentBuilderPlugin.log(e); } }
From source file:runjettyrun.tabs.action.AddClassFolderAction.java
License:Open Source License
/** * Adds all projects required by <code>proj</code> to the list * <code>res</code>/*from ww w . j a v a2 s. co m*/ * * @param proj the project for which to compute required * projects * @param res the list to add all required projects too */ protected void collectRequiredProjects(IJavaProject proj, List<IJavaProject> res) throws JavaModelException { if (!res.contains(proj)) { res.add(proj); IJavaModel model = proj.getJavaModel(); IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry curr = entries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject ref = model.getJavaProject(curr.getPath().segment(0)); if (ref.exists()) { collectRequiredProjects(ref, res); } } } } }
From source file:runjettyrun.tabs.action.AddClassFolderAction.java
License:Open Source License
/** * Adds all exported entries defined by <code>proj</code> to the list * <code>runtimeEntries</code>. * * @param proj// w w w .jav a2s . c om * @param runtimeEntries * @throws JavaModelException */ protected void collectExportedEntries(IJavaProject proj, List<IRuntimeClasspathEntry> runtimeEntries) throws CoreException { IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.isExported()) { IRuntimeClasspathEntry rte = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), proj); int kind = 0; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: kind = IRuntimeClasspathEntry.USER_CLASSES; break; case IClasspathContainer.K_SYSTEM: kind = IRuntimeClasspathEntry.BOOTSTRAP_CLASSES; break; case IClasspathContainer.K_DEFAULT_SYSTEM: kind = IRuntimeClasspathEntry.STANDARD_CLASSES; break; } rte = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), kind, proj); break; case IClasspathEntry.CPE_LIBRARY: rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); rte.setSourceAttachmentPath(entry.getSourceAttachmentPath()); rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath()); break; case IClasspathEntry.CPE_PROJECT: String name = entry.getPath().segment(0); IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (p.exists()) { IJavaProject jp = JavaCore.create(p); if (jp.exists()) { rte = JavaRuntime.newProjectRuntimeClasspathEntry(jp); } } break; case IClasspathEntry.CPE_VARIABLE: rte = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); break; default: break; } if (rte != null) { if (!runtimeEntries.contains(rte)) { runtimeEntries.add(rte); } } } } }
From source file:tod.plugin.TODPluginUtils.java
License:Open Source License
/** * Searches for declarations of the given name and kind in the whole workspace. */// w ww .j ava 2 s . co m public static List searchDeclarations(List<IJavaProject> aJavaProject, String aName, int aKind) throws CoreException { // Recursively add referenced projects (because Eclipse doesn't recursively include non-exported referenced projects) Set<IJavaProject> theProjects = new HashSet<IJavaProject>(); Stack<IJavaProject> theWorkingList = new ArrayStack<IJavaProject>(); for (IJavaProject theProject : aJavaProject) theWorkingList.push(theProject); while (!theWorkingList.isEmpty()) { IJavaProject theProject = theWorkingList.pop(); theProjects.add(theProject); IJavaModel theJavaModel = theProject.getJavaModel(); IClasspathEntry[] theEntries = theProject.getResolvedClasspath(true); for (IClasspathEntry theEntry : theEntries) if (theEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject theReferencedProject = theJavaModel .getJavaProject(theEntry.getPath().lastSegment()); if (theReferencedProject.exists() && !theProjects.contains(theReferencedProject)) theWorkingList.push(theReferencedProject); } } SearchPattern thePattern = SearchPattern.createPattern(aName.replace('$', '.'), aKind, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope theScope = SearchEngine .createJavaSearchScope(theProjects.toArray(new IJavaElement[theProjects.size()]), true); SearchEngine theSearchEngine = new SearchEngine(); SimpleResultCollector theCollector = new SimpleResultCollector(); theSearchEngine.search(thePattern, PARTICIPANTS, theScope, theCollector, null); return theCollector.getResults(); }
From source file:x10dt.search.core.pdb.X10FactGenerator.java
License:Open Source License
private void processEntries(final CompilerOptionsBuilder cmpOptBuilder, final IWorkspaceRoot wsRoot, final IClasspathEntry[] entries, final IJavaProject javaProject, final IResource contextResource, final boolean isInRuntime) throws JavaModelException, AnalysisException { for (final IClasspathEntry pathEntry : entries) { switch (pathEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (pathEntry.getPath().isRoot()) { cmpOptBuilder.addToSourcePath(pathEntry.getPath().toFile()); } else { cmpOptBuilder.addToSourcePath(wsRoot.getLocation().append(pathEntry.getPath()).toFile()); }//from w w w. j a v a 2 s . c o m if (pathEntry.getPath().segmentCount() > 1) { processSourceFolder(cmpOptBuilder, wsRoot.getFolder(pathEntry.getPath()), contextResource); } break; case IClasspathEntry.CPE_LIBRARY: try { final IPackageFragmentRoot pkgRoot = javaProject.findPackageFragmentRoot(pathEntry.getPath()); if ((pkgRoot != null) && pkgRoot.exists()) { final File localFile; if (pkgRoot.isExternal()) { localFile = pathEntry.getPath().toFile(); } else { localFile = pkgRoot.getResource().getLocation().toFile(); } cmpOptBuilder.addToClassPath(localFile.getAbsolutePath()); if (isInRuntime) { cmpOptBuilder.addToSourcePath(localFile); } final ZipFile zipFile; if (JAR_EXT.equals(pathEntry.getPath().getFileExtension())) { zipFile = new JarFile(localFile); } else { zipFile = new ZipFile(localFile); } processLibrary(cmpOptBuilder, zipFile, localFile, contextResource, isInRuntime); } } catch (IOException except) { throw new AnalysisException(NLS.bind(Messages.XFG_JarReadingError, pathEntry.getPath()), except); } break; case IClasspathEntry.CPE_CONTAINER: final IClasspathContainer cpContainer = JavaCore.getClasspathContainer(pathEntry.getPath(), javaProject); processEntries(cmpOptBuilder, wsRoot, cpContainer.getClasspathEntries(), javaProject, contextResource, true); break; case IClasspathEntry.CPE_PROJECT: final IResource projectResource = ResourcesPlugin.getWorkspace().getRoot() .findMember(pathEntry.getPath()); if ((projectResource != null) && projectResource.isAccessible()) { final IJavaProject newJavaProject = JavaCore.create((IProject) projectResource); processEntries(cmpOptBuilder, wsRoot, newJavaProject.getRawClasspath(), newJavaProject, contextResource, false); } break; case IClasspathEntry.CPE_VARIABLE: processEntries(cmpOptBuilder, wsRoot, new IClasspathEntry[] { JavaCore.getResolvedClasspathEntry(pathEntry) }, javaProject, contextResource, false); break; } } }
From source file:x10dt.ui.launch.core.builder.AbstractX10Builder.java
License:Open Source License
public static Collection<IPath> getProjectDependencies(IJavaProject project) throws JavaModelException { Collection<IPath> ret = new ArrayList<IPath>(); if (project == null) return ret; for (final IClasspathEntry cpEntry : project.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject javaProject = JavaCore.create(wsRoot.getProject(cpEntry.getPath().toOSString())); ret.add(wsRoot.getLocation().append(javaProject.getOutputLocation())); for (final IClasspathEntry pEntry : javaProject.getRawClasspath()) { if (pEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (pEntry.getOutputLocation() != null) { ret.add(wsRoot.getLocation().append(pEntry.getOutputLocation())); }/* www .j a v a2 s. co m*/ } } } } return ret; }
From source file:x10dt.ui.launch.core.builder.AbstractX10Builder.java
License:Open Source License
public static Collection<String> getProjectDependenciesNames(IJavaProject project) throws JavaModelException { Collection<String> ret = new ArrayList<String>(); for (final IClasspathEntry cpEntry : project.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); ret.add(wsRoot.getProject(cpEntry.getPath().toOSString()).getName()); }/*ww w .j av a 2 s .c o m*/ } return ret; }
From source file:x10dt.ui.launch.core.utils.ProjectUtils.java
License:Open Source License
/** * Returns the set of projects on this project's classpath. *//*from ww w .j a v a 2s .c o m*/ public static Collection<IProject> getDependentProjects(IJavaProject project) throws JavaModelException { Collection<IProject> result = new ArrayList<IProject>(); final IWorkspaceRoot root = project.getResource().getWorkspace().getRoot(); for (final IClasspathEntry cpEntry : project.getResolvedClasspath(true)) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { final IResource resource = root.findMember(cpEntry.getPath()); if (resource == null) { LaunchCore.log(IStatus.WARNING, NLS.bind(Messages.JPU_ResourceErrorMsg, cpEntry.getPath())); } else { result.add((IProject) resource); } } } return result; }
From source file:x10dt.ui.launch.core.utils.ProjectUtils.java
License:Open Source License
private static <T> void collectCpEntries(final Set<T> container, final IClasspathEntry cpEntry, final IWorkspaceRoot root, final IFilter<IPath> libFilter, final IFunctor<IPath, T> functor, final IProject project, StringBuffer pathBuffer) throws JavaModelException { final IJavaProject javaProject = JavaCore.create(project); switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (isX10Project(javaProject)) { IPath outputPath = getOutputLocation(cpEntry, javaProject); if (outputPath.lastSegment().equals("bin-java")) { appendNew(functor, container, pathBuffer, makeAbsolutePath(root, outputPath)); } else { appendNew(functor, container, pathBuffer, makeAbsolutePath(root, cpEntry.getPath())); }//from ww w .j a v a 2 s . c o m } else { appendNew(functor, container, pathBuffer, makeAbsolutePath(root, getOutputLocation(cpEntry, javaProject))); } break; case IClasspathEntry.CPE_LIBRARY: IPath path = cpEntry.getPath(); if (libFilter.accepts(path)) { IPath absolutePath = makeAbsolutePath(root, path); appendNew(functor, container, pathBuffer, absolutePath); } break; case IClasspathEntry.CPE_PROJECT: final IResource resource = root.findMember(cpEntry.getPath()); if (resource == null) { LaunchCore.log(IStatus.WARNING, NLS.bind(Messages.JPU_ResourceErrorMsg, cpEntry.getPath())); } else { final IJavaProject refProject = JavaCore.create((IProject) resource); for (final IClasspathEntry newCPEntry : refProject.getResolvedClasspath(true)) { collectCpEntries(container, newCPEntry, root, libFilter, functor, (IProject) resource, pathBuffer); } } break; default: throw new IllegalArgumentException( NLS.bind(Messages.JPU_UnexpectedEntryKindMsg, cpEntry.getEntryKind())); } }
From source file:x10dt.ui.parser.CompilerDelegate.java
License:Open Source License
/** * @return a list of all project-relative CPE_SOURCE-type classpath entries. * @throws JavaModelException/* www .jav a 2 s.c om*/ */ private List<IPath> getProjectSrcPath() throws CoreException { List<IPath> srcPath = new ArrayList<IPath>(); // Produce a search path heuristically for files living outside the workspace, // and for workspace files living in non-X10-natured projects. if (fX10Project == null || !isX10Project()) { IPath pkgRootPath = determinePkgRootPath(); if (pkgRootPath != null) { if (fX10Project != null && fX10Project.getProject().getName().equals("x10.runtime")) { // If the containing project happens to be x10.runtime, // don't add the runtime bound into the X10DT to the search path return Arrays.asList(pkgRootPath); } else { return Arrays.asList(pkgRootPath, new Path(getRuntimePath())); } } else { return Arrays.asList((IPath) new Path(getRuntimePath())); } } IClasspathEntry[] classPath = fX10Project.getResolvedClasspath(true); for (int i = 0; i < classPath.length; i++) { IClasspathEntry e = classPath[i]; if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcPath.add(e.getPath()); } else if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { //PORT1.7 Compiler needs to see X10 source for all referenced compilation units, // so add source path entries of referenced projects to this project's sourcepath. // Assume that goal dependencies are such that Polyglot will not be compelled to // compile referenced X10 source down to Java source (causing duplication; see below). // // RMF 6/4/2008 - Don't add referenced projects to the source path: // 1) doing so should be unnecessary, since the classpath will include // the project, and the class files should satisfy all references, // 2) doing so will cause Polyglot to compile the source files found in // the other project to Java source files located in the *referencing* // project, causing duplication, which is not what we want. // IProject refProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(e.getPath().toPortableString()); IJavaProject refJavaProject = JavaCore.create(refProject); IClasspathEntry[] refJavaCPEntries = refJavaProject.getResolvedClasspath(true); for (int j = 0; j < refJavaCPEntries.length; j++) { if (refJavaCPEntries[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcPath.add(refJavaCPEntries[j].getPath()); } } } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // PORT1.7 Add the X10 runtime jar to the source path, since the compiler // needs to see the X10 source for the user-visible runtime classes (like // x10.lang.Region) to get the extra type information (for deptypes) that // can't be stored in Java class files, and for now, these source files // actually live in the X10 runtime jar. IPath path = e.getPath(); if (path.toPortableString().contains(X10BundleUtils.X10_RUNTIME_BUNDLE_ID)) { srcPath.add(path); } } } if (srcPath.size() == 0) srcPath.add(fX10Project.getProject().getLocation()); return srcPath; }