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:org.eclipse.vjet.eclipse.javalaunch.utils.EclipseResourceUtils.java
License:Open Source License
/** * Searches through the tree of dependencies and adds to a list of projects. * @param javaProject - The Java project to search * @param transitiveClosureProjectList - The list to store the projects * @throws JavaModelException//from w ww . j a va 2 s. c o m */ public static void getTransitiveClosureDependencies(IJavaProject javaProject, Map<String, IJavaProject> transitiveClosureProjectList, Map<String, IPath> transitiveLibrarySet) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); if (classPathEntries != null) { for (IClasspathEntry classPathEntry : classPathEntries) { if (classPathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IResource classPathProject = ResourcesPlugin.getWorkspace().getRoot() .findMember(classPathEntry.getPath()); if (classPathProject != null) { if (transitiveClosureProjectList.containsKey(classPathProject.getName()) == false) { IJavaProject subJavaProject = getJavaProject(classPathProject); transitiveClosureProjectList.put(classPathProject.getName(), subJavaProject); getTransitiveClosureDependencies(subJavaProject, transitiveClosureProjectList, transitiveLibrarySet); } } } else if (classPathEntry != null && classPathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (classPathEntry.getSourceAttachmentPath() != null) { String key = classPathEntry.getSourceAttachmentPath().toString(); transitiveLibrarySet.put(key, classPathEntry.getSourceAttachmentPath()); } } } } }
From source file:org.eclipse.xtend.ide.macro.JdtBasedProcessorProvider.java
License:Open Source License
protected void collectClasspathURLs(final IJavaProject projectToUse, final LinkedHashSet<URL> result, final boolean includeOutputFolder, final Set<IJavaProject> visited) throws JavaModelException { try {//from w w w . j ava2s. co m if (((!projectToUse.getProject().isAccessible()) || (!visited.add(projectToUse)))) { return; } if (includeOutputFolder) { IPath path = projectToUse.getOutputLocation().addTrailingSeparator(); String _string = URI.createPlatformResourceURI(path.toString(), true).toString(); URL url = new URL(_string); result.add(url); } final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true); for (final IClasspathEntry entry : resolvedClasspath) { { URL url_1 = null; int _entryKind = entry.getEntryKind(); switch (_entryKind) { case IClasspathEntry.CPE_SOURCE: if (includeOutputFolder) { final IPath path_1 = entry.getOutputLocation(); if ((path_1 != null)) { String _string_1 = URI .createPlatformResourceURI(path_1.addTrailingSeparator().toString(), true) .toString(); URL _uRL = new URL(_string_1); url_1 = _uRL; } } break; case IClasspathEntry.CPE_PROJECT: IPath path_2 = entry.getPath(); final IResource project = this.getWorkspaceRoot(projectToUse).findMember(path_2); final IJavaProject referencedProject = JavaCore.create(project.getProject()); this.collectClasspathURLs(referencedProject, result, true, visited); break; case IClasspathEntry.CPE_LIBRARY: IPath path_3 = entry.getPath(); final IResource library = this.getWorkspaceRoot(projectToUse).findMember(path_3); URL _xifexpression = null; if ((library != null)) { URL _xblockexpression = null; { final java.net.URI locationUri = library.getLocationURI(); URL _xifexpression_1 = null; String _scheme = null; if (locationUri != null) { _scheme = locationUri.getScheme(); } boolean _equals = Objects.equal(EFS.SCHEME_FILE, _scheme); if (_equals) { java.net.URI _rawLocationURI = library.getRawLocationURI(); URL _uRL_1 = null; if (_rawLocationURI != null) { _uRL_1 = _rawLocationURI.toURL(); } _xifexpression_1 = _uRL_1; } else { _xifexpression_1 = null; } _xblockexpression = _xifexpression_1; } _xifexpression = _xblockexpression; } else { _xifexpression = path_3.toFile().toURI().toURL(); } url_1 = _xifexpression; break; default: { IPath path_4 = entry.getPath(); url_1 = path_4.toFile().toURI().toURL(); } break; } if ((url_1 != null)) { result.add(url_1); } } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.java
License:Open Source License
/** * @see JavaProject#computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, java.util.Map) *//* ww w.j a va 2 s . c om*/ private void collectSourcePackageFragmentRoots(JavaProject javaProject, HashSet<String> rootIDs, IClasspathEntry referringEntry, ObjectVector result) throws JavaModelException { if (referringEntry == null) { rootIDs.add(javaProject.rootID()); } else if (rootIDs.contains(javaProject.rootID())) { return; } IWorkspaceRoot workspaceRoot = javaProject.getProject().getWorkspace().getRoot(); for (IClasspathEntry entry : javaProject.getResolvedClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: if (referringEntry != null && !entry.isExported()) return; IPath pathToProject = entry.getPath(); IResource referencedProject = workspaceRoot.findMember(pathToProject); if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) { IProject casted = (IProject) referencedProject; if (JavaProject.hasJavaNature(casted)) { rootIDs.add(javaProject.rootID()); JavaProject referencedJavaProject = (JavaProject) JavaCore.create(casted); collectSourcePackageFragmentRoots(referencedJavaProject, rootIDs, entry, result); } } break; case IClasspathEntry.CPE_SOURCE: javaProject.computePackageFragmentRoots(entry, result, rootIDs, referringEntry, true, null); break; } } }
From source file:org.eclipse.xtext.junit4.ui.util.JavaProjectSetupUtil.java
License:Open Source License
public static void removeProjectReference(IJavaProject from, IJavaProject to) throws CoreException { removeFromClasspath(from, IClasspathEntry.CPE_PROJECT, to.getPath()); }
From source file:org.eclipse.xtext.ui.util.JdtClasspathUriResolver.java
License:Open Source License
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException { boolean includeAll = visited.isEmpty(); if (visited.add(javaProject.getElementName())) { IProject project = javaProject.getProject(); IResource resourceFromProjectRoot = project.findMember(path); if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) { return createPlatformResourceURI(resourceFromProjectRoot); }//ww w . ja v a2 s . c o m for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (includeAll || entry.isExported()) { IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath()); if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) { IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject); if (referencedJavaProject.exists()) { URI result = findResourceInProjectRoot(referencedJavaProject, path, visited); if (result != null) { return result; } } } break; } } } } return null; }
From source file:org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.java
License:Open Source License
protected ClassLoader createClassLoader(IJavaProject javaProject) throws CoreException { List<URL> urls = Lists.newArrayListWithExpectedSize(javaProject.getResolvedClasspath(true).length); try {//from w ww.j a va 2s. c om IWorkspaceRoot workspaceRoot = getWorkspace().getRoot(); urls.addAll(getOutputFolders(javaProject)); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { IPath path = null; URL url = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: break; case IClasspathEntry.CPE_PROJECT: IResource project = workspaceRoot.findMember(entry.getPath()); urls.addAll(getOutputFolders(JavaCore.create(project.getProject()))); break; default: path = entry.getPath(); url = path.toFile().toURI().toURL(); break; } if (url != null) { urls.add(url); } } } catch (MalformedURLException e) { logger.error( "Error creating class loader for java project '" + javaProject.getProject().getName() + "'", e); } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }
From source file:org.eclipselabs.jar2uml.JarToUML.java
License:Open Source License
/** * Retrieves the project references for javaProject and stores them in refs * @param javaProject/*from w w w .j av a 2 s . c om*/ * @param refs the project references for javaProject */ public static void findJavaProjectReferences(IJavaProject javaProject, Set<IJavaProject> refs) { try { for (IClasspathEntry cpe : javaProject.getResolvedClasspath(true)) { IPath cpePath; switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: cpePath = cpe.getPath(); IJavaProject ref = getJavaProject(cpePath); refs.add(ref); break; } } } catch (JavaModelException e) { JarToUMLPlugin.getPlugin().report(e); } }
From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java
License:Apache License
private static void processEntry(IJavaProject javaProject, List<URL> urlList, IClasspathEntry entry, boolean ignoreSource) throws MalformedURLException { // This source output ... always included & exported if (!ignoreSource && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null) { URL url = new URL("file", null, outputLocation.toString() + "/"); urlList.add(url);/*from ww w . j a v a 2 s . c o m*/ } } // Referenced project classpath. If this project is exported, // Then all *exported* entries are exported with respect to this // project, else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject ijproject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0)); IJavaProject ref = JavaCore.create(ijproject); Collection<URL> cpEntries = getClasspathEntries(ref, false); urlList.addAll(cpEntries); } // This is the Directories classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath entryPath = entry.getPath(); URL url = new URL("file", null, entryPath.toString()); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (res != null && res.exists()) { url = new URL("file", null, res.getLocation().toString()); } urlList.add(url); } // This is Library classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = entry.getPath(); URL url = new URL("file", null, entryPath.toString()); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (res != null && res.exists()) { url = new URL("file", null, res.getLocation().toString()); } urlList.add(url); } // This is Variables classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String variableName = entry.getPath().segment(0); IPath variablePath = JavaCore.getClasspathVariable(variableName); if (variablePath != null) { URL url = new URL("file", null, variablePath.toString()); urlList.add(url); } } }
From source file:org.evosuite.eclipse.popup.actions.TestGenerationJob.java
License:Open Source License
private String buildProjectCP() throws JavaModelException { IJavaProject jProject = JavaCore.create(target.getProject()); IClasspathEntry[] oldEntries = jProject.getRawClasspath(); String classPath = ""; boolean first = true; for (int i = 0; i < oldEntries.length; i++) { IClasspathEntry curr = oldEntries[i]; System.out.println("Current entry: " + curr.getPath()); if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = curr.getPath(); if (path.toFile().getName().startsWith("evosuite")) { System.out.println("Skipping evosuite.jar"); continue; }/*www.j a va 2s. c o m*/ if (!first) classPath += File.pathSeparator; else first = false; if (path.toFile().exists()) { classPath += path.toOSString(); System.out.println("Adding CPE_LIBRARY to classpath: " + path.toOSString()); } else { classPath += target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString(); System.out.println("Adding CPE_LIBRARY to classpath: " + target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString()); } } else if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (curr.isExported()) { if (curr.toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) { System.out.println("Found JRE container"); } else if (curr.toString().startsWith("org.eclipse.jdt.junit.JUNIT_CONTAINER")) { System.out.println("Found JUnit container"); } else { System.out.println("Found unknown container: " + curr); } } else { System.out.println("Container not exported: " + curr); } } else if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // Add binary dirs of this project to classpath System.out.println("Don't handle CPE_PROJECT yet"); } else if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { System.out.println("Path: " + curr.getPath()); System.out.println("Resolved Path: " + JavaCore.getResolvedVariablePath(curr.getPath())); if (!first) classPath += File.pathSeparator; else first = false; classPath += JavaCore.getResolvedVariablePath(curr.getPath()); } else if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { System.out.println("Don't handle CPE_SOURCE yet"); } else { System.out.println("CP type: " + curr.getEntryKind()); } } ResourceList.resetAllCaches(); if (!first) classPath += File.pathSeparator; classPath += target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation() .toOSString(); return classPath; }
From source file:org.flowerplatform.editor.java.propertypage.remote.JavaProjectPropertyPageService.java
License:Open Source License
public Object getClasspathEntries(ServiceInvocationContext context, List<PathFragment> path) { @SuppressWarnings("unchecked") Pair<File, String> node = (Pair<File, String>) GenericTreeStatefulService.getNodeByPathFor(path, null); File projectFile = node.a;/*from w w w . j a va 2s . c o m*/ File wd = ProjectsService.getInstance().getProjectToWorkingDirectoryAndIProjectMap().get(projectFile).a; IProject project = ProjectsService.getInstance().getProjectToWorkingDirectoryAndIProjectMap() .get(projectFile).b; IJavaProject javaProject = JavaCore.create(project); List<String> srcFolders = new ArrayList<String>(); List<String> projects = new ArrayList<String>(); List<String> libraries = new ArrayList<String>(); try { if (!project.getFile(IJavaProject.CLASSPATH_FILE_NAME).exists()) { return null; } @SuppressWarnings("restriction") IClasspathEntry[][] entries = ((JavaProject) javaProject).readFileEntriesWithException(null); for (IClasspathEntry entry : entries[0]) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcFolders.add(entry.getPath() .makeRelativeTo(project.getFolder(ProjectsService.LINK_TO_PROJECT).getFullPath()) .toFile().getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { File file = ProjectsService.getInstance().getFileFromProjectWrapperResource( ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment())); projects.add(CommonPlugin.getInstance().getPathRelativeToFile(file, wd)); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getContentKind() == IPackageFragmentRoot.K_BINARY) { IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()); File file = ProjectsService.getInstance().getFileFromProjectWrapperResource(resource); libraries.add(CommonPlugin.getInstance().getPathRelativeToFile(file, wd)); } } } catch (CoreException | IOException e) { logger.error("Exception thrown while getting java classpath entries for {}", project.getName(), e); return null; } return new Object[] { srcFolders, projects, libraries }; }