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:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java
License:Open Source License
private void resolveClasspathEntries(Set<URL> urls, IWorkspaceRoot root, IClasspathEntry[] entries) throws JavaModelException { for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path.segmentCount() >= 2) { IFolder sourceFolder = root.getFolder(path); try { urls.add(new URL("file:///" + sourceFolder.getRawLocation().toOSString() + "/")); } catch (MalformedURLException e) { }//from w ww . j a v a 2s.c o m } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = entry.getPath(); covertPathToUrl(javaProject.getProject(), urls, sourcePath); IPath sourceOutputPath = entry.getOutputLocation(); covertPathToUrl(javaProject.getProject(), urls, sourceOutputPath); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(JRClasspathContainer.ID)) continue; IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), javaProject); resolveClasspathEntries(urls, root, cont.getClasspathEntries()); } } }
From source file:net.sf.jasperreports.eclipse.classpath.OutputFolderClassLoader.java
License:Open Source License
private byte[] loadClassData(String className, IJavaProject javaProject) throws Exception { IPath defaultLocationPath = javaProject.getOutputLocation(); IWorkspaceRoot wsRoot = javaProject.getProject().getWorkspace().getRoot(); IFolder folder = wsRoot.getFolder(defaultLocationPath); String prjDefaultLocation = folder.getLocation().toOSString(); byte[] classBytes = loadClassFile(prjDefaultLocation + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes == null) { // Iterate over the (possible) output locations of the sourcefolder classpath entries IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry e : classpathEntries) { if (e.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath entryOutputLocation = e.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classBytes = loadClassFile( entryOutputFolder + "/" + className.replaceAll("\\.", "/") + ".class"); if (classBytes != null) break; }/* w w w .ja va 2 s . c o m*/ } } } return classBytes; }
From source file:net.sourceforge.floggy.eclipse.builder.MTJBuilder.java
License:Open Source License
/** * This is where the classpool is actually set. The typical case only requires adding the required jar files * to the classpool (classPool and classPoolList), however if the project is dependent on other projects then * not only do we need the jar files from these dependencies but we also need the output folders. * @TODO EXPERIMENTAL - Dependencies support should be considered experimental at this time because it isn't fully tested ! *///from w w w .j a v a 2s . co m private void configureClassPool(ClassPool classPool, List classPoolList, IClasspathEntry[] entries, IProject project, boolean isRootProject) throws NotFoundException, JavaModelException { IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); IPath classIPath = classpathEntry.getPath(); if ((isRootProject || classpathEntry.isExported()) && classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { pathName = getAccessablePathName(classIPath, project); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { classIPath = classpathEntry.getOutputLocation(); if (classIPath == null) { classIPath = JavaCore.create(project).getOutputLocation(); } pathName = getAccessablePathName(classIPath, project); } else { // Currently we only add : All source folders, All libs in the root project & Exported libs in other projects continue; } if (pathName.contains("floggy-persistence-framework-impl.jar")) { continue; } if (pathName != null && !classPoolList.contains(pathName)) { LOG.debug(pathName + " added to classPool"); classPoolList.add(pathName); classPool.appendClassPath(pathName); } else { LOG.debug(pathName + " alreaded added to classPool"); } } }
From source file:org.antlr.eclipse.smapinstaller.SMapInstallerBuilder.java
License:Open Source License
/** * Installs the modified smap into a generated classfile * @param resource/* w ww.j a v a 2s.c o m*/ * @throws JavaModelException */ protected void installSmap(final IResource resource) throws JavaModelException { // We only work on smap files -- skip everything else if (!(resource instanceof IFile)) return; IFile smapIFile = (IFile) resource; if (!"smap".equalsIgnoreCase(smapIFile.getFileExtension())) return; IJavaProject javaProject = JavaCore.create(smapIFile.getProject()); // get the name of the corresponding java source file IPath smapPath = smapIFile.getFullPath(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0, l = classpathEntries.length; i < l; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; if (!entry.getPath().isPrefixOf(smapPath)) continue; // found the right source container IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) outputLocation = javaProject.getOutputLocation(); // strip the source dir and .smap suffix String sourceDir = entry.getPath().toString(); String smapName = smapPath.toString(); String javaSourceName = smapName.substring(0, smapName.length() - 5) + ".java"; String className = smapName.substring(sourceDir.length(), smapName.length() - 5) + ".class"; IPath path = outputLocation.append(className); IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation(); IPath classFileLocation = workspaceLoc.append(path); IResource classResource = ResourcesPlugin.getWorkspace().getRoot().findMember(javaSourceName); File classFile = classFileLocation.toFile(); File smapFile = smapIFile.getLocation().toFile(); try { String installSmap = classResource.getPersistentProperty(AntlrBuilder.INSTALL_SMAP); if ("true".equals(installSmap)) SDEInstaller.install(classFile, smapFile); } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convertSource(ISigilProjectModel sigil, IClasspathEntry cp, List<File> files) throws JavaModelException { IPath path = cp.getOutputLocation() == null ? sigil.getJavaModel().getOutputLocation() : cp.getOutputLocation();/* w w w .j av a2s .co m*/ IFolder buildFolder = sigil.getProject().getFolder(path.removeFirstSegments(1)); if (buildFolder.exists()) { files.add(buildFolder.getLocation().toFile()); } }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.standalone.StandaloneRuntimeResolver.java
License:Open Source License
protected Collection<String> getSourceOutputLocations(boolean istest) { Collection<IClasspathEntry> entries = getSourceEntries(istest); Set<String> locations = new HashSet<String>(); for (IClasspathEntry entry : entries) { IPath path = entry.getOutputLocation(); // For source entries, path is relative to workspace root path = getWorkspaceFullPath(path); if (path != null) { locations.add(path.toOSString()); }/*from ww w.ja v a 2 s. c om*/ } return locations; }
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.JavaPackageFragmentRootHandler.java
License:Open Source License
/** * /*from w w w . j a va 2s . c o m*/ * Determines if the given package fragment root corresponds to the class * path entry path. * <p/> * Note that different package fragment roots may point to the same class * path entry. * <p/> * Example: * <p/> * A Java project may have the following package fragment roots: * <p/> * - src/main/java * <p/> * - src/main/resources * <p/> * Both may be using the same output folder: * <p/> * target/classes. * <p/> * In this case, the output folder will have a class path entry - * target/classes - and it will be the same for both roots, and this method * will return true for both roots if passed the entry for target/classes * * @param root * to check if it corresponds to the given class path entry path * @param entry * @return true if root is at the given entry */ private static boolean isRootAtEntry(IPackageFragmentRoot root, IPath entry) { try { IClasspathEntry cpe = root.getRawClasspathEntry(); if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (outputLocation == null) { outputLocation = root.getJavaProject().getOutputLocation(); } IPath location = ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation(); if (entry.equals(location)) { return true; } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } IResource resource = root.getResource(); if (resource != null && entry.equals(resource.getLocation())) { return true; } IPath path = root.getPath(); if (path != null && entry.equals(path)) { return true; } return false; }
From source file:org.cloudfoundry.ide.eclipse.server.ui.internal.CloudRebelUIHandler.java
License:Open Source License
protected List<String> getClasspathSourceOutputPaths(IProject project) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); List<String> outputPaths = new ArrayList<String>(); if (javaProject != null) { try {/* www.ja v a 2 s .com*/ IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); if (classpath != null) { for (IClasspathEntry entry : classpath) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation().toString() : null; if (outputPath != null && !outputPaths.contains(outputPath) && !outputPath.contains("target/test-classes")) {//$NON-NLS-1$ outputPaths.add(outputPath); } } } } String outputPath = javaProject.getOutputLocation() != null ? javaProject.getOutputLocation().toString() : null; if (outputPath != null && !outputPaths.contains(outputPath)) { outputPaths.add(outputPath); } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } } return outputPaths; }
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 * //from w w w. j a v a2 s.c om * @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.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//from w w w . ja va 2 s . com * @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); } } }