List of usage examples for org.eclipse.jdt.core IClasspathEntry getOutputLocation
IPath getOutputLocation();
.class
files generated for this source entry (entry kind #CPE_SOURCE ). From source file:org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.java
License:Open Source License
private List<URL> getOutputFolders(IJavaProject javaProject) throws CoreException, MalformedURLException { List<URL> result = Lists.newArrayListWithExpectedSize(1); IPath path = javaProject.getOutputLocation().addTrailingSeparator(); URL url = new URL(URI.createPlatformResourceURI(path.toString(), true).toString()); result.add(url);/*from w w w.j a va 2 s . c o m*/ for (IClasspathEntry entry : javaProject.getRawClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: path = entry.getOutputLocation(); if (path != null) { url = new URL( URI.createPlatformResourceURI(path.addTrailingSeparator().toString(), true).toString()); result.add(url); } break; default: break; } } return result; }
From source file:org.eclipselabs.jar2uml.JarToUML.java
License:Open Source License
/** * Adds all relevant class file paths for javaProject * @param javaProject//from w w w . j ava2s . c o m * @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.entirej.ide.core.project.EJPluginEntireJClassLoader.java
License:Apache License
private static void processEntry(IJavaProject javaProject, List<URL> urlList, IClasspathEntry entry, boolean ignoreSource) throws MalformedURLException { // This source output ... always included & exported if (!ignoreSource && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null) { URL url = new URL("file", null, outputLocation.toString() + "/"); urlList.add(url);//from w w w. j a v a2 s .c om } } // Referenced project classpath. If this project is exported, // Then all *exported* entries are exported with respect to this // project, else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject ijproject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0)); IJavaProject ref = JavaCore.create(ijproject); Collection<URL> cpEntries = getClasspathEntries(ref, false); urlList.addAll(cpEntries); } // This is the Directories classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath entryPath = entry.getPath(); URL url = new URL("file", null, entryPath.toString()); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (res != null && res.exists()) { url = new URL("file", null, res.getLocation().toString()); } urlList.add(url); } // This is Library classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = entry.getPath(); URL url = new URL("file", null, entryPath.toString()); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (res != null && res.exists()) { url = new URL("file", null, res.getLocation().toString()); } urlList.add(url); } // This is Variables classpath else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String variableName = entry.getPath().segment(0); IPath variablePath = JavaCore.getClasspathVariable(variableName); if (variablePath != null) { URL url = new URL("file", null, variablePath.toString()); urlList.add(url); } } }
From source file:org.fastcode.util.SourceUtil.java
License:Open Source License
/** * * @param javaProject//from w ww . j a v a 2s .c o m * @return */ public static Set<String> getBinaryFoldersForJavaProject(final IJavaProject javaProject) { final Set<String> binaryFolders = new TreeSet<String>(); try { // Get default output folder location. IPath outputPath = javaProject.getOutputLocation(); if (outputPath != null) { binaryFolders.add(outputPath.toString()); } // Find all the output folders by looking for source folders. for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputPath = entry.getOutputLocation(); if (outputPath == null) { continue; } binaryFolders.add(outputPath.toString()); } } } catch (final JavaModelException e) { e.printStackTrace(); } return binaryFolders; }
From source file:org.gololang.gldt.jdt.internal.GoloBuilder.java
License:Apache License
private IPath isOnSourceRoot(IResource resource, IJavaProject javaProject) throws JavaModelException { IPath result = null;//from w w w .jav a 2 s . c o m IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && entry.getPath().isPrefixOf(resource.getFullPath())) { result = entry.getOutputLocation(); if (result == null) { result = javaProject.getOutputLocation(); } break; } } return result; }
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;/* w w w. j av a 2 s.com*/ 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.granite.builder.util.ProjectUtil.java
License:Open Source License
public static IPath getOutputFolder(IJavaProject project, IClasspathEntry cpe) throws CoreException { if (cpe.getOutputLocation() != null) return cpe.getOutputLocation(); return project.getOutputLocation(); }
From source file:org.granite.builder.util.ProjectUtil.java
License:Open Source License
public static List<IPath> getOutputFolders(IJavaProject project) throws CoreException { List<IPath> paths = new ArrayList<IPath>(); for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = cpe.getOutputLocation(); if (output != null) paths.add(output);/*from w ww .ja v a 2 s .c om*/ } } IPath output = project.getOutputLocation(); if (output != null) paths.add(output); return paths; }
From source file:org.granite.builder.util.ProjectUtil.java
License:Open Source License
public static JavaClassInfo getJavaClassInfo(IJavaProject project, IFile resource) throws CoreException { // classPath = "<project name>/<output folder>/<package>/<file>.class" IPath classPath = resource.getFullPath().makeRelative(); // Find output folder: "<project name>/<output folder>". IPath outputFolder = null;// w w w. j av a2s . c o m if (project.getOutputLocation() != null && project.getOutputLocation().isPrefixOf(classPath)) outputFolder = project.getOutputLocation(); else { for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = cpe.getOutputLocation(); if (output != null && output.isPrefixOf(classPath)) { outputFolder = output; break; } } } } if (outputFolder == null) return null; // Compute class name. IPath relativeClassPath = classPath.removeFirstSegments(outputFolder.segmentCount()); IPath relativeClassName = relativeClassPath.removeFileExtension(); String className = relativeClassName.toPortableString().replace('/', '.'); // Compute java source path: "<package>/<class name>[$<inner class>].java". String javaFullPath = relativeClassName.addFileExtension("java").toPortableString(); String javaFilePath = javaFullPath; int iDollar = javaFilePath.indexOf('$'); if (iDollar != -1) javaFilePath = javaFilePath.substring(0, iDollar) + ".java"; IJavaElement javaElement = project.findElement(new Path(javaFilePath)); if (javaElement == null) return null; IJavaElement sourceFolder = javaElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (sourceFolder == null) return null; IPath folderPath = sourceFolder.getPath().makeRelative(); if (folderPath.segmentCount() > 0) folderPath = folderPath.removeFirstSegments(1); // Fix issues with project not in the workspace directory. outputFolder = project.getProject().getWorkspace().getRoot().findMember(outputFolder).getLocation(); return new JavaClassInfo(folderPath.toPortableString(), javaFullPath, className, new File(outputFolder.toPortableString(), relativeClassPath.toPortableString())); }
From source file:org.infinitest.eclipse.workspace.JavaProjectSet.java
License:Open Source License
private List<File> customOutputDirectoriesFor(EclipseProject project) { List<File> outputDirectories = Lists.newArrayList(); for (IClasspathEntry each : project.getClasspathEntries()) { IPath outputLocation = each.getOutputLocation(); if (outputLocation != null) { File file = absoluteFile(outputLocation); outputDirectories.add(file); }/*from w w w . ja v a 2 s . co m*/ } return outputDirectories; }