List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
From source file:org.grails.ide.eclipse.groovy.debug.core.evaluation.GroovyJDIEvaluator.java
License:Open Source License
private void addClasspathEntries(JDIGroovyClassLoader groovyLoader, IJavaProject currentProject, boolean includeAll) throws JavaModelException, CoreException { IClasspathEntry[] entries = currentProject.getResolvedClasspath(true); IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation(); for (int i = 0; i < entries.length; i++) { if (!includeAll && !entries[i].isExported()) { continue; }//from w w w.j a v a 2 s .c o m switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: try { groovyLoader.addURL(entries[i].getPath().toFile().toURL()); } catch (MalformedURLException e) { throw new CoreException(new Status(IStatus.ERROR, GroovyDebugCoreActivator.PLUGIN_ID, e.getLocalizedMessage(), e)); } break; case IClasspathEntry.CPE_SOURCE: IPath outLocation = entries[i].getOutputLocation(); if (outLocation != null) { // using non-default output location try { groovyLoader.addURL(workspaceLocation.append(outLocation).toFile().toURL()); } catch (MalformedURLException e) { throw new CoreException(new Status(IStatus.ERROR, GroovyDebugCoreActivator.PLUGIN_ID, e.getLocalizedMessage(), e)); } } break; case IClasspathEntry.CPE_PROJECT: IProject otherProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entries[i].getPath().lastSegment()); if (otherProject.isAccessible()) { IJavaProject otherJavaProject = JavaCore.create(otherProject); addClasspathEntries(groovyLoader, otherJavaProject, false); } break; default: break; } } // now add default out location IPath outLocation = currentProject.getOutputLocation(); if (outLocation != null) { try { groovyLoader.addURL(workspaceLocation.append(outLocation).toFile().toURL()); } catch (MalformedURLException e) { e.printStackTrace(); } } }
From source file:org.grails.ide.eclipse.refactoring.test.GrailsRefactoringTest.java
License:Open Source License
/** * Checks a bunch of stuff about the imported test project. * //from ww w.j av a 2 s.c om * @throws Throwable */ protected void checkImportedProject() throws Exception { //Check project config, like classpath related stuff. // The config 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 { assertJobManagerIdle(); //Wait for jobs... like Refresh dependencies to all complete. System.out.println("Checking project config..."); IJavaProject javaProject = JavaCore.create(project); assertDefaultOutputFolder(javaProject); assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature assertTrue(GrailsNature.isGrailsAppProject(project)); // Should look like a Grails app to grails tooling /////////////////////////////////// // Check resolved classpath stuff IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false); // A whole bunch of libraries should be there, check for just a few of those assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "/jsse.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); System.out.println("Checking project config => OK!"); return true; } }.waitFor(4 * 60000); }
From source file:org.grails.ide.eclipse.test.GrailsProjectVersionFixerTest.java
License:Open Source License
/** * Checks a bunch of stuff about the "very old test project" once it has * been imported in the workspace.// w w w .ja v a 2s. c o m * * @throws Throwable */ private void checkImportedProject() throws Exception { // Check project config, like classpath related stuff. // The config may not be right initially... but should eventually become // correct as a background // refresh dependency job should get scheduled. // ACondition new ACondition("check importe project: " + project.getName()) { @Override public boolean test() throws Exception { System.out.println("Checking project config..."); IJavaProject javaProject = JavaCore.create(project); assertDefaultOutputFolder(javaProject); assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should // have Java // Nature at // this // point assertTrue(GroovyNature.hasGroovyNature(project)); // Should // also have // Groovy // nature assertTrue(GrailsNature.isGrailsAppProject(project)); // Should // look // like // a // Grails // app // to // grails // tooling // ///////////////////////////////// // Check resolved classpath stuff IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false); // A whole bunch of libraries should be there, check for just a // few of those assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "/jsse.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); System.out.println("Checking project config => OK!"); return true; } }.waitFor(10 * 60000); }
From source file:org.grails.ide.eclipse.test.GrailsProjectVersionFixerTest.java
License:Open Source License
/** * Assert that the grails version as apparant from libs on resolved project classpath matches * a given version.//w w w . jav a 2 s. com */ private void assertClasspathVersion(GrailsVersion version) throws Exception { IClasspathEntry[] classpath = JavaCore.create(project).getResolvedClasspath(true); String expectedLib = "grails-core-" + version; assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, expectedLib, classpath); }
From source file:org.grails.ide.eclipse.test.util.GrailsTest.java
License:Open Source License
/** * Verify that an expected classPath entry with given kind and path exists in the classpath. *//*from w ww.java 2 s . c o m*/ protected void assertClassPathEntry(int kind, String path, IClasspathEntry[] classPath) { StringBuffer found = new StringBuffer(); for (IClasspathEntry entry : classPath) { found.append(kindString(entry.getEntryKind()) + ": " + entry.getPath() + "\n"); if (entry.getEntryKind() == kind) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(Path.EMPTY.append(path))) { return; //OK } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // Library paths will vary a lot in location and version numbers, so use an 'approximate' // check to see if it contains some key string. if (entry.getPath().toString().contains(path)) { return; //OK } } else { if (entry.getPath().toString().endsWith(path)) { return; //OK } } } } fail("No classpath entry found for: " + kindString(kind) + ": " + path + "\n" + "found entries are: \n" + found.toString()); }
From source file:org.grails.ide.eclipse.test.util.GrailsTest.java
License:Open Source License
/** * Verify that an expected classPath entry with given kind and path exists in the classpath. *//*from w w w. ja va2s . c o m*/ protected void assertAbsentClassPathEntry(int kind, String path, IClasspathEntry[] classPath) { for (IClasspathEntry entry : classPath) { if (entry.getEntryKind() == kind) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(Path.EMPTY.append(path))) { fail("Class path entry should not be there: " + entry); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // Library paths will vary a lot in location and version numbers, so use an 'approximate' // check to see if it contains some key string. if (entry.getPath().toString().contains(path)) { fail("Class path entry should not be there: " + entry); } } else { if (entry.getPath().toString().endsWith(path)) { fail("Class path entry should not be there: " + entry); } } } } // OK }
From source file:org.grails.ide.eclipse.test.util.GrailsTest.java
License:Open Source License
/** * @param kind/*from w ww. ja va2s.c o m*/ * @return */ protected String kindString(int kind) { switch (kind) { case IClasspathEntry.CPE_SOURCE: return "src"; case IClasspathEntry.CPE_CONTAINER: return "con"; case IClasspathEntry.CPE_LIBRARY: return "lib"; default: return "" + kind; } }
From source file:org.granite.builder.util.ProjectUtil.java
License:Open Source License
public static List<CpEntry> getFullClasspath(IJavaProject project, IClasspathEntry[] classpathEntries) throws CoreException { List<CpEntry> classpath = new ArrayList<CpEntry>(); IWorkspaceRoot workspace = project.getProject().getWorkspace().getRoot(); IPath path = null;/*from w w w.j av a2 s. c o m*/ try { // Output locations. if (project.getOutputLocation() != null) { path = project.getOutputLocation(); File file = workspace.findMember(path).getLocation().toFile(); classpath.add(new CpEntry(path.makeRelative().toString(), path, file, CpEntry.CpeKind.PROJECT_OUTPUT_DIR)); } for (IClasspathEntry cpe : classpathEntries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpe.getOutputLocation() != null) { path = cpe.getOutputLocation(); File file = workspace.findMember(path).getLocation().toFile(); classpath.add(new CpEntry(path.makeRelative().toString(), path, file, CpEntry.CpeKind.SOURCE_OUTPUT_DIR)); } } // Project jars. for (IClasspathEntry cpe : classpathEntries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { path = cpe.getPath(); if (path != null) { IResource member = workspace.findMember(path); String description = path.lastSegment(); if (path.segmentCount() > 1) description += " - " + path.removeLastSegments(1).makeRelative(); if (member != null) classpath.add(new CpEntry(description, path, member.getLocation().toFile(), CpEntry.CpeKind.LIB_JAR)); else classpath.add(new CpEntry(description, path, path.toFile(), CpEntry.CpeKind.LIB_JAR)); } } } // Containers jars/directories. for (IClasspathEntry cpe : classpathEntries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { path = cpe.getPath(); IClasspathContainer container = JavaCore.getClasspathContainer(path, project); String description = container.getDescription(); CpEntry entry = new CpEntry(description, path, (path != null ? path.toFile() : null), CpEntry.CpeKind.CONTAINER_JAR); for (IClasspathEntry ccpe : container.getClasspathEntries()) { path = ccpe.getPath(); String label = path.lastSegment(); if (path.segmentCount() > 1) label += " - " + path.removeLastSegments(1).makeRelative(); File file = path.toFile(); IResource resource = workspace.findMember(path); if (resource != null) file = resource.getLocation().toFile(); entry.getChildren().add(new CpEntry(label, path, file, CpEntry.CpeKind.LIB_JAR)); } classpath.add(entry); } } } catch (Exception e) { String msg = "Problem with classpath location: " + path; throw new CoreException(createErrorStatus(msg, e)); } return classpath; }
From source file:org.gw4e.eclipse.facade.TestResourceGeneration.java
License:Open Source License
public static void getProjectClassPath(IJavaProject project, List<File> dst) throws Exception { IRuntimeClasspathEntry[] rentries = JavaRuntime.computeUnresolvedRuntimeClasspath(project); for (IRuntimeClasspathEntry entry : rentries) { switch (entry.getType()) { case IClasspathEntry.CPE_SOURCE: break; case IClasspathEntry.CPE_PROJECT: break; case IClasspathEntry.CPE_LIBRARY: break; case IClasspathEntry.CPE_VARIABLE: // JRE like entries IRuntimeClasspathEntry[] variableEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, project); break; case IClasspathEntry.CPE_CONTAINER: IRuntimeClasspathEntry[] containerEntries = JavaRuntime.resolveRuntimeClasspathEntry(entry, project);/*from w w w.jav a 2 s . c om*/ for (IRuntimeClasspathEntry containerentry : containerEntries) { dst.add(new File(containerentry.getLocation())); } break; default: throw new Exception("unsupported classpath entry " + entry); } } }
From source file:org.hammurapi.eclipse.plugin.HammurapiBuilder.java
License:Open Source License
/** * @author Daniel Berg jdt-dev@eclipse.org. * @param javaProject/*from w w w . j a v a2 s. c om*/ * @return */ private List getClasspathURLs(IJavaProject javaProject, boolean exportedOnly) throws JavaModelException, MalformedURLException, CoreException { HashSet urls = new HashSet(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); boolean defaultOutputAdded = false; for (int i = 0; i < entries.length; i++) { // Source entries are apparently always assumed to be exported - but don't // report themselves as such. if (!exportedOnly || entries[i].isExported() || entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { IPath outputLocation = null; if (isEclipse_2_1_Safe()) { outputLocation = entries[i].getOutputLocation(); } if (outputLocation == null) { // // If the output location is null then the project's // default output location is being used. // if (!defaultOutputAdded) { defaultOutputAdded = true; outputLocation = javaProject.getOutputLocation(); } } if (outputLocation != null) { // When the output location is the project itself, the project // can't resolve the file - therefore just get the project's // location. if (outputLocation.segmentCount() == 1) { outputLocation = javaProject.getProject().getLocation(); } else { // Output locations are always workspace relative. Do this mess // to get a fully qualified location. outputLocation = javaProject.getProject().getParent().getFile(outputLocation) .getLocation(); } urls.add(outputLocation.addTrailingSeparator().toFile().toURL()); } break; } case IClasspathEntry.CPE_LIBRARY: { // Jars always come with a nice fully specified path. urls.add(new URL("file:/" + entries[i].getPath().toOSString())); break; } case IClasspathEntry.CPE_PROJECT: { IJavaProject dependentProject = (IJavaProject) (ResourcesPlugin.getWorkspace().getRoot() .getProject(entries[i].getPath().segment(0))).getAdapter(IJavaElement.class); urls.addAll(getClasspathURLs(dependentProject, true)); break; } default: { String msg = "Encountered unexpected classpath entry : " + entries[i].getEntryKind(); HammurapiPlugin.report2LogError(msg, null); Status status = new Status(IStatus.ERROR, "HammurapiPlugin", IStatus.ERROR, msg, null); throw new CoreException(status); } } } } return new ArrayList(urls); }