List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath
IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;
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. jav a2s. c o m*/ * @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.eclipselabs.jar2uml.JarToUML.java
License:Open Source License
/** * Adds all relevant class file paths for javaProject * @param javaProject//from ww w .j a v a 2 s. c om * @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.eclipselabs.jar2uml.test.JarToUMLTest.java
License:Open Source License
/** * Test method for {@link org.eclipselabs.jar2uml.JarToUML#findJavaProjectReferences(org.eclipse.jdt.core.IJavaProject, java.util.Set)}. * @throws JavaModelException //from ww w .ja v a 2 s . c om */ public void testFindJavaProjectReferences() throws JavaModelException { // // Retrieve Java project // IProject project = getProject(javatestProject); IJavaProject jproject = JarToUML.getJavaProject(project.getFullPath()); // // Retrieve another Java project and add it to the classpath of the first project // IProject projectref = getProject(javatestReferredProject); IClasspathEntry[] cp = jproject.getResolvedClasspath(true); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : cp) { entries.add(entry); } entries.add(JavaCore.newProjectEntry(projectref.getFullPath())); jproject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); JarToUMLResources.logger.info("Java project classpath entries: " + entries); IJavaProject jprojectref = JarToUML.getJavaProject(projectref.getFullPath()); // // Find references of the first project // Set<IJavaProject> refs = new HashSet<IJavaProject>(); JarToUML.findJavaProjectReferences(jproject, refs); JarToUMLResources.logger.info("Java project references: " + refs); assertFalse(refs.isEmpty()); assertTrue(refs.contains(jprojectref)); }
From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java
License:Apache License
private static Collection<URL> getClasspathEntries(IJavaProject javaProject, boolean ignoreSource) { if (javaProject == null) { throw new NullPointerException( "Trying to get hte projects class path, but the project passed was null"); }/*from w w w .j a v a 2s. com*/ try { if (!javaProject.exists()) { return new ArrayList<URL>(); } // IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); List<URL> urlList = toURLS(javaProject, entries, ignoreSource); //add Project output path IPath outputLocation = null; try { outputLocation = javaProject.getOutputLocation(); IPath path = javaProject.getProject().getLocation(); outputLocation = path.append(outputLocation.removeFirstSegments(1)); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (outputLocation != null) { URL url = new URL("file", null, outputLocation.toString() + "/"); urlList.add(url); } return urlList; } catch (JavaModelException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelComponentUtils.java
License:Open Source License
private static String getComponentClassFromJar(IProject project, String scheme) { IJavaProject jpr = JavaCore.create(project); if (jpr.exists()) { try {/*from w w w . j a v a2s. c om*/ IClasspathEntry[] resolvedClasspath = jpr.getResolvedClasspath(true); return getComponentClassFromClasspath(scheme, resolvedClasspath); } catch (JavaModelException ex) { CamelModelServiceCoreActivator.pluginLog().logError(ex); } } return null; }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelComponentUtils.java
License:Open Source License
/** * returns the component class for the given scheme * * @param scheme//from ww w . j a va2s. co m * @param project * @return the class or null if not found */ protected static String getComponentJSon(String scheme, IProject project) { IJavaProject jpr = JavaCore.create(project); if (jpr.exists()) { try { IClasspathEntry[] resolvedClasspath = jpr.getResolvedClasspath(true); return getComponentJSONFromClasspath(scheme, resolvedClasspath); } catch (JavaModelException ex) { CamelModelServiceCoreActivator.pluginLog().logError(ex); } } return null; }
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 w ww . ja v a 2 s. 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"); }
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 ww . ja v a 2 s .c om*/ 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. * /* w w w . ja v a2 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.//from w w w.j av a 2 s . 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); }