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:com.google.test.metric.eclipse.internal.core.TestabilityLauncher.java
License:Apache License
public String[] getClassPaths(IJavaProject javaProject, String projectLocation) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); String[] classPaths = new String[classPathEntries.length + 1]; for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classPathEntry = classPathEntries[i]; String classPathString = null; IPath outputPath = classPathEntry.getOutputLocation(); if (outputPath != null) { classPathString = projectLocation + outputPath.toOSString(); } else {/*from w ww. ja v a2 s .c om*/ IPath classPath = classPathEntry.getPath(); classPathString = classPath.toOSString(); if (!classPathString.startsWith(System.getProperty("file.separator"))) { classPathString = System.getProperty("file.separator") + classPathString; } classPathString = projectLocation + classPathString; } classPathString = classPathString.replace("\\", "/"); classPaths[i] = classPathString; } String defaultOutputPath = javaProject.getOutputLocation().toOSString(); defaultOutputPath = defaultOutputPath.replace("\\", "/"); classPaths[classPathEntries.length] = projectLocation + defaultOutputPath; return classPaths; }
From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java
License:Open Source License
@Override protected void resolveClasspathEntry(IJavaProject project, IClasspathEntry entry, ILoader loader, boolean includeSource, boolean cpeFromMainProject) { entry = JavaCore.getResolvedClasspathEntry(entry); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { resolveSourcePathEntry(includeSource ? JavaSourceLoader.SOURCE : Loader.APPLICATION, includeSource, cpeFromMainProject, entry.getPath(), entry.getOutputLocation(), entry.getExclusionPatterns(), "java"); break;//from w w w. j a va2s . c o m } case IClasspathEntry.CPE_LIBRARY: { resolveLibraryPathEntry(loader, entry.getPath()); break; } case IClasspathEntry.CPE_PROJECT: { resolveProjectPathEntry(loader, includeSource, entry.getPath()); break; } case IClasspathEntry.CPE_CONTAINER: { try { IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project); IClasspathEntry[] entries = cont.getClasspathEntries(); resolveClasspathEntries(project, Arrays.asList(entries), cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL, includeSource, false); } catch (CoreException e) { System.err.println(e); Assertions.UNREACHABLE(); } } } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void addJavaProject(IJavaProject project) throws CoreException { if (project != null) { final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>(); for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_BINARY && fragment.getSourceAttachmentPath() != null) { File classpathLocation; if (fragment.isExternal()) { classpathLocation = fragment.getPath().toFile(); } else { classpathLocation = toFile(fragment.getPath()); }//from w w w . ja v a2s .c om if (classpathLocation != null) { classpath.put(classpathLocation, fragment); } } } final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath); final Set<File> projectLocations = new HashSet<File>(); final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR); if (jarLocation != null) { // maven binary project projectLocations.add(new File(jarLocation)); } else { // regular project projectLocations.add(toFile(project.getOutputLocation())); for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { projectLocations.add(toFile(cpe.getOutputLocation())); } } } synchronized (lock) { projects.put(project, projectLocations); for (File projectLocation : projectLocations) { locations.put(projectLocation, projectInfo); } } } }
From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java
License:Open Source License
/** * Get all the resolved classpath entries for a specific project. The entries * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved * or included in the result. At also add the source and output folder provided with the * project// w w w . j a v a 2 s .c om * * @param project the project where the file to compile is contained, must be not null * @return a not null list of string that contains the classpath to include in the compilation project */ private List<String> getClasspaths(IProject project) { IJavaProject jprj = JavaCore.create(project); List<String> classpath = new ArrayList<String>(); IWorkspaceRoot wsRoot = project.getWorkspace().getRoot(); if (jprj != null) { try { IClasspathEntry[] entries = jprj.getRawClasspath(); //Add the default output folder if any IPath defaultLocationPath = jprj.getOutputLocation(); if (defaultLocationPath != null) { IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } for (IClasspathEntry en : entries) { if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String containerPath = en.getPath().toString(); //Don't add the eclipse runtime and the classpath extension defined in the exclusion list if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER) && !classpathExclusionSet.contains(containerPath)) { addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath, jprj); } } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) { classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator); } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) { //check if is a source folder and if it has a custom output folder to add them also to the classpath IPath entryOutputLocation = en.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } } else { //It is a jar check if it is internal to the workspace of external IPath location = wsRoot.getFile(en.getPath()).getLocation(); if (location == null) { //The location could not be resolved from the root of the workspace, it is external classpath.add(en.getPath().toOSString()); } else { //The location has been resolved from the root of the workspace, it is internal classpath.add(location.toOSString()); } } } } catch (Exception ex) { ex.printStackTrace(); } } return classpath; }
From source file:com.javadude.antxr.eclipse.smapinstaller.SMapInstallerBuilder.java
License:Open Source License
/** * Installs the modified smap into a generated classfile * @param resource// ww w . ja v a2 s . c om * @throws JavaModelException */ protected void installSmap(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 (IClasspathEntry entry : classpathEntries) { 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(AntxrBuilder.INSTALL_SMAP); if ("true".equals(installSmap)) { SDEInstaller.install(classFile, smapFile); } } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.javapathfinder.vjp.DefaultProperties.java
License:Open Source License
/** * append all relevant paths from the target project settings to the vm.classpath *//*from w w w.j av a2s . c o m*/ private static void appendProjectClassPaths(IJavaProject project, StringBuilder cp) { try { // we need to maintain order LinkedHashSet<IPath> paths = new LinkedHashSet<IPath>(); // append the default output folder IPath defOutputFolder = project.getOutputLocation(); if (defOutputFolder != null) { paths.add(defOutputFolder); } // look for libraries and source root specific output folders for (IClasspathEntry e : project.getResolvedClasspath(true)) { IPath ePath = null; switch (e.getContentKind()) { case IClasspathEntry.CPE_LIBRARY: ePath = e.getPath(); break; case IClasspathEntry.CPE_SOURCE: ePath = e.getOutputLocation(); break; } if (ePath != null && !paths.contains(ePath)) { paths.add(ePath); } } for (IPath path : paths) { String absPath = getAbsolutePath(project, path).toOSString(); // if (cp.length() > 0) { // cp.append(Config.LIST_SEPARATOR); // } // only add classes that are found in bin if (absPath.contains("/bin")) cp.append(absPath); } System.out.println("cp is" + cp); } catch (JavaModelException jme) { VJP.logError("Could not append Project classpath", jme); } }
From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java
License:Open Source License
/** * Given classpath entries from a java project, populate a list of * collections.//from w w w. j ava 2 s . c om * * @param selectedPathElementsLocations the output path locations * @param classPathEntries the java project class path entries * @param javaProject the java project * @throws JavaModelException if invalid classpath */ private void addPathElements(final List<String> selectedPathElementsLocations, final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException { IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry(); IPath projectPath = javaProject.getProject().getLocation(); for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classpathEntry = classPathEntries[i]; String pathElementLocation = null; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathElementLocation = classpathEntry.getPath().toOSString(); break; case IClasspathEntry.CPE_CONTAINER: /* No need for the default jre */ if (classpathEntry.equals(jreEntry)) { break; } /* Resolve container into class path entries */ IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(), javaProject); addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(), javaProject); break; case IClasspathEntry.CPE_VARIABLE: pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString(); break; case IClasspathEntry.CPE_SOURCE: /* * If source has no specific output, use the project default * one */ IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation == null) { outputLocation = javaProject.getOutputLocation(); } pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString(); break; default: break; } if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) { selectedPathElementsLocations.add(pathElementLocation); } } }
From source file:com.liferay.ide.project.core.util.ProjectUtil.java
License:Open Source License
private static void fixExtProjectClasspathEntries(IProject project) { try {//w w w .j ava 2s . c o m boolean fixedAttr = false; IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { IClasspathEntry newEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>(); IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (!CoreUtil.isNullOrEmpty(attrs)) { for (IClasspathAttribute attr : attrs) { IClasspathAttribute newAttr = null; if ("owner.project.facets".equals(attr.getName()) && //$NON-NLS-1$ "liferay.plugin".equals(attr.getValue())) //$NON-NLS-1$ { newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext"); //$NON-NLS-1$ fixedAttr = true; } else { newAttr = attr; } newAttrs.add(newAttr); } newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttrs.toArray(new IClasspathAttribute[0])); } } if (newEntry == null) { newEntry = entry; } newEntries.add(newEntry); } if (fixedAttr) { IProgressMonitor monitor = new NullProgressMonitor(); javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor); try { javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (Exception e) { ProjectCore.logError(e); } } fixExtProjectSrcFolderLinks(project); } catch (Exception ex) { ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex); //$NON-NLS-1$ } }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static void traverseWebComponentLocalEntries(WorkbenchComponent comp, IModuleVisitor visitor, IProgressMonitor monitor) throws CoreException { IProject warProject = StructureEdit.getContainingProject(comp); if (warProject == null || !warProject.hasNature(JavaCore.NATURE_ID)) { return;/*from w w w . j av a2 s .co m*/ } IJavaProject project = JavaCore.create(warProject); List res = comp.getResources(); for (Iterator itorRes = res.iterator(); itorRes.hasNext();) { ComponentResource childComp = (ComponentResource) itorRes.next(); IClasspathEntry cpe = getClasspathEntry(project, childComp.getSourcePath()); if (cpe == null) continue; visitor.visitWebResource(childComp.getRuntimePath(), getOSPath(warProject, project, cpe.getOutputLocation())); } // Include tagged classpath entries Map classpathDeps = getComponentClasspathDependencies(project, true); for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext();) { IClasspathEntry entry = (IClasspathEntry) iterator.next(); IClasspathAttribute attrib = (IClasspathAttribute) classpathDeps.get(entry); boolean isClassFolder = isClassFolderEntry(entry); String rtFolder = attrib.getValue(); if (rtFolder == null) { if (isClassFolder) { rtFolder = "/WEB-INF/classes"; //$NON-NLS-1$ } else { rtFolder = "/WEB-INF/lib"; //$NON-NLS-1$ } } IPath entryPath = entry.getPath(); IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (entryRes != null) { entryPath = entryRes.getLocation(); } // TODO Determine if different handling is needed for some use cases if (isClassFolder) { visitor.visitWebResource(new Path(rtFolder), getOSPath(warProject, project, entry.getPath())); } else { visitor.visitArchiveComponent(new Path(rtFolder), entryPath); } } }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static void traverseDependentEntries(IModuleVisitor visitor, IPath runtimeFolder, WorkbenchComponent component, IProgressMonitor monitor) throws CoreException { IProject dependentProject = StructureEdit.getContainingProject(component); if (!dependentProject.hasNature(JavaCore.NATURE_ID)) return;//ww w . ja v a2s . co m IJavaProject project = JavaCore.create(dependentProject); visitor.visitDependentJavaProject(project); String name = component.getName(); // assume it is the same as URI // go thru all entries List res = component.getResources(); for (Iterator itorRes = res.iterator(); itorRes.hasNext();) { ComponentResource childComp = (ComponentResource) itorRes.next(); IPath rtPath = childComp.getRuntimePath(); IPath srcPath = childComp.getSourcePath(); IClasspathEntry cpe = getClasspathEntry(project, srcPath); if (cpe != null) { visitor.visitDependentComponent(runtimeFolder.append(rtPath).append(name + ".jar"), //$NON-NLS-1$ getOSPath(dependentProject, project, cpe.getOutputLocation())); } // Handle META-INF/resources String path = rtPath.toString(); IFolder resFolder = null; String targetPath = StringPool.EMPTY; if ("/".equals(path)) { //$NON-NLS-1$ resFolder = dependentProject.getFolder(srcPath.append("META-INF/resources")); //$NON-NLS-1$ } else if ("/META-INF".equals(path)) { //$NON-NLS-1$ resFolder = dependentProject.getFolder(srcPath.append("resources")); //$NON-NLS-1$ } else if ("/META-INF/resources".equals(path)) { //$NON-NLS-1$ resFolder = dependentProject.getFolder(srcPath); } else if (path.startsWith("/META-INF/resources/")) { //$NON-NLS-1$ resFolder = dependentProject.getFolder(srcPath); targetPath = path.substring("/META-INF/resources".length()); //$NON-NLS-1$ } if (resFolder != null && resFolder.exists()) { visitor.visitDependentContentResource(new Path(targetPath), resFolder.getLocation()); } } // Include tagged classpath entries Map classpathDeps = getComponentClasspathDependencies(project, false); for (Iterator iterator = classpathDeps.keySet().iterator(); iterator.hasNext();) { IClasspathEntry entry = (IClasspathEntry) iterator.next(); boolean isClassFolder = isClassFolderEntry(entry); String rtFolder = null; if (isClassFolder) { rtFolder = "/"; //$NON-NLS-1$ } else { rtFolder = "/WEB-INF/lib"; //$NON-NLS-1$ } IPath entryPath = entry.getPath(); IResource entryRes = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (entryRes != null) { entryPath = entryRes.getLocation(); } // TODO Determine if different handling is needed for some use cases if (isClassFolder) { visitor.visitDependentComponent(runtimeFolder.append(rtFolder).append(name + ".jar"), //$NON-NLS-1$ getOSPath(dependentProject, project, entry.getPath())); } else { visitor.visitArchiveComponent(new Path(rtFolder), entryPath); } } }