List of usage examples for org.eclipse.jdt.core IClasspathEntry getSourceAttachmentRootPath
IPath getSourceAttachmentRootPath();
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
@Override public IPath getSourceAttachmentRootPath() throws JavaModelException { if (getKind() != K_BINARY) return null; // // 1) look source attachment property (set iff attachSource(...) was called // IPath path = getPath(); // String serverPathString= Util.getSourceAttachmentProperty(path); // if (serverPathString != null) { // int index = serverPathString.lastIndexOf(ATTACHMENT_PROPERTY_DELIMITER); // if (index == -1) return null; // String serverRootPathString= IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH; // if (index != serverPathString.length() - 1) { // serverRootPathString= serverPathString.substring(index + 1); // } // return new Path(serverRootPathString); // }/*from w w w . j a v a 2s .c om*/ // 2) look at classpath entry IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(path); IPath sourceAttachmentRootPath; if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) return sourceAttachmentRootPath; // 3) look for a recomendation entry = findSourceAttachmentRecommendation(); if (entry != null && (sourceAttachmentRootPath = entry.getSourceAttachmentRootPath()) != null) return sourceAttachmentRootPath; return null; }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathEntryHelper.java
License:Open Source License
private void setClasspathEntry(IClasspathEntry entry) { this.kind = entry.getEntryKind(); this.path = entry.getPath(); this.exported = entry.isExported(); this.outputLocation = entry.getOutputLocation(); this.accessRules = new ArrayList<>(); for (IAccessRule rule : entry.getAccessRules()) { this.accessRules.add(rule); }//from w w w . ja va 2s . c o m this.attributes = new HashMap<>(); for (IClasspathAttribute attribute : entry.getExtraAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } this.sourcePath = entry.getSourceAttachmentPath(); this.sourceRootPath = entry.getSourceAttachmentRootPath(); setInclusionPatterns(entry.getInclusionPatterns()); setExclusionPatterns(entry.getExclusionPatterns()); this.combineAccessRules = entry.combineAccessRules(); String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE); String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE); String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE); String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE); String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE); if (groupId != null && artifactId != null && version != null) { this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier); } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) { if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) return entry; IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession); if (resolvedPath == null) return null; // By passing a null reference path, we keep it relative to workspace root. resolvedPath = ClasspathEntry.resolveDotDot(null, resolvedPath); Object target = JavaModel.getTarget(resolvedPath, false); if (target == null) return null; // inside the workspace if (target instanceof IResource) { IResource resolvedResource = (IResource) target; switch (resolvedResource.getType()) { case IResource.PROJECT: // internal project return JavaCore.newProjectEntry(resolvedPath, entry.getAccessRules(), entry.combineAccessRules(), entry.getExtraAttributes(), entry.isExported()); case IResource.FILE: // internal binary archive return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); case IResource.FOLDER: // internal binary folder return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); }/* www. j a v a2s . c o m*/ } if (target instanceof File) { File externalFile = JavaModel.getFile(target); if (externalFile != null) { // external binary archive return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); } else { // non-existing file if (resolvedPath.isAbsolute()) { return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); } } } return null; }
From source file:org.eclipse.jst.common.jdt.internal.classpath.FlexibleProjectContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(final IPath containerPath, final IJavaProject project, final IClasspathContainer sg) throws CoreException { final String key = FlexibleProjectContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());//from w ww . j a va2 s .c om final IClasspathEntry[] entries = sg.getClasspathEntries(); decorations.clearAllDecorations(key); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); decorations.setDecorations(key, eid, dec); } } decorations.save(); final IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project); ((FlexibleProjectContainer) container).refresh(); }
From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java
License:Open Source License
private static IClasspathEntry setOwners(final IClasspathEntry cpe, final String owners) { final List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>(); for (IClasspathAttribute attr : cpe.getExtraAttributes()) { if (!attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) { attrs.add(attr);/*from w ww . j av a 2s . co m*/ } } if (owners != null) { attrs.add(JavaCore.newClasspathAttribute(OWNER_PROJECT_FACETS_ATTR, owners)); } return new ClasspathEntry(cpe.getContentKind(), cpe.getEntryKind(), cpe.getPath(), cpe.getInclusionPatterns(), cpe.getExclusionPatterns(), cpe.getSourceAttachmentPath(), cpe.getSourceAttachmentRootPath(), cpe.getOutputLocation(), cpe.isExported(), cpe.getAccessRules(), cpe.combineAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()])); }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;/*w w w . ja v a 2 s . c o m*/ IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }
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 2s. c om 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.common.classpath.J2EEComponentClasspathInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(final IPath containerPath, final IJavaProject javaProject, final IClasspathContainer sg) throws CoreException { final String key = containerPath.toString(); final IClasspathEntry[] entries = sg.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); decorations.setDecorations(key, eid, dec); }/* ww w. j a va2 s . co m*/ } decorations.save(); final IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject); ((J2EEComponentClasspathContainer) container).refresh(true); }
From source file:org.eclipse.jst.j2ee.internal.common.operations.UpdateJavaBuildPathOperation.java
License:Open Source License
protected void ensureClasspathEntryIsExported(List cp, IClasspathEntry entry) { if (entry.isExported()) return;/*from www . j av a2 s .c o m*/ int index = getIndex(cp, entry); IClasspathEntry newEntry = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), true); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), true); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); } cp.set(index, newEntry); }
From source file:org.eclipse.jst.j2ee.internal.web.operations.WebPropertiesUtil.java
License:Open Source License
/** * Update the classpath entries and Server Root Name for this web project only. * //from w ww. j ava2 s . c om * @param project * @param webContentName * @return */ public static void updateWebContentNamePropertiesOnly(IProject project, String webContentName, IProgressMonitor progressMonitor) throws CoreException { IPath newPath = new Path(webContentName); if (getModuleServerRoot(project).equals(newPath)) return; if (!getModuleServerRoot(project).equals(webContentName)) { // if (webModuleArtifact.isJ2EE) { // Update the library references IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length]; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry library = classpath[i]; IPath libpath = library.getPath(); IPath modServerRootPath = getModuleServerRoot(project).getFullPath(); if (modServerRootPath.isPrefixOf(libpath)) { IPath prunedPath = libpath.removeFirstSegments(modServerRootPath.segmentCount()); IPath relWebContentPath = new Path(webContentName + "/" + prunedPath.toString()); //$NON-NLS-1$ IResource absWebContentPath = project.getFile(relWebContentPath); IPath srcAttachmentPath = library.getSourceAttachmentPath(); if (null != srcAttachmentPath) { prunedPath = srcAttachmentPath.removeFirstSegments(modServerRootPath.segmentCount()); } IResource absWebContentSrcAttachmentPath = project.getFile(relWebContentPath); newClasspath[i] = JavaCore.newLibraryEntry(absWebContentPath.getFullPath(), absWebContentSrcAttachmentPath.getFullPath(), library.getSourceAttachmentRootPath(), library.isExported()); } else { newClasspath[i] = classpath[i]; } } else { newClasspath[i] = classpath[i]; } // } // Set the java output folder IFolder outputFolder = project.getFolder(getModuleServerRoot(project).getFullPath()); javaProject.setRawClasspath(newClasspath, outputFolder.getFullPath(), new SubProgressMonitor(progressMonitor, 1)); } // update websettings // TODO add to WebArtifactEdit // webNature.setModuleServerRootName(webContentName); } }