List of usage examples for org.eclipse.jdt.core IClasspathEntry getSourceAttachmentPath
IPath getSourceAttachmentPath();
null
if this classpath entry has no source attachment. From source file:me.gladwell.eclipse.m2e.android.test.DownloadSourcesAndJavadocTest.java
License:Open Source License
public void testSourcesAttachedIfEnabledBeforeRefresh() throws Exception { mavenConfiguration.setDownloadSources(false); IProject project = importAndroidProject(PROJECT_NAME); IJavaProject javaProject = JavaCore.create(project); getClasspathEntry(javaProject, CONTAINER_NONRUNTIME_DEPENDENCIES, "mockito-core-1.9.5.jar"); mavenConfiguration.setDownloadSources(true); IClasspathEntry entry = getClasspathEntry(javaProject, CONTAINER_NONRUNTIME_DEPENDENCIES, "mockito-core-1.9.5.jar"); assertNotNull(entry.getSourceAttachmentPath()); }
From source file:net.rim.ejde.internal.model.ui.VMLibraryBlock.java
License:Open Source License
/** * Open the javadoc location dialog or the source location dialog, and set the result to the selected libraries. *//*from ww w .j a va 2s.c o m*/ private void edit(IStructuredSelection selection, int type) { Object obj = selection.getFirstElement(); LibraryStandin standin = null; if (obj instanceof LibraryStandin) { standin = (LibraryStandin) obj; } else if (obj instanceof SubElement) { SubElement sub = (SubElement) obj; standin = sub.getParent(); } if (standin != null) { LibraryLocation library = standin.toLibraryLocation(); if (type == SubElement.JAVADOC_URL) { URL[] urls = BuildPathDialogAccess.configureJavadocLocation(fLibraryViewer.getControl().getShell(), library.getSystemLibraryPath().toOSString(), library.getJavadocLocation()); if (urls != null) { fLibraryContentProvider.setJavadoc(urls[0], selection); } } else if (type == SubElement.SOURCE_PATH) { IRuntimeClasspathEntry entry = JavaRuntime .newArchiveRuntimeClasspathEntry(library.getSystemLibraryPath()); entry.setSourceAttachmentPath(library.getSystemLibrarySourcePath()); entry.setSourceAttachmentRootPath(library.getPackageRootPath()); IClasspathEntry classpathEntry = BuildPathDialogAccess.configureSourceAttachment( fLibraryViewer.getControl().getShell(), entry.getClasspathEntry()); if (classpathEntry != null) { fLibraryContentProvider.setSourcePath(classpathEntry.getSourceAttachmentPath(), classpathEntry.getSourceAttachmentRootPath(), selection); } } } }
From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java
License:Apache License
private static Collection<IClasspathEntry> newProjectEntry(ISigilProjectModel n, IAccessRule[] rules, IClasspathAttribute[] attributes, boolean export) throws CoreException { ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(JavaCore.newProjectEntry(n.getProject().getFullPath(), rules, false, attributes, export)); for (IClasspathEntry e : n.getJavaModel().getRawClasspath()) { String encoded = n.getJavaModel().encodeClasspathEntry(e); if (n.getBundle().getClasspathEntrys().contains(encoded)) { switch (e.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), rules, attributes, export)); break; case IClasspathEntry.CPE_VARIABLE: IPath path = JavaCore.getResolvedVariablePath(e.getPath()); if (path != null) { IPath spath = e.getSourceAttachmentPath(); if (spath != null) { spath = JavaCore.getResolvedVariablePath(spath); }//from w w w.ja va 2 s. co m entries.add(JavaCore.newLibraryEntry(path, spath, e.getSourceAttachmentRootPath(), rules, attributes, export)); } break; } } } return entries; }
From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyAttachementManager.java
License:Apache License
public void updateAttchements(IJavaProject project, IPath containerPath, IClasspathContainer containerSuggestion) { IvyDEMessage.verbose("Updating attachements on the container " + containerPath); Properties newProps = new Properties(); IClasspathEntry[] newEntries = containerSuggestion.getClasspathEntries(); for (int i = 0; i < newEntries.length; i++) { IClasspathEntry entry = newEntries[i]; if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) { String path = entry.getPath().toPortableString(); if (entry.getSourceAttachmentPath() != null) { newProps.put(path + SRC_SUFFIX, entry.getSourceAttachmentPath().toPortableString()); }/*from w w w .j a v a 2s . c o m*/ if (entry.getSourceAttachmentRootPath() != null) { newProps.put(path + SRCROOT_SUFFIX, entry.getSourceAttachmentRootPath().toPortableString()); } String javadocUrl = getJavadocLocation(entry); if (javadocUrl != null) { newProps.put(path + DOC_SUFFIX, javadocUrl); } } } IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) IvyClasspathContainerHelper .getContainer(containerPath, project); if (ivycp == null) { IvyDEMessage.error("The IvyDE container could not be found. Aborting updating attachements."); // something wrong happened, give up return; } IClasspathEntry[] existingEntries = ivycp.getClasspathEntries(); for (int i = 0; i < existingEntries.length; i++) { IClasspathEntry entry = existingEntries[i]; if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) { String path = entry.getPath().toPortableString(); String value = (String) prop.get(path + SRC_SUFFIX); if (value != null && entry.getSourceAttachmentPath() != null && value.equals(entry.getSourceAttachmentPath().toPortableString())) { newProps.remove(path + SRC_SUFFIX); } value = (String) prop.get(path + SRCROOT_SUFFIX); if (value != null && entry.getSourceAttachmentRootPath() != null && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) { newProps.remove(path + SRCROOT_SUFFIX); } } } // copy the actually new overrided properties prop.putAll(newProps); // now update the ivyde container for real ivycp.updateClasspathEntries(newEntries); // store the global result IvyDEMessage.verbose("Saving attachement properties"); try { FileOutputStream out = new FileOutputStream(containersAttachementFile); try { prop.store(out, ""); } finally { try { out.close(); } catch (IOException e) { // don't care } } } catch (IOException ioe) { IvyPlugin.logWarn("IvyDE attachement properties could not be saved", ioe); } }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a library entry in the classpath * @param entry the classpath entry//www .ja va 2 s.co m * @param root the workspace root * @throws IOException */ private void handleLibrary(IClasspathEntry entry, IWorkspaceRoot root) throws IOException { // 3 types of library entries: internal (this project), internal (another project), and external // (1) Rooted absolute path // (2) Rooted absolute path (but with different project directory) --> Need to copy this to swampbin // (3) Actual absolute path to somewhere else on the filesystem --> Need to copy this to swampbin System.out.println("\n\n\n\n"); System.out.println("Library absolute path: " + entry.getPath().makeAbsolute()); //System.out.println("First segment: " + entry.getPath().segment(0)); IFile file = root.getFile(entry.getPath()); System.out.println("File project: " + file.getProject().getName()); if (file.getProject().equals(this.project.getProject())) { System.out.println("Is inside project"); libs.add(entry); } else { System.out.println("Is outside project"); IFile libFile = root.getFile(entry.getPath()); IProject libProject = libFile.getProject(); String filename = getLibraryFileName(entry.getPath()); IPath destPath; if (libProject.exists()) { if (libProject.isOpen()) { try { System.out.println("Local project"); destPath = copyWorkspacePathIntoBinDir(libFile, filename, SWAMPBIN_PATH); } catch (Exception e) { System.out.println("Local project that failed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Local project that's closed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Not a project - just an absolute path"); destPath = copyAbsolutePathIntoBinDir(entry.getPath().toOSString(), filename, SWAMPBIN_PATH); } hasSwampbinDependencies = true; System.out.println("SWAMPBIN path: " + destPath); IClasspathEntry newEntry = JavaCore.newLibraryEntry(destPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); System.out.println("New entry path: " + newEntry.getPath()); libs.add(newEntry); if (entry.isExported()) { exportedEntries.add(newEntry); } } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project// ww w. j a v a 2s . co m * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }
From source file:org.eclipse.andmore.internal.project.AndroidClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { AndmoreAndroidPlugin plugin = AndmoreAndroidPlugin.getDefault(); synchronized (Sdk.getLock()) { boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED; // check if the project has a valid target. IAndroidTarget target = null;// w w w . j a v a 2s. c o 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:org.eclipse.andmore.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*/, AndmoreAndroidPlugin.getOutStream())); String errorMessage = null;/* w w w.j av 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) { AndmoreAndroidPlugin.log(e, "Failed to process 'doc' attribute for %s", jarProperties.getAbsolutePath()); } } } } catch (FileNotFoundException e) { // shouldn't happen since we check upfront } catch (IOException e) { AndmoreAndroidPlugin.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(); AndmoreAndroidPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails()); } catch (Sha1Exception e) { errorMessage = e.getMessage(); } processError(iProject, errorMessage, AndmoreAndroidConstants.MARKER_DEPENDENCY, true /*outputToConsole*/); return entries; }
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
@Override public IPath getSourceAttachmentPath() 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 < 0) { // // no root path specified // return new Path(serverPathString); // } else { // String serverSourcePathString= serverPathString.substring(0, index); // return new Path(serverSourcePathString); // } // }/*from w w w .j a v a 2 s .co m*/ // 2) look at classpath entry IClasspathEntry entry = ((JavaProject) getParent()).getClasspathEntryFor(path); IPath sourceAttachmentPath; if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) return sourceAttachmentPath; // 3) look for a recommendation entry = findSourceAttachmentRecommendation(); if (entry != null && (sourceAttachmentPath = entry.getSourceAttachmentPath()) != null) { return sourceAttachmentPath; } 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); }/* www .j a va 2 s. 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); } }