List of usage examples for org.eclipse.jdt.core IClasspathEntry combineAccessRules
boolean combineAccessRules();
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);/* www. j a va2s .c o 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;/*from w w w . j a v a2 s. c om*/ 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 www. j a v a2s. 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.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); }/*w ww. j a va2 s .c o m*/ 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.tests.jdt.internal.MavenClasspathContainerSaveHelperTest.java
License:Open Source License
public void testClasspathContainerSace() throws Exception { IClasspathEntry[] entries = new IClasspathEntry[2]; {// w w w .j a v a 2 s. c o m IAccessRule[] accessRules = new IAccessRule[1]; accessRules[0] = JavaCore.newAccessRule(new Path("aa/**"), IAccessRule.K_ACCESSIBLE); IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("foo", "11"); attributes[1] = JavaCore.newClasspathAttribute("moo", "22"); entries[0] = JavaCore.newProjectEntry(new Path("/foo"), accessRules, true, attributes, false); } { IAccessRule[] accessRules = new IAccessRule[1]; accessRules[0] = JavaCore.newAccessRule(new Path("bb/**"), IAccessRule.K_DISCOURAGED); IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("foo", "aa"); entries[1] = JavaCore.newLibraryEntry(new Path("/foo/moo.jar"), new Path("/foo/moo-sources.jar"), new Path("/foo/moo-javadoc.jar"), accessRules, attributes, false); } ByteArrayOutputStream os = new ByteArrayOutputStream(); helper.writeContainer(new MavenClasspathContainer(new Path(IClasspathManager.CONTAINER_ID), entries), os); os.close(); IClasspathContainer container = helper.readContainer(new ByteArrayInputStream(os.toByteArray())); assertEquals(IClasspathManager.CONTAINER_ID, container.getPath().toString()); IClasspathEntry[] classpathEntries = container.getClasspathEntries(); assertEquals(2, classpathEntries.length); { IClasspathEntry entry = classpathEntries[0]; assertEquals(IClasspathEntry.CPE_PROJECT, entry.getEntryKind()); assertEquals("/foo", entry.getPath().toString()); assertEquals(false, entry.isExported()); assertEquals(true, entry.combineAccessRules()); IAccessRule[] accessRules = entry.getAccessRules(); assertEquals(1, accessRules.length); assertEquals(IAccessRule.K_ACCESSIBLE, accessRules[0].getKind()); assertEquals("aa/**", accessRules[0].getPattern().toString()); IClasspathAttribute[] attributes = entry.getExtraAttributes(); assertEquals(2, attributes.length); assertEquals("foo", attributes[0].getName()); assertEquals("11", attributes[0].getValue()); assertEquals("moo", attributes[1].getName()); assertEquals("22", attributes[1].getValue()); } { IClasspathEntry entry = classpathEntries[1]; assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind()); assertEquals("/foo/moo.jar", entry.getPath().toString()); assertEquals(false, entry.isExported()); IAccessRule[] accessRules = entry.getAccessRules(); assertEquals(1, accessRules.length); assertEquals(IAccessRule.K_DISCOURAGED, accessRules[0].getKind()); assertEquals("bb/**", accessRules[0].getPattern().toString()); IClasspathAttribute[] attributes = entry.getExtraAttributes(); assertEquals(1, attributes.length); assertEquals("foo", attributes[0].getName()); assertEquals("aa", attributes[0].getValue()); } }