List of usage examples for org.eclipse.jdt.core IClasspathEntry getExtraAttributes
IClasspathAttribute[] getExtraAttributes();
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()); }/* ww w . j av a 2s . co 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 www. j ava 2 s. co m*/ 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 Set<Object> getOwners(final IJavaProject project, final IClasspathEntry cpe) throws CoreException { final Set<Object> owners = new HashSet<Object>(); if (cpe != null) { for (IClasspathAttribute attr : cpe.getExtraAttributes()) { if (attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) { owners.addAll(decodeOwnersString(attr.getValue())); break; }/*from ww w . j a v a 2 s . c o m*/ } owners.addAll(getOwnersFromLegacyMetadata(project, cpe)); if (owners.isEmpty()) { owners.add(SYSTEM_OWNER); } } return owners; }
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 w w . j a v a 2s.c om*/ } } 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
private static String getCustomArchiveName(IClasspathEntry entry) { IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); if (extraAttributes != null) { for (IClasspathAttribute cpa : extraAttributes) { if (cpa != null && CLASSPATH_ARCHIVENAME_ATTRIBUTE.equals(cpa.getName())) { return cpa.getValue(); }// w ww. jav a 2 s .co m } } return null; }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathAttribute checkForComponentDependencyAttribute(final IClasspathEntry entry, final DependencyAttributeType attributeType, final boolean isLegacyJ2EE) { if (entry == null) return null; final IClasspathAttribute[] attributes = entry.getExtraAttributes(); for (int i = 0; i < attributes.length; i++) { final IClasspathAttribute attribute = attributes[i]; final String name = attribute.getName(); if (name.equals(CLASSPATH_COMPONENT_DEPENDENCY)) { if (attributeType == DependencyAttributeType.DEPENDENCY_OR_NONDEPENDENCY || attributeType == DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY) { return attribute; }/*from w w w. ja v a2 s. com*/ } else if (name.equals(CLASSPATH_COMPONENT_NON_DEPENDENCY)) { if (attributeType == DependencyAttributeType.DEPENDENCY_OR_NONDEPENDENCY || attributeType == DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY) { return attribute; } } } return null; }
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;/* www.j a v a 2s . 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.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IPath getRuntimePath(final IClasspathEntry entry) { IClasspathAttribute[] attributes = entry.getExtraAttributes(); for (IClasspathAttribute attribute : attributes) { if (attribute.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { return new Path(attribute.getValue()); }//from w w w . j av a 2 s . co m } return null; }
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 va2s . com*/ 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); }/* w w w.ja v a2s.co m*/ } decorations.save(); final IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject); ((J2EEComponentClasspathContainer) container).refresh(true); }