List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipselabs.jar2uml.JarToUML.java
License:Open Source License
/** * Adds all relevant class file paths for javaProject * @param javaProject/* w ww . ja v a2s. co m*/ * @param includeWorkspaceReferences Include referenced projects and jar files in workspace * @throws JavaModelException * @throws IOException */ public void addPaths(IJavaProject javaProject, boolean includeWorkspaceReferences) throws JavaModelException, IOException { for (IClasspathEntry cpe : javaProject.getResolvedClasspath(true)) { IPath cpePath; switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: cpePath = cpe.getOutputLocation(); if (cpePath == null) { cpePath = javaProject.getOutputLocation(); } IContainer container = (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(cpePath); addPath(container); break; case IClasspathEntry.CPE_LIBRARY: cpePath = cpe.getPath(); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(cpePath); if ((resource != null) && (includeWorkspaceReferences || javaProject.getProject().equals(resource.getProject()))) { if (resource instanceof IFile) { addCpJar(new JarFile(resource.getLocation().toFile())); } else if (resource instanceof IContainer) { addCpPath((IContainer) resource); } else { throw new IOException(String .format(JarToUMLResources.getString("JarToUML.unexpectedResourceKind"), resource)); //$NON-NLS-1$ } } break; } } if (includeWorkspaceReferences) { Set<IJavaProject> refs = new HashSet<IJavaProject>(); findJavaProjectReferences(javaProject, refs); for (IJavaProject ref : refs) { addPaths(ref, includeWorkspaceReferences); } } }
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);/*www.ja va 2 s.co 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; }//w w w . j a v a2 s.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.fastcode.util.SourceUtil.java
License:Open Source License
/** * * @param javaProject/*from w w w. j a v a 2 s . c o m*/ * @return */ public static Set<String> getBinaryFoldersForJavaProject(final IJavaProject javaProject) { final Set<String> binaryFolders = new TreeSet<String>(); try { // Get default output folder location. IPath outputPath = javaProject.getOutputLocation(); if (outputPath != null) { binaryFolders.add(outputPath.toString()); } // Find all the output folders by looking for source folders. for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputPath = entry.getOutputLocation(); if (outputPath == null) { continue; } binaryFolders.add(outputPath.toString()); } } } catch (final JavaModelException e) { e.printStackTrace(); } return binaryFolders; }
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. jav a 2 s. c om 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 }; }
From source file:org.fusesource.tools.core.Classpath.java
License:Open Source License
public Collection<IPath> getSrc() { return getPaths(IClasspathEntry.CPE_SOURCE); }
From source file:org.gololang.gldt.jdt.internal.GoloBuilder.java
License:Apache License
private IPath isOnSourceRoot(IResource resource, IJavaProject javaProject) throws JavaModelException { IPath result = null;//from ww w . j av a2s . c o m IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && entry.getPath().isPrefixOf(resource.getFullPath())) { result = entry.getOutputLocation(); if (result == null) { result = javaProject.getOutputLocation(); } break; } } return result; }
From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java
License:Open Source License
/** * Test to see if we can use the "eclipsifyProject" method to "eclipsify" a very bare-bones * imported grails project that is missing just about *everything* in the way of configuration files. * <p>// w w w. ja v a2 s .c o m * This bare bones project is created by deleting all Eclipse related stuff and the target directory * from a grails project and then importing this into eclipse as a "general" project. Thus it has the * minimum, of configuration to make it a valid Eclipse project but nothing more. */ public void testEclipsifyBareBonesProject() throws Exception { GrailsVersion version = GrailsVersion.MOST_RECENT; if (GrailsVersion.MOST_RECENT.isSnapshot()) { //Don't run this for snapshot builds. Too much work to create test projects for moving target. return; } ensureDefaultGrailsVersion(version); // The version of the BareBones project URL bareBonesURL = getProjectZip("bareBonesProject", version); // Create bare bones project from zip file IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); project = workspaceRoot.getProject("testProject"); IPath unzipLoc = workspaceRoot.getLocation(); ZipFileUtil.unzip(bareBonesURL, unzipLoc.toFile(), new NullProgressMonitor()); project.create(new NullProgressMonitor()); assertTrue(project.exists()); project.open(new NullProgressMonitor()); project.refreshLocal(IResource.DEPTH_INFINITE, null); assertTrue(project.isAccessible()); assertTrue(project.isAccessible()); assertTrue(project.getFolder("grails-app").exists()); GrailsCommandUtils.eclipsifyProject(project); ///////////////////////////////////////////////////////////////////////////////////////////////// //Check a few things about this test project assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature IJavaProject javaProject = JavaCore.create(project); assertDefaultOutputFolder(javaProject); IClasspathEntry[] classPath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : classPath) { System.out.println(kindString(classpathEntry.getEntryKind()) + ": " + classpathEntry.getPath()); } //The usual source folders: assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/java", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/groovy", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/conf", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/controllers", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/domain", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/services", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/taglib", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/integration", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/unit", classPath); //The classpath containers for Java and Grails assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.eclipse.jdt.launching.JRE_CONTAINER", classPath); assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.grails.ide.eclipse.core.CLASSPATH_CONTAINER", classPath); //Installed plugins source folders assertBareBonesProjectUserPluginSourceFolders(version); assertDefaultPluginSourceFolders(project); assertCharset(project); }
From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java
License:Open Source License
private void checkProjectBasics() throws CoreException, JavaModelException { assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature IJavaProject javaProject = JavaCore.create(project); assertDefaultOutputFolder(javaProject); IClasspathEntry[] classPath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : classPath) { System.out.println(kindString(classpathEntry.getEntryKind()) + ": " + classpathEntry.getPath()); }/*from w w w . j a v a2 s . c om*/ //The usual source folders: assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/java", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/groovy", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/conf", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/controllers", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/domain", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/services", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/taglib", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/integration", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/unit", classPath); //The classpath containers for Java and Grails assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.eclipse.jdt.launching.JRE_CONTAINER", classPath); assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.grails.ide.eclipse.core.CLASSPATH_CONTAINER", classPath); //Installed plugins source folders assertDefaultPluginSourceFolders(project); assertCharset(project); }
From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java
License:Open Source License
/** * This test isn't actually testing stuff from {@link GrailsCommandUtils}, but it is in here because * it uses some similar checks that a project is properly setup after doing a "raw" import of project * created outside eclipse using grails commands. * <p>/*from ww w . j a v a 2s .c o m*/ * A "raw" import means simply pulling in a project from files from somewhere outside eclipse and doing * nothing more than adding them as a new project to the workspace. As of Grails 1.3.5 this should produce * a correctly configured grails project (grails 1.3.5 produces correct .project etc. files). So there * should be no need to call 'eclipsify' on such projects. */ public void testImportExistingProject() throws Throwable { GrailsProjectVersionFixer.globalAskToConvertToGrailsProjectAnswer = true; System.out.println(">>>>>>>>>>>>>>>>>>>testImportExistingProject"); GroovyCompilerVersionCheck.testMode(); ensureDefaultGrailsVersion(GrailsVersion.V_1_3_5); // GrailsVersion of test project! StsTestUtil.setAutoBuilding(true); System.out.println("Waiting for autobuild..."); StsTestUtil.waitForAutoBuild(); System.out.println("Done autobuild"); URL bareBonesURL = this.getClass().getClassLoader().getResource("external-project.zip"); String projectName = "External"; // Create bare bones project from zip file IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IPath unzipLoc = workspaceRoot.getLocation(); ZipFileUtil.unzip(bareBonesURL, unzipLoc.toFile(), new NullProgressMonitor()); project = workspaceRoot.getProject(projectName); project.create(null); if (!project.isOpen()) { project.open(null); } assertTrue(project.isAccessible()); assertTrue(project.getFolder("grails-app").exists()); ///////////////////////////////////////////////////////////////////////////////////////////////// //Check a few things about this test project assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature final IJavaProject javaProject = JavaCore.create(project); //Next we check the classpath related stuff. // The classpath may not be right initially... but should eventually become correct as a background // refresh dependency job should get scheduled. // ACondition new ACondition() { @Override public boolean test() throws Exception { System.out.println("Checking project config..."); assertEquals("/" + project.getName() + "/target-eclipse/classes", javaProject.getOutputLocation().toString()); /////////////////////////////////// // Check resolved classpath stuff IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false); // A whole bunch of libraries should be there, check for just a few of those // this one will fail on macs // assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "jre/lib/rt.jar", classPath); assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-core", classPath); assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-bootstrap", classPath); assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "groovy-all", classPath); //assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "servlet-api", classPath); // System.out.println(">>>Resolved classpath"); // for (IClasspathEntry entry : classPath) { // System.out.println(kindString(entry.getEntryKind())+": "+entry.getPath()); // } // System.out.println("<<<Resolved classpath"); /////////////////////////////////// // Check raw classpath stuff classPath = javaProject.getRawClasspath(); // for (IClasspathEntry classpathEntry : classPath) { // System.out.println(kindString(classpathEntry.getEntryKind())+": "+classpathEntry.getPath()); // } //The usual source folders: assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/java", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/groovy", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/conf", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/controllers", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/domain", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/services", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/taglib", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/integration", classPath); assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/unit", classPath); //The classpath containers for Java and Grails assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.eclipse.jdt.launching.JRE_CONTAINER", classPath); assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.grails.ide.eclipse.core.CLASSPATH_CONTAINER", classPath); //Installed plugins source folders assertDefaultPluginSourceFolders(project); assertCharset(project); System.out.println("Checking project config => OK!"); return true; } }.waitFor(60000); System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<testImportExistingProject"); }