List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath
IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;
From source file:org.eclipse.wb.internal.core.utils.jdt.core.CodeUtils.java
License:Open Source License
/** * Adds {@link IContainer}'s for all source directories of given {@link IJavaProject} and its * required projects./*from ww w . jav a2 s .c om*/ */ private static void addSourceContainers(List<IContainer> containers, Set<IJavaProject> visitedProjects, IJavaProject javaProject, boolean includeRequiredProjects) throws Exception { // check for existence if (!javaProject.exists()) { return; } // check for recursion if (visitedProjects.contains(javaProject)) { return; } visitedProjects.add(javaProject); // prepare information IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = javaProject.getProject(); // add source folders for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IContainer container = (IContainer) root.findMember(entry.getPath()); if (container != null) { containers.add(container); } } } // source folders of required projects if (includeRequiredProjects) { for (String requiredProjectName : javaProject.getRequiredProjectNames()) { addSourceContainers(containers, visitedProjects, requiredProjectName); } } // source folders for fragments if (includeRequiredProjects) { Object model = ReflectivePDE.findModel(project); if (model != null) { BundleDescription bundleDescription = ReflectivePDE.getPluginModelBundleDescription(model); if (bundleDescription != null) { BundleDescription[] fragments = bundleDescription.getFragments(); for (BundleDescription fragment : fragments) { String fragmentProjectName = fragment.getSymbolicName(); addSourceContainers(containers, visitedProjects, fragmentProjectName); } } } } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of output folders for given and required projects. */// w w w .j av a 2 s.co m public static void addOutputLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add output folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { // default output location { IPath outputPath = javaProject.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } // source folder specific output locations for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getOutputLocation(); addAbsoluteLocation(locations, outputPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addOutputLocations(visitedProjects, locations, referencedProject); } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
/** * Adds absolute locations (in file system) of source folders for given and required projects. *///from www . j a v a2 s.c o m public static void addSourceLocations(Set<IProject> visitedProjects, List<String> locations, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // check for recursion if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add source folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath entryPath = entry.getPath(); addAbsoluteLocation(locations, entryPath); } } } } // process required projects IProject[] referencedProjects = project.getReferencedProjects(); for (IProject referencedProject : referencedProjects) { addSourceLocations(visitedProjects, locations, referencedProject); } }
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 {/* w ww . j a v a 2s . com*/ 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.xtend.ide.validator.XtendUIValidator.java
License:Open Source License
protected boolean isInSourceFolder(IJavaProject javaProject, IFile resource) { IPath path = resource.getFullPath(); IClasspathEntry[] classpath;/*from w w w. j a va 2 s . c o m*/ try { classpath = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return false; // not a Java project } for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath entryPath = entry.getPath(); if (entryPath.isPrefixOf(path)) { return true; } } } return false; }
From source file:org.eclipse.xtend.ide.XtendResourceUiServiceProvider.java
License:Open Source License
public boolean isInSourceFolder(IJavaProject javaProject, IFile resource) { IPath path = resource.getFullPath(); IClasspathEntry[] classpath;// w ww .j ava 2s .com try { classpath = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return false; // not a Java project } for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath entryPath = entry.getPath(); if (entryPath.isPrefixOf(path) && !isExcluded(entry, path)) { return true; } } } return false; }
From source file:org.eclipse.xtext.common.types.access.jdt.MockJavaProjectProviderTest.java
License:Open Source License
@Test public void testClasspathResolved() throws CoreException { IJavaProject javaProject = new MockJavaProjectProvider().getJavaProject(null); javaProject.getResolvedClasspath(false); // assertTrue(expandAndLookFor(javaProject, 0, ParameterizedTypes.class.getSimpleName() + ".class")); }
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); }//from www . ja va 2 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 {/* w w w . j a v a 2 s .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.eclipsejc.builder.CapBuilder.java
License:Open Source License
private IPath getConverterPath(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(false); for (IClasspathEntry entry : resolvedClasspath) { if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) continue; IPath path = entry.getPath();//from w ww. j a va 2s . c o m if (!path.lastSegment().equals("api.jar")) continue; IPath libPath = path.removeLastSegments(1); return libPath.append("converter.jar"); } return null; }