List of usage examples for org.eclipse.jdt.core IClasspathEntry getExtraAttributes
IClasspathAttribute[] getExtraAttributes();
From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocLocations.java
License:Open Source License
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ }//ww w . ja v a2s .c o m int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return parseURL(attrib.getValue()); } } return null; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException { String encoding = ResourcesPlugin.getEncoding(); IClasspathEntry entry = root.getRawClasspathEntry(); if (entry != null) { int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) { IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); }/*from w w w . j a va2s. c o m*/ } } } return encoding; }
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 w w w . java 2 s. co 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.AndroidClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { AdtPlugin plugin = AdtPlugin.getDefault(); synchronized (Sdk.getLock()) { boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED; // check if the project has a valid target. IAndroidTarget target = null;/*from www . ja va 2 s. c om*/ if (sdkIsLoaded) { target = Sdk.getCurrent().getTarget(project.getProject()); } if (sdkIsLoaded && target != null) { String[] paths = getTargetPaths(target); IPath android_lib = new Path(paths[CACHE_INDEX_JAR]); IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = entry.getPath(); if (entryPath != null) { if (entryPath.equals(android_lib)) { IPath entrySrcPath = entry.getSourceAttachmentPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (entrySrcPath != null) { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), entrySrcPath.toString()); } else { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), null); } IClasspathAttribute[] extraAttributtes = entry.getExtraAttributes(); if (extraAttributtes.length == 0) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, NULL_API_URL); } for (int j = 0; j < extraAttributtes.length; j++) { IClasspathAttribute extraAttribute = extraAttributtes[j]; String value = extraAttribute.getValue(); if ((value == null || value.trim().length() == 0) && IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { value = NULL_API_URL; } if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, value); } } } } } } rebindClasspathEntries(project.getJavaModel(), containerPath); } } }
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 ww w. ja va 2 s .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>//from w w w.ja v a 2 s .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.android.ide.eclipse.auidt.internal.project.AndroidClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { AdtPlugin plugin = AdtPlugin.getDefault(); synchronized (Sdk.getLock()) { boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED; // check if the project has a valid target. IAndroidTarget target = null;//from ww w .j ava 2s. co m if (sdkIsLoaded) { target = Sdk.getCurrent().getTarget(project.getProject()); } if (sdkIsLoaded && target != null) { String[] paths = getTargetPaths(target); IPath android_lib = new Path(paths[CACHE_INDEX_JAR]); IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = entry.getPath(); if (entryPath != null) { if (entryPath.equals(android_lib)) { IPath entrySrcPath = entry.getSourceAttachmentPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (entrySrcPath != null) { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), entrySrcPath.toString()); } else { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), null); } IClasspathAttribute[] extraAttributtes = entry.getExtraAttributes(); if (extraAttributtes.length == 0) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, NULL_API_URL); } for (int j = 0; j < extraAttributtes.length; j++) { IClasspathAttribute extraAttribute = extraAttributtes[j]; String value = extraAttribute.getValue(); if ((value == null || value.trim().length() == 0) && IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { value = NULL_API_URL; } if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, value); } } } } } } rebindClasspathEntries(project.getJavaModel(), containerPath); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
protected static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: break;//www .j a va 2 s .c om default: throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, value)); } } } return null; }
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 .jav a 2s . com 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()); }