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.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java
License:Open Source License
/** * Updates the specified Java project so that only the specified classpath entries have * the WTP component dependency attribute. * @param javaProject Target Java project. * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry * to the IClasspathAttribute for the WTP classpath component dependency. * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute. * @throws CoreException Thrown if an error is encountered. *//*from w w w . j a v a 2 s.c o m*/ private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib, final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) { return; } final List updatedClasspath = new ArrayList(); final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean needToUpdateClasspath = false; IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute(); if (!modifyComponentDep) { attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); } for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry entry = rawClasspath[i]; final int kind = entry.getEntryKind(); boolean hasAttribute = ClasspathDependencyUtil .checkForComponentDependencyAttribute(entry, modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY, isLegacyJ2EE) != null; boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry); boolean updateAttributes = false; IClasspathAttribute[] updatedAttributes = null; if (shouldHaveAttribute) { if (!hasAttribute) { // should have the attribute and currently missing it attrib = (IClasspathAttribute) entriesWithAttrib.get(entry); updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true); needToUpdateClasspath = true; updateAttributes = true; } } else if (hasAttribute) { // should not have the attribute and currently has it updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false); needToUpdateClasspath = true; updateAttributes = true; } if (updateAttributes) { switch (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes); break; } } updatedClasspath.add(entry); } if (needToUpdateClasspath) { final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath .toArray(new IClasspathEntry[updatedClasspath.size()]); javaProject.setRawClasspath(updatedCPArray, null); } }
From source file:org.eclipse.jst.j2ee.internal.J2EEComponentProjectMigrator.java
License:Open Source License
private void replaceDeployablesOutputIfNecessary(IProject proj) { IJavaProject jproj = JemProjectUtilities.getJavaProject(proj); final IClasspathEntry[] current; boolean deployablesFound = false; try {/*from w ww . j av a 2 s.c o m*/ current = jproj.getRawClasspath(); List updatedList = new ArrayList(); IPath sourcePath = null; for (int i = 0; i < current.length; i++) { IClasspathEntry entry = current[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) && (entry.getOutputLocation() != null && entry.getOutputLocation().toString().indexOf(OLD_DEPLOYABLES_PATH) != -1)) { sourcePath = entry.getPath(); updatedList.add(JavaCore.newSourceEntry(sourcePath)); deployablesFound = true; } else updatedList.add(entry); } if (deployablesFound) { IClasspathEntry[] updated = (IClasspathEntry[]) updatedList .toArray(new IClasspathEntry[updatedList.size()]); jproj.setRawClasspath(updated, null); jproj.save(null, true); } } catch (JavaModelException e) { J2EEUIPlugin.logError(e); } }
From source file:org.eclipse.jst.server.jetty.core.internal.wst.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 . ja v a 2s . 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"; } else { rtFolder = "/WEB-INF/lib"; } } 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:org.eclipse.jst.server.jetty.core.internal.wst.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;// w ww .j a v a2s . c om IJavaProject project = JavaCore.create(dependentProject); 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"), getOSPath(dependentProject, project, cpe.getOutputLocation())); } // Handle META-INF/resources String path = rtPath.toString(); IFolder resFolder = null; String targetPath = ""; if ("/".equals(path)) { resFolder = dependentProject.getFolder(srcPath.append("META-INF/resources")); } else if ("/META-INF".equals(path)) { resFolder = dependentProject.getFolder(srcPath.append("resources")); } else if ("/META-INF/resources".equals(path)) { resFolder = dependentProject.getFolder(srcPath); } else if (path.startsWith("/META-INF/resources/")) { resFolder = dependentProject.getFolder(srcPath); targetPath = path.substring("/META-INF/resources".length()); } 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 = "/"; } else { rtFolder = "/WEB-INF/lib"; } 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"), getOSPath(dependentProject, project, entry.getPath())); } else { visitor.visitArchiveComponent(new Path(rtFolder), entryPath); } } }
From source file:org.eclipse.jst.server.tomcat.core.internal.wst.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;//from www . j a v a2s. c om 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"), getOSPath(dependentProject, project, cpe.getOutputLocation())); } // Handle META-INF/resources String path = rtPath.toString(); IFolder resFolder = null; String targetPath = ""; if ("/".equals(path)) { resFolder = dependentProject.getFolder(srcPath.append("META-INF/resources")); } else if ("/META-INF".equals(path)) { resFolder = dependentProject.getFolder(srcPath.append("resources")); } else if ("/META-INF/resources".equals(path)) { resFolder = dependentProject.getFolder(srcPath); } else if (path.startsWith("/META-INF/resources/")) { resFolder = dependentProject.getFolder(srcPath); targetPath = path.substring("/META-INF/resources".length()); } 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 = "/"; } else { rtFolder = "/WEB-INF/lib"; } 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"), getOSPath(dependentProject, project, entry.getPath())); } else { visitor.visitArchiveComponent(new Path(rtFolder), entryPath); } } }
From source file:org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor.java
License:Open Source License
private void setClasspathEntry(IClasspathEntry entry) { this.entryKind = entry.getEntryKind(); this.path = entry.getPath(); this.exported = entry.isExported(); this.outputLocation = entry.getOutputLocation(); this.accessRules = new ArrayList<IAccessRule>(); for (IAccessRule rule : entry.getAccessRules()) { this.accessRules.add(rule); }/* www . j av a 2 s . com*/ this.attributes = new LinkedHashMap<String, String>(); for (IClasspathAttribute attribute : entry.getExtraAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } this.sourceAttachmentPath = entry.getSourceAttachmentPath(); this.sourceAttachmentRootPath = entry.getSourceAttachmentRootPath(); setInclusionPatterns(entry.getInclusionPatterns()); setExclusionPatterns(entry.getExclusionPatterns()); this.combineAccessRules = entry.combineAccessRules(); }
From source file:org.eclipse.m2e.wtp.WTPProjectsUtil.java
License:Open Source License
public static void removeTestFolderLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor, String folder) throws CoreException { IVirtualComponent component = ComponentCore.createComponent(project); if (component == null) { return;//from w ww .j a va2 s . c om } IVirtualFolder jsrc = component.getRootFolder().getFolder(folder); for (IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } //MECLIPSEWTP-217 : exclude other test source folders, added by build-helper for instance if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } IPath testOutputDirPath = MavenProjectUtils.getProjectRelativePath(project, mavenProject.getBuild().getTestOutputDirectory()); if (testOutputDirPath == null) { return; } IPath testPath = project.getFullPath().append(testOutputDirPath); IClasspathEntry[] cpes = javaProject.getRawClasspath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry cpe : cpes) { if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (testPath.equals(outputLocation)) { IPath sourcePath = root.getFolder(cpe.getPath()).getProjectRelativePath(); if (sourcePath != null) { jsrc.removeLink(sourcePath, 0, monitor); } } } } } }
From source file:org.eclipse.ocl.examples.editor.ui.builder.CommonBuilder.java
License:Open Source License
protected IPath getWorkspaceRelativeOutputFilePath(final IFile inputFile) { IPath workspaceRelativeInputPath = inputFile.getFullPath(); IPath workspaceRelativeOutputPath = workspaceRelativeInputPath; IClasspathEntry[] resolvedClasspath = getClasspathEntries(inputFile.getProject()); IClasspathEntry classpathEntry = resolvedClasspath != null ? getClasspathEntry(inputFile, resolvedClasspath) : null;// w w w. j a va 2s .c o m if (classpathEntry != null) { IPath sourcePath = classpathEntry.getPath(); IPath outputPath = classpathEntry.getOutputLocation(); workspaceRelativeOutputPath = outputPath != null ? outputPath.append(workspaceRelativeInputPath.removeFirstSegments(sourcePath.segmentCount())) : workspaceRelativeInputPath; } if (hasTextExtension(inputFile)) workspaceRelativeOutputPath = workspaceRelativeOutputPath.removeFileExtension(); return workspaceRelativeOutputPath.addFileExtension(creationFactory.getXMLExtension()); }
From source file:org.eclipse.ocl.examples.editor.ui.builder.CommonBuilder.java
License:Open Source License
/** * @return true iff this resource identifies an output folder *///from w w w. j a v a 2 s . c o m @Override protected boolean isOutputFolder(IResource resource) { IClasspathEntry[] resolvedClasspath = getClasspathEntries(resource.getProject()); if (resolvedClasspath == null) return false; // FIXME ??? IPath workspaceRelativePath = resource.getFullPath(); for (IClasspathEntry resolvedClasspathEntry : resolvedClasspath) { if (resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = resolvedClasspathEntry.getOutputLocation(); if ((outputPath != null) && outputPath.isPrefixOf(workspaceRelativePath)) return true; } } return false; }
From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java
License:Open Source License
/** * Returns the complete listing of required projects from the classpath of * the backing project/*from www . j a va 2 s. co m*/ * * @param includeBinaryPrerequisites * @return the list of projects required * @throws CoreException */ IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); if (this.currentproject == null || workspaceRoot == null) { return new IProject[0]; } ArrayList<IProject> projects = new ArrayList<IProject>(); try { IJavaProject javaProject = JavaCore.create(this.currentproject); HashSet<IPath> blocations = new HashSet<IPath>(); blocations.add(javaProject.getOutputLocation()); this.output_locs.put(this.currentproject, blocations); HashSet<IPath> slocations = new HashSet<IPath>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].isArchive()) { continue; } slocations.add(roots[i].getPath()); } this.src_locs.put(this.currentproject, slocations); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { p = workspaceRoot.getProject(path.lastSegment()); // missing // projects // are // considered // too if (isOptional(entry) && !p.hasNature(ApiPlugin.NATURE_ID)) {// except // if // entry // is // optional p = null; } break; } case IClasspathEntry.CPE_LIBRARY: { if (includebinaries && path.segmentCount() > 1) { // some binary resources on the class path can come // from projects that are not included in the // project references IResource resource = workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) { p = (IProject) resource; } } break; } case IClasspathEntry.CPE_SOURCE: { IPath entrypath = entry.getOutputLocation(); if (entrypath != null) { blocations.add(entrypath); } break; } default: { break; } } if (p != null && !projects.contains(p)) { projects.add(p); // try to derive all of the output locations for each of the // projects javaProject = JavaCore.create(p); HashSet<IPath> bins = new HashSet<IPath>(); HashSet<IPath> srcs = new HashSet<IPath>(); if (javaProject.exists()) { bins.add(javaProject.getOutputLocation()); IClasspathEntry[] source = javaProject.getRawClasspath(); IPath entrypath = null; for (int j = 0; j < source.length; j++) { if (source[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcs.add(source[j].getPath()); entrypath = source[j].getOutputLocation(); if (entrypath != null) { bins.add(entrypath); } } } this.output_locs.put(p, bins); this.src_locs.put(p, srcs); } } } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }