List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT
int CPE_PROJECT
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.
Click Source Link
From source file:org.springsource.ide.eclipse.gradle.core.ClassPath.java
License:Open Source License
public IClasspathEntry[] getProjectEntries() { Collection<IClasspathEntry> entries = getEntries(IClasspathEntry.CPE_PROJECT); return entries.toArray(new IClasspathEntry[entries.size()]); }
From source file:org.springsource.ide.eclipse.gradle.core.GradleProject.java
License:Open Source License
/** * @param all/*w w w . j av a2s . c o m*/ * @param subProgressMonitor */ private void setProjectDependencies(EclipseProject projectModel, IProjectMapper projectMapper, IProgressMonitor monitor) throws JavaModelException { DomainObjectSet<? extends EclipseProjectDependency> projectDeps = projectModel.getProjectDependencies(); //TODO: we remove and re-add all project dep entries, even if they didn't change. Should we optimize this to // only add/remove when entries have changed? //TODO: We could mark 'our' entries with a special classpath attribute. That way user's can add their own // and we can avoid zapping them on each refresh. //TODO: access rules etc.. (what is that? can gradle give something like this to us, or is just using the default ok) IJavaProject javaProject = getJavaProject(); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); int totalWork = 2 * (projectDeps.size() + oldClasspath.length); monitor.beginTask("Converting gradle project dependencies to Eclipse", totalWork); try { //Convert gradle entries into Eclipse classpath entries List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); for (EclipseProjectDependency dep : projectDeps) { IClasspathEntry newEntry = newProjectEntry(projectMapper, dep); if (newEntry != null) { entries.add(newEntry); } monitor.worked(1); } for (IClasspathEntry newEntry : this.getDependencyComputer().getProjectEntries(projectModel)) { entries.add(newEntry); } //Remove old project entries and replace with new ones. ClassPath newClasspath = new ClassPath(this, entries.size()); newClasspath.addAll(entries); for (IClasspathEntry oldEntry : oldClasspath) { if (oldEntry.getEntryKind() != IClasspathEntry.CPE_PROJECT) { newClasspath.add(oldEntry); } monitor.worked(1); } newClasspath.setOn(javaProject, new SubProgressMonitor(monitor, totalWork / 2)); } finally { monitor.done(); } }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertClasspathProjectEntry(IProject expectProject, IJavaProject project) throws JavaModelException { IClasspathEntry[] classpath = project.getRawClasspath(); StringBuilder msg = new StringBuilder(); for (IClasspathEntry e : classpath) { if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath path = e.getPath();// w w w. j av a2s.c o m if (expectProject.getFullPath().equals(path)) { return; //OK } msg.append(e + "\n"); } } fail("Not found '" + expectProject + "':\n" + msg.toString()); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertNoClasspathProjectEntry(IProject expectProject, IJavaProject project) throws JavaModelException { IClasspathEntry[] classpath = project.getRawClasspath(); for (IClasspathEntry e : classpath) { if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath path = e.getPath();// www. ja v a2 s .c om if (expectProject.getFullPath().equals(path)) { fail("Found '" + expectProject + "'"); } } } }
From source file:org.switchyard.tools.cxf.Activator.java
License:Open Source License
static ClassLoader getProjectBuildClassLoader(IJavaProject javaProject) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(/* ww w. j av a2 s. c o m*/ new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-1$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = classpathEntry.getPath(); if (!BLACKLIST.matcher(path.lastSegment()).find()) { urls.add(new File(path.toOSString()).toURI().toURL()); } } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), Activator.class.getClassLoader()); }
From source file:org.switchyard.tools.cxf.Java2WSDLOperation.java
License:Open Source License
private ClassLoader getProjectBuildClassLoader(IType interfaceType) throws Exception { IJavaProject javaProject = interfaceType.getJavaProject(); IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(//w w w. j a v a 2 s . c o m new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }
From source file:org.switchyard.tools.ui.JavaUtil.java
License:Open Source License
/** * Creates a ClassLoader using the project's build path. * //from w ww. j av a 2s .c o m * @param javaProject the Java project. * @param parentClassLoader the parent class loader, may be null. * * @return a new ClassLoader based on the project's build path. * * @throws Exception if something goes wrong. */ public static ClassLoader getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add( new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-1$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } if (parentClassLoader == null) { return new URLClassLoader(urls.toArray(new URL[urls.size()])); } else { return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader); } }
From source file:org.teavm.eclipse.TeaVMProjectBuilder.java
License:Apache License
private Set<IProject> getRelatedProjects() throws CoreException { Set<IProject> projects = new HashSet<>(); Set<IProject> visited = new HashSet<>(); Queue<IProject> queue = new ArrayDeque<>(); queue.add(getProject());//ww w . j ava 2 s . c o m IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); while (!queue.isEmpty()) { IProject project = queue.remove(); if (!visited.add(project) || !project.hasNature(JavaCore.NATURE_ID)) { continue; } projects.add(project); IJavaProject javaProject = JavaCore.create(project); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { project = (IProject) root.findMember(entry.getPath()); queue.add(project); } } } return projects; }
From source file:org.teavm.eclipse.TeaVMProjectBuilder.java
License:Apache License
private void prepareClassPath() throws CoreException { classPath = new URL[0]; sourceContainers = new IContainer[0]; sourceProviders = new SourceFileProvider[0]; IProject project = getProject();/* www .j a va 2 s. c o m*/ if (!project.hasNature(JavaCore.NATURE_ID)) { return; } IJavaProject javaProject = JavaCore.create(project); PathCollector collector = new PathCollector(); SourcePathCollector srcCollector = new SourcePathCollector(); SourcePathCollector binCollector = new SourcePathCollector(); SourceFileCollector sourceFileCollector = new SourceFileCollector(); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); try { if (javaProject.getOutputLocation() != null) { IContainer container = (IContainer) workspaceRoot.findMember(javaProject.getOutputLocation()); collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } Queue<IJavaProject> projectQueue = new ArrayDeque<>(); projectQueue.add(javaProject); Set<IJavaProject> visitedProjects = new HashSet<>(); while (!projectQueue.isEmpty()) { javaProject = projectQueue.remove(); if (!visitedProjects.add(javaProject)) { continue; } IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: try { collector.addPath(entry.getPath()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } if (entry.getSourceAttachmentPath() != null) { sourceFileCollector.addFile(entry.getSourceAttachmentPath()); } break; case IClasspathEntry.CPE_SOURCE: if (entry.getOutputLocation() != null) { try { IResource res = workspaceRoot.findMember(entry.getOutputLocation()); if (res != null) { collector.addPath(res.getLocation()); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } IContainer srcContainer = (IContainer) workspaceRoot.findMember(entry.getPath()); if (srcContainer != null) { srcCollector.addContainer(srcContainer); sourceFileCollector.addFile(srcContainer.getLocation()); try { collector.addPath(srcContainer.getLocation()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } break; case IClasspathEntry.CPE_PROJECT: { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); IProject depProject = resource.getProject(); if (!depProject.hasNature(JavaCore.NATURE_ID)) { break; } IJavaProject depJavaProject = JavaCore.create(depProject); if (depJavaProject.getOutputLocation() != null) { try { IContainer container = (IContainer) workspaceRoot .findMember(depJavaProject.getOutputLocation()); if (container != null) { collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } projectQueue.add(depJavaProject); break; } } } } classPath = collector.getUrls(); sourceContainers = srcCollector.getContainers(); classFileContainers = binCollector.getContainers(); sourceProviders = sourceFileCollector.getProviders(); }
From source file:pt.org.aguiaj.core.AguiaJActivator.java
License:Open Source License
private void addDependencyPaths(List<IPath> workingDirs, IPath dir) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); try {/* w ww . j a v a 2 s . c om*/ for (IProject proj : projects) { if (proj.getLocation().equals(dir) && proj.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProj = (IJavaProject) proj.getNature(JavaCore.NATURE_ID); IClasspathEntry[] classpath = javaProj.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { for (IProject p : projects) { if (p.isOpen() && p.hasNature(JavaCore.NATURE_ID) && p.getLocation().lastSegment().equals(entry.getPath().lastSegment())) { IJavaProject javaProj2 = (IJavaProject) proj.getNature(JavaCore.NATURE_ID); IPath path = p.getLocation() .append(javaProj2.getOutputLocation().lastSegment()); workingDirs.add(path); } } } } } } } catch (Exception e) { e.printStackTrace(); } }