List of usage examples for org.eclipse.jdt.core IClasspathEntry getAccessRules
IAccessRule[] getAccessRules();
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java
License:Open Source License
public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement, IJavaProject project) {//from ww w .ja va 2 s.c o m IPath path = curr.getPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // get the resource IResource res = null; boolean isMissing = false; IPath linkTarget = null; switch (curr.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: try { isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null); } catch (JavaModelException e) { isMissing = true; } break; case IClasspathEntry.CPE_VARIABLE: IPath resolvedPath = JavaCore.getResolvedVariablePath(path); isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists(); break; case IClasspathEntry.CPE_LIBRARY: res = root.findMember(path); if (res == null) { if (!ArchiveFileFilter.isArchivePath(path, true)) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK() && root.getProject(path.segment(0)).exists()) { res = root.getFolder(path); } } IPath rawPath = path; if (project != null) { IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr); if (roots.length == 1) rawPath = roots[0].getPath(); } isMissing = !rawPath.toFile().exists(); // look for external JARs and folders } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_SOURCE: path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { res = root.getFolder(path); } isMissing = true; } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_PROJECT: res = root.findMember(path); isMissing = (res == null); break; } CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res, linkTarget); elem.setExported(curr.isExported()); elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath()); elem.setAttribute(OUTPUT, curr.getOutputLocation()); elem.setAttribute(EXCLUSION, curr.getExclusionPatterns()); elem.setAttribute(INCLUSION, curr.getInclusionPatterns()); elem.setAttribute(ACCESSRULES, curr.getAccessRules()); elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules())); IClasspathAttribute[] extraAttributes = curr.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName()); if (attribElem == null) { elem.createAttributeElement(attrib.getName(), attrib.getValue(), false); } else { attribElem.setValue(attrib.getValue()); } } elem.setIsMissing(isMissing); return elem; }
From source file:com.android.ide.eclipse.adt.internal.project.LibraryClasspathContainerInitializer.java
License:Open Source License
private static List<IClasspathEntry> convertJarsToClasspathEntries(final IProject iProject, Set<File> jarFiles) { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(jarFiles.size()); // and process the jar files list, but first sanitize it to remove dups. JarListSanitizer sanitizer = new JarListSanitizer( iProject.getFolder(SdkConstants.FD_OUTPUT).getLocation().toFile(), new AndroidPrintStream(iProject, null /*prefix*/, AdtPlugin.getOutStream())); String errorMessage = null;//from w w w .j a v a 2s. com try { List<File> sanitizedList = sanitizer.sanitize(jarFiles); for (File jarFile : sanitizedList) { if (jarFile instanceof CPEFile) { CPEFile cpeFile = (CPEFile) jarFile; IClasspathEntry e = cpeFile.getClasspathEntry(); entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), e.getAccessRules(), e.getExtraAttributes(), true /*isExported*/)); } else { String jarPath = jarFile.getAbsolutePath(); IPath sourceAttachmentPath = null; IClasspathAttribute javaDocAttribute = null; File jarProperties = new File(jarPath + DOT_PROPERTIES); if (jarProperties.isFile()) { Properties p = new Properties(); InputStream is = null; try { p.load(is = new FileInputStream(jarProperties)); String value = p.getProperty(ATTR_SRC); if (value != null) { File srcPath = getFile(jarFile, value); if (srcPath.exists()) { sourceAttachmentPath = new Path(srcPath.getAbsolutePath()); } } value = p.getProperty(ATTR_DOC); if (value != null) { File docPath = getFile(jarFile, value); if (docPath.exists()) { try { javaDocAttribute = JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath.toURI().toURL().toString()); } catch (MalformedURLException e) { AdtPlugin.log(e, "Failed to process 'doc' attribute for %s", jarProperties.getAbsolutePath()); } } } } catch (FileNotFoundException e) { // shouldn't happen since we check upfront } catch (IOException e) { AdtPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath()); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // ignore } } } } if (javaDocAttribute != null) { entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath, null /*sourceAttachmentRootPath*/, new IAccessRule[0], new IClasspathAttribute[] { javaDocAttribute }, true /*isExported*/)); } else { entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath, null /*sourceAttachmentRootPath*/, true /*isExported*/)); } } } } catch (DifferentLibException e) { errorMessage = e.getMessage(); AdtPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails()); } catch (Sha1Exception e) { errorMessage = e.getMessage(); } processError(iProject, errorMessage, AdtConstants.MARKER_DEPENDENCY, true /*outputToConsole*/); return entries; }
From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java
License:Open Source License
/** * Fix the project classpath entries. The method ensures that: * <ul>/*w w w . ja va2s. c o m*/ * <li>The project does not reference any old android.zip/android.jar archive.</li> * <li>The project does not use its output folder as a sourc folder.</li> * <li>The project does not reference a desktop JRE</li> * <li>The project references the AndroidClasspathContainer. * </ul> * @param javaProject The project to fix. * @throws JavaModelException */ public static void fixProjectClasspathEntries(IJavaProject javaProject) throws JavaModelException { // get the project classpath IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] oldEntries = entries; boolean forceRewriteOfCPE = false; // check if the JRE is set as library int jreIndex = ProjectHelper.findClasspathEntryByPath(entries, JavaRuntime.JRE_CONTAINER, IClasspathEntry.CPE_CONTAINER); if (jreIndex != -1) { // the project has a JRE included, we remove it entries = ProjectHelper.removeEntryFromClasspath(entries, jreIndex); } // get the output folder IPath outputFolder = javaProject.getOutputLocation(); boolean foundFrameworkContainer = false; IClasspathEntry foundLibrariesContainer = null; IClasspathEntry foundDependenciesContainer = null; for (int i = 0; i < entries.length;) { // get the entry and kind IClasspathEntry entry = entries[i]; int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path.equals(outputFolder)) { entries = ProjectHelper.removeEntryFromClasspath(entries, i); // continue, to skip the i++; continue; } } else if (kind == IClasspathEntry.CPE_CONTAINER) { String path = entry.getPath().toString(); if (AdtConstants.CONTAINER_FRAMEWORK.equals(path)) { foundFrameworkContainer = true; } else if (AdtConstants.CONTAINER_PRIVATE_LIBRARIES.equals(path)) { foundLibrariesContainer = entry; } else if (AdtConstants.CONTAINER_DEPENDENCIES.equals(path)) { foundDependenciesContainer = entry; } } i++; } // look to see if we have the m2eclipse nature boolean m2eNature = false; try { m2eNature = javaProject.getProject().hasNature("org.eclipse.m2e.core.maven2Nature"); } catch (CoreException e) { AdtPlugin.log(e, "Failed to query project %s for m2e nature", javaProject.getProject().getName()); } // if the framework container is not there, we add it if (!foundFrameworkContainer) { // add the android container to the array entries = ProjectHelper.addEntryToClasspath(entries, JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_FRAMEWORK))); } // same thing for the library container if (foundLibrariesContainer == null) { // add the exported libraries android container to the array entries = ProjectHelper.addEntryToClasspath(entries, JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_PRIVATE_LIBRARIES), true)); } else if (!m2eNature && !foundLibrariesContainer.isExported()) { // the container is present but it's not exported and since there's no m2e nature // we do want it to be exported. // keep all the other parameters the same. entries = ProjectHelper.replaceEntryInClasspath(entries, JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_PRIVATE_LIBRARIES), foundLibrariesContainer.getAccessRules(), foundLibrariesContainer.getExtraAttributes(), true)); forceRewriteOfCPE = true; } // same thing for the dependencies container if (foundDependenciesContainer == null) { // add the android dependencies container to the array entries = ProjectHelper.addEntryToClasspath(entries, JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_DEPENDENCIES), true)); } else if (!m2eNature && !foundDependenciesContainer.isExported()) { // the container is present but it's not exported and since there's no m2e nature // we do want it to be exported. // keep all the other parameters the same. entries = ProjectHelper.replaceEntryInClasspath(entries, JavaCore.newContainerEntry(new Path(AdtConstants.CONTAINER_DEPENDENCIES), foundDependenciesContainer.getAccessRules(), foundDependenciesContainer.getExtraAttributes(), true)); forceRewriteOfCPE = true; } // set the new list of entries to the project if (entries != oldEntries || forceRewriteOfCPE) { javaProject.setRawClasspath(entries, new NullProgressMonitor()); } // If needed, check and fix compiler compliance and source compatibility ProjectHelper.checkAndFixCompilerCompliance(javaProject); }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.LibraryClasspathContainerSerializerTest.java
License:Apache License
private void compare(LibraryClasspathContainer container, LibraryClasspathContainer otherContainer) { assertEquals(container.getPath(), otherContainer.getPath()); assertEquals(container.getKind(), otherContainer.getKind()); assertEquals(container.getDescription(), otherContainer.getDescription()); for (int i = 0; i < container.getClasspathEntries().length; i++) { IClasspathEntry classpathEntry = container.getClasspathEntries()[i]; IClasspathEntry otherClasspathEntry = otherContainer.getClasspathEntries()[i]; assertEquals(classpathEntry.getPath(), otherClasspathEntry.getPath()); assertEquals(classpathEntry.getEntryKind(), otherClasspathEntry.getEntryKind()); assertEquals(classpathEntry.getSourceAttachmentPath(), otherClasspathEntry.getSourceAttachmentPath()); assertEquals(classpathEntry.isExported(), otherClasspathEntry.isExported()); for (int j = 0; j < classpathEntry.getAccessRules().length; j++) { IAccessRule accessRule = classpathEntry.getAccessRules()[j]; IAccessRule otherAccessRule = otherClasspathEntry.getAccessRules()[j]; assertEquals(accessRule.getKind(), otherAccessRule.getKind()); assertEquals(accessRule.getPattern(), otherAccessRule.getPattern()); }// w w w . j ava 2 s .co m for (int k = 0; k < classpathEntry.getExtraAttributes().length; k++) { IClasspathAttribute classpathAttribute = classpathEntry.getExtraAttributes()[k]; IClasspathAttribute otherClasspathAttribute = otherClasspathEntry.getExtraAttributes()[k]; assertEquals(classpathAttribute.getName(), otherClasspathAttribute.getName()); assertEquals(classpathAttribute.getValue(), otherClasspathAttribute.getValue()); } } }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.SerializableClasspathEntry.java
License:Apache License
public SerializableClasspathEntry(IClasspathEntry entry, IPath baseDirectory) { setAttributes(entry.getExtraAttributes()); setAccessRules(entry.getAccessRules()); setSourcePath(entry.getSourceAttachmentPath()); setPath(PathUtil.relativizePath(entry.getPath(), baseDirectory).toString()); }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.M2RepositoryService.java
License:Apache License
@Override public IClasspathEntry rebuildClasspathEntry(IClasspathEntry classpathEntry) throws LibraryRepositoryServiceException { MavenCoordinates mavenCoordinates = transformer.createMavenCoordinates(classpathEntry.getExtraAttributes()); Artifact artifact = resolveArtifact(mavenCoordinates); return JavaCore.newLibraryEntry(new Path(artifact.getFile().getAbsolutePath()), classpathEntry.getSourceAttachmentPath(), null /* sourceAttachmentRootPath */, classpathEntry.getAccessRules(), classpathEntry.getExtraAttributes(), true /* isExported */); }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerInitializerTest.java
License:Open Source License
/** * TODO: We need to revisit this test. Since we don't allow container updates * right now, it is not clear that the test is sufficiently strong. *//*ww w . jav a 2 s. c o m*/ public void testRequestClasspathContainerUpdate() throws CoreException { IJavaProject testProject = getTestProject(); IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(defaultRuntimePath, testProject); final List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry classpathEntry : classpathEntries) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathAttribute[] extraAttributes = classpathEntry.getExtraAttributes(); List<IClasspathAttribute> newAttributes = new ArrayList<IClasspathAttribute>(); for (IClasspathAttribute extraAttribute : extraAttributes) { String attributeName = extraAttribute.getName(); if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attributeName)) { String attributeValue = extraAttribute.getValue() + "modified"; extraAttribute = JavaCore.newClasspathAttribute(attributeName, attributeValue); } newAttributes.add(extraAttribute); } IPath sourceAttachmentPath = new Path("/sourceAttachmentPath"); IPath sourceAttachmentRootPath = new Path("sourceAttachmentRootPath"); classpathEntry = JavaCore.newLibraryEntry(classpathEntry.getPath(), sourceAttachmentPath, sourceAttachmentRootPath, classpathEntry.getAccessRules(), newAttributes.toArray(new IClasspathAttribute[0]), classpathEntry.isExported()); } newClasspathEntries.add(classpathEntry); } // Update the classpath container initializer.requestClasspathContainerUpdate(defaultRuntimePath, testProject, new ClasspathContainerAdapter(classpathContainer) { @Override public IClasspathEntry[] getClasspathEntries() { return newClasspathEntries.toArray(new IClasspathEntry[0]); } }); // Check that the modifications took effect IClasspathContainer updatedContainer = JavaCore.getClasspathContainer(defaultRuntimePath, testProject); for (IClasspathEntry classpathEntry : updatedContainer.getClasspathEntries()) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) { // Ignore all non-library entries continue; } for (IClasspathAttribute attribute : classpathEntry.getExtraAttributes()) { if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attribute.getName())) { String value = attribute.getValue(); assertTrue(value.endsWith("modified")); } } IPath sourceAttachmentPath = classpathEntry.getSourceAttachmentPath(); assertEquals(new Path("/sourceAttachmentPath"), sourceAttachmentPath); IPath sourceAttachmentRootPath = classpathEntry.getSourceAttachmentRootPath(); assertEquals(new Path("sourceAttachmentRootPath"), sourceAttachmentRootPath); } }
From source file:com.liferay.ide.server.tomcat.core.LiferayTomcatRuntimeClasspathProvider.java
License:Open Source License
private IClasspathEntry[] getUpdatedJavadocEntries(IClasspathEntry[] entries, ILiferayTomcatRuntime liferayTomcatRuntime) { List<IClasspathEntry> updatedEntries = new ArrayList<IClasspathEntry>(); String javadocURL = liferayTomcatRuntime.getJavadocURL(); if (javadocURL != null) { for (IClasspathEntry existingEntry : entries) { IPath path = existingEntry.getPath(); IClasspathEntry newEntry = null; for (String javadocJar : JARS) { if (path.lastSegment().equalsIgnoreCase(javadocJar)) { IClasspathAttribute[] extraAttrs = existingEntry.getExtraAttributes(); List<IClasspathAttribute> newExtraAttrs = new ArrayList<IClasspathAttribute>(); IClasspathAttribute javadocAttr = newJavadocAttr(javadocURL); newExtraAttrs.add(javadocAttr); if (!CoreUtil.isNullOrEmpty(extraAttrs)) { for (IClasspathAttribute attr : extraAttrs) { if (!attr.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) { newExtraAttrs.add(attr); }/*from w ww. ja v a2 s .c o m*/ } } newEntry = JavaCore.newLibraryEntry(existingEntry.getPath(), existingEntry.getSourceAttachmentPath(), existingEntry.getSourceAttachmentRootPath(), existingEntry.getAccessRules(), newExtraAttrs.toArray(new IClasspathAttribute[0]), existingEntry.isExported()); break; } } if (newEntry != null) { updatedEntries.add(newEntry); } else { updatedEntries.add(existingEntry); } } } else { Collections.addAll(updatedEntries, entries); } return updatedEntries.toArray(new IClasspathEntry[0]); }
From source file:com.liferay.ide.server.tomcat.core.LiferayTomcatRuntimeClasspathProvider.java
License:Open Source License
private IClasspathEntry[] getUpdatedSourceEntries(IClasspathEntry[] entries, ILiferayTomcatRuntime liferayTomcatRuntime) { List<IClasspathEntry> updatedEntries = new ArrayList<IClasspathEntry>(); IPath sourceLocation = liferayTomcatRuntime.getSourceLocation(); if (sourceLocation != null) { for (IClasspathEntry existingEntry : entries) { IPath path = existingEntry.getPath(); IClasspathEntry newEntry = null; for (String sourceJar : JARS) { if (path.lastSegment().equalsIgnoreCase(sourceJar)) { IPath sourcePath = existingEntry.getSourceAttachmentPath(); if (sourcePath == null) { sourcePath = sourceLocation; }/*from ww w .j a v a2s .co m*/ newEntry = JavaCore.newLibraryEntry(existingEntry.getPath(), sourcePath, existingEntry.getSourceAttachmentRootPath(), existingEntry.getAccessRules(), existingEntry.getExtraAttributes(), existingEntry.isExported()); break; } } if (newEntry != null) { updatedEntries.add(newEntry); } else { updatedEntries.add(existingEntry); } } } else { Collections.addAll(updatedEntries, entries); } return updatedEntries.toArray(new IClasspathEntry[0]); }
From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java
License:Open Source License
/** * Set the source path of given <code>ClasspathEntry</code> to the current build path * @param e The entry to set// ww w. j ava 2 s .co m * @return The entry with the new source path */ public IClasspathEntry setSourceEntry(IClasspathEntry e) { return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), featureProject.getBuildFolder().getFullPath(), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }