List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:org.codehaus.aspectwerkz.ide.eclipse.core.AwCorePlugin.java
License:Open Source License
/** * Build the list of URL for the given project * Resolve container (ie JRE jars) and dependancies and project output folder * /*w w w . ja v a2 s. c o m*/ * @param project * @return */ public List getProjectClassPathURLs(IJavaProject project) { List paths = new ArrayList(); try { // configured classpath IClasspathEntry classpath[] = project.getResolvedClasspath(false); for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; URL urlEntry = null; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); Object target = JavaModel.getTarget(workspaceRoot, path.getPath(), false); if (target != null) { // inside the workspace if (target instanceof IResource) { urlEntry = ((IResource) target).getLocation().toFile().toURL(); } else if (target instanceof File) { urlEntry = ((File) target).toURL(); } } } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outPath = path.getOutputLocation(); if (outPath != null) { //TODO : don't know if I ll have absolute path here urlEntry = outPath.toFile().toURL(); } } if (urlEntry != null) { paths.add(urlEntry); } else { AwLog.logTrace("project loader - ignored " + path.toString()); } } // project build output IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); paths.add(outputPath.toFile().toURL()); } catch (Exception e) { AwLog.logError("Could not build project path", e); } return paths; }
From source file:org.codehaus.groovy.eclipse.core.ClasspathContainerTest.java
License:Apache License
private List<IClasspathEntry> getGroovyAllEntries(IClasspathEntry[] entries) { List<IClasspathEntry> groovyAllEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : entries) { if (entry.getPath().toPortableString().contains("groovy-all")) { groovyAllEntries.add(entry); }// w w w . j a v a 2 s . co m } return groovyAllEntries; }
From source file:org.codehaus.groovy.eclipse.core.ClasspathContainerTest.java
License:Apache License
private List<IClasspathEntry> getNonPluginEntries(IClasspathEntry[] entries) { List<IClasspathEntry> nonPluginEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : entries) { if (!entry.getPath().toPortableString().contains("/org.codehaus.groovy")) { nonPluginEntries.add(entry); }/*from ww w . j av a 2 s. c o m*/ } return nonPluginEntries; }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
public static void removeLibraryFromClasspath(final IJavaProject javaProject, final IPath libraryPath) throws JavaModelException { final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { final IClasspathEntry entry = oldEntries[i]; if (entry.getPath().equals(libraryPath)) { final IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(oldEntries, i); javaProject.setRawClasspath(newEntries, null); return; }// ww w .j ava2s .co m } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
public static boolean hasClasspathContainer(final IJavaProject javaProject, final IPath libraryPath) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) return false; final IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (ObjectUtils.equals(entry.getPath(), libraryPath) || libraryPath.isPrefixOf(entry.getPath())) { return true; }// w w w.j ava 2 s .c om } } return false; }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Looks through a set of classpath entries and checks to see if the path is * in them.// w w w. j av a 2s . co m * * @param project * The project to search. * @param possiblePath * The path to check the entries for. * @return If possiblePath is included in entries returns true, otherwise * returns false. * @throws JavaModelException */ private static boolean includesClasspathEntry(IJavaProject project, String entryName) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getPath().lastSegment().equals(entryName)) { return true; } } return false; }
From source file:org.codehaus.groovy.eclipse.dsl.tests.BuiltInDSLInferencingTests.java
License:Open Source License
public void testSanity() throws Exception { IJavaProject javaProject = JavaCore.create(project); assertTrue("Should have DSL support classpath container", GroovyRuntime.hasClasspathContainer(javaProject, GroovyDSLCoreActivator.CLASSPATH_CONTAINER_ID)); IClasspathContainer container = JavaCore .getClasspathContainer(GroovyDSLCoreActivator.CLASSPATH_CONTAINER_ID, javaProject); IClasspathEntry[] cpes = container.getClasspathEntries(); assertEquals("Wrong number of classpath entries found: " + Arrays.toString(cpes), 2, cpes.length); IClasspathEntry pluginEntry = null;/*from w w w . ja v a 2 s. c om*/ IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { if (entry.getPath().toString().contains("plugin_dsld")) { pluginEntry = entry; } } IPackageFragmentRoot root = null; List<String> elements = new ArrayList<String>(); for (IJavaElement elt : javaProject.getChildren()) { elements.add(elt.getElementName()); if (elt.getElementName().contains("plugin_dsld")) { root = (IPackageFragmentRoot) elt; } } List<String> possibleFrags = new ArrayList<String>(); for (IPackageFragment frag : javaProject.getPackageFragments()) { if (frag.getElementName().equals("dsld")) { possibleFrags.add(frag.toString()); possibleFrags.add(" ["); for (IJavaElement child : frag.getChildren()) { possibleFrags.add(" " + child.getElementName()); } possibleFrags.add(" ]"); } } assertNotNull("Did not find the Plugin DSLD classpath entry. Exsting resolved roots:\n" + printList(elements) + "\nOther DSLD fragments:\n" + printList(possibleFrags), pluginEntry); assertNotNull("Plugin DSLD classpath entry should exist. Exsting resolved roots:\n" + printList(elements) + "\nOther DSLD fragments:\n" + printList(possibleFrags), root); assertTrue("Plugin DSLD classpath entry should exist", root.exists()); ExternalPackageFragmentRoot ext = (ExternalPackageFragmentRoot) root; ext.resource().refreshLocal(IResource.DEPTH_INFINITE, null); root.close(); root.open(null); IPackageFragment frag = root.getPackageFragment("dsld"); assertTrue("DSLD package fragment should exist", frag.exists()); }
From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java
License:Apache License
/** * Need to recursively walk the classpath and visit all dependent projects * Not looking at classpath containers yet. * * @param javaProject// w ww .j ava2 s . co m * @param entries */ private void addClasspathEntriesForProject(IJavaProject javaProject, SortedSet<String> sourceEntries, SortedSet<String> binEntries) { List<IJavaProject> dependingProjects = new ArrayList<IJavaProject>(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { int kind = entry.getEntryKind(); switch (kind) { case IClasspathEntry.CPE_LIBRARY: IPath libPath = entry.getPath(); if (!isPathInWorkspace(libPath)) { sourceEntries.add(libPath.toOSString()); break; } //$FALL-THROUGH$ case IClasspathEntry.CPE_SOURCE: IPath srcPath = entry.getPath(); String sloc = getProjectLocation(srcPath); if (srcPath.segmentCount() > 1) { sloc += File.separator + srcPath.removeFirstSegments(1).toOSString(); } sourceEntries.add(sloc); IPath outPath = entry.getOutputLocation(); if (outPath != null) { String bloc = getProjectLocation(outPath); if (outPath.segmentCount() > 1) { bloc += File.separator + outPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } break; case IClasspathEntry.CPE_PROJECT: dependingProjects.add(javaProject.getJavaModel().getJavaProject(entry.getPath().lastSegment())); break; } } IPath defaultOutPath = javaProject.getOutputLocation(); if (defaultOutPath != null) { String bloc = getProjectLocation(javaProject); if (defaultOutPath.segmentCount() > 1) { bloc += File.separator + defaultOutPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } } catch (JavaModelException e) { GroovyCore.logException("Exception generating classpath for launching groovy script", e); } // recur through dependent projects for (IJavaProject dependingProject : dependingProjects) { if (dependingProject.getProject().isAccessible()) { addClasspathEntriesForProject(dependingProject, sourceEntries, binEntries); } } }
From source file:org.codehaus.groovy.m2eclipse.GroovyProjectConfigurator.java
License:Open Source License
public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException { SourceType sourceType = getSourceType(facade); if (sourceType != null) { // add source folders IJavaProject javaProject = JavaCore.create(facade.getProject()); IPath projectPath = facade.getFullPath(); if (sourceType == SourceType.TEST || sourceType == SourceType.BOTH) { IPath testPath = projectPath.append("src/test/groovy"); //$NON-NLS-1$ IPath testOutPath = projectPath.append("target/test-classes"); //$NON-NLS-1$ if (!hasEntry(javaProject, testPath)) { GroovyRuntime.addClassPathEntryToFront(javaProject, JavaCore.newSourceEntry(testPath, new Path[0], testOutPath)); }// ww w . j ava2 s . c o m } if (sourceType == SourceType.MAIN || sourceType == SourceType.BOTH) { IPath sourcePath = projectPath.append("src/main/groovy"); //$NON-NLS-1$ IPath sourceOutPath = projectPath.append("target/classes"); //$NON-NLS-1$ if (!hasEntry(javaProject, sourcePath)) { GroovyRuntime.addClassPathEntryToFront(javaProject, JavaCore.newSourceEntry(sourcePath, new Path[0], sourceOutPath)); } } // now remove the generated sources from the classpath if it exists IClasspathEntry[] allEntries = javaProject.getRawClasspath(); for (IClasspathEntry entry : allEntries) { if (entry.getPath().equals(javaProject.getProject() .getFolder("target/generated-sources/groovy-stubs/main").getFullPath())) { GroovyRuntime.removeClassPathEntry(javaProject, entry); break; } } } }
From source file:org.codehaus.groovy.m2eclipse.GroovyProjectConfigurator.java
License:Open Source License
private boolean hasEntry(IJavaProject javaProject, IPath path) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getPath().equals(path)) { return true; }/* w w w . ja v a 2 s . com*/ } return false; }