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:org.lwjgl.tools.LWJGLClasspathContainerPage.java
License:Open Source License
protected void update() { IStatus status = null;/* w w w. ja v a 2 s . co m*/ IClasspathEntry[] libEntries = BuildPathSupport.getLWJGLLibraryEntries(); IPath containerPath = LWJGLClasspathContainerInitializer.LWJGL_LIBRARY_PATH; containerEntryResult = JavaCore.newContainerEntry(containerPath); if (libEntries == null) { status = new Status(ERROR, Activator.PLUGIN_ID, "No LWJGL library found"); } else if (labelResolvedPath != null && !labelResolvedPath.isDisposed()) { // implies all other labels to be created and not yet disposed if (libEntries != null) { Set<String> setLines = new TreeSet<String>(); IPath path; for (IClasspathEntry entry : libEntries) { path = entry.getPath(); if (path != null) { setLines.add(getPathLabel(path)); } } setLabel(labelResolvedPath, setLines); setLines.clear(); for (IClasspathEntry entry : libEntries) { path = entry.getSourceAttachmentPath(); if (path != null) { setLines.add(getPathLabel(path)); } } setLabel(labelResolvedSourcePath, setLines); setLines.clear(); for (IClasspathEntry entry : libEntries) { if (entry.getExtraAttributes() != null) { for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attr.getName())) { setLines.add(attr.getValue()); break; } if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) { } } } } setLabel(labelResolvedDocPath, setLines); setLines.clear(); for (IClasspathEntry entry : libEntries) { if (entry.getExtraAttributes() != null) { for (IClasspathAttribute attr : entry.getExtraAttributes()) { if (JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY.equals(attr.getName())) { setLines.add(attr.getValue()); } } } } setLabel(labelNativePath, setLines); } else { labelResolvedPath.setText("not found"); labelResolvedSourcePath.setText("not found"); labelResolvedDocPath.setText("not found"); } } if (status != null) updateStatus(status); }
From source file:org.maven.ide.eclipse.scala.ScalaProjectConfigurator.java
License:Open Source License
private static void addDeployableAttribute(IJavaProject javaProject, IClasspathAttribute deployableAttribute, IProgressMonitor monitor) throws JavaModelException, CoreException { if (javaProject == null) return;/*w w w . j a va2 s. c o m*/ ClasspathContainerInitializer scalaInitializer = JavaCore .getClasspathContainerInitializer(SCALA_CONTAINER_PATH); if (scalaInitializer == null) return; IPath scalaContainerPath = Path.fromPortableString(SCALA_CONTAINER_PATH); Boolean updateAble = scalaInitializer.canUpdateClasspathContainer(scalaContainerPath, javaProject); final IClasspathContainer scalaLibrary = JavaCore.getClasspathContainer(scalaContainerPath, javaProject); final IClasspathEntry[] cpEntries = scalaLibrary.getClasspathEntries(); for (int i = 0; i < cpEntries.length; i++) { IClasspathEntry cpe = cpEntries[i]; LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>(); for (IClasspathAttribute attr : cpe.getExtraAttributes()) { //Keep all existing attributes except the non_deployable key if (!attr.getName().equals(NON_DEPLOYABLE_KEY)) { attrs.put(attr.getName(), attr); } } attrs.put(deployableAttribute.getName(), deployableAttribute); IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]); cpEntries[i] = JavaCore.newLibraryEntry(cpe.getPath(), cpe.getSourceAttachmentPath(), cpe.getSourceAttachmentRootPath(), cpe.getAccessRules(), newAttrs, cpe.isExported()); } IClasspathContainer candidateScalaContainer = new IClasspathContainer() { public IPath getPath() { return scalaLibrary.getPath(); } public IClasspathEntry[] getClasspathEntries() { return cpEntries; } public String getDescription() { return scalaLibrary.getDescription(); } public int getKind() { return scalaLibrary.getKind(); } }; if (updateAble) { scalaInitializer.requestClasspathContainerUpdate(scalaContainerPath, javaProject, candidateScalaContainer); } else { IJavaProject[] jPArray = { javaProject }; IClasspathContainer[] cpArray = { candidateScalaContainer }; JavaCore.setClasspathContainer(scalaContainerPath, jPArray, cpArray, null); } }
From source file:org.neuro4j.studio.core.buildpath.Neuro4jContainerWizardPage.java
License:Apache License
protected void doSelectionChanged() { Neuro4jStatus status = new Neuro4jStatus(); IClasspathEntry corelibEntry = null, logicLibEntry = null; IPath containerPath = null;//from ww w .j a va2 s .com if ((this.fVersionCombo != null) && (this.fVersionCombo.getSelectionIndex() == 0)) { containerPath = Neuro4jCore.NEURO4J_CONTAINER_PATH; corelibEntry = BuildPathSupport.getNeuro4jCoreLibraryEntry(); logicLibEntry = BuildPathSupport.getNeuro4jLogicLibraryEntry(); } if (corelibEntry == null) status.setError(WizardMessages.Neuro4jContainerWizardPage_error_version_not_available); else if ((Neuro4jCore.NEURO4J_CONTAINER_PATH.equals(containerPath)) && (this.fProject != null) && (!JUnitStubUtility.is50OrHigher(this.fProject))) { status.setWarning(WizardMessages.Neuro4jContainerWizardPage_warning_java5_required); } this.fContainerEntryResult = JavaCore.newContainerEntry(containerPath); if ((this.fResolvedPath != null) && (!this.fResolvedPath.isDisposed())) { if (corelibEntry != null) this.fResolvedPath .setText(getPathLabel(corelibEntry.getPath()) + getPathLabel(logicLibEntry.getPath())); else { this.fResolvedPath.setText(WizardMessages.Neuro4jContainerWizardPage_lib_not_found); } } if ((this.fResolvedSourcePath != null) && (!this.fResolvedSourcePath.isDisposed())) { if ((corelibEntry != null) && (corelibEntry.getSourceAttachmentPath() != null)) this.fResolvedSourcePath.setText(getPathLabel(corelibEntry.getSourceAttachmentPath())); else { this.fResolvedSourcePath.setText(WizardMessages.Neuro4jContainerWizardPage_source_not_found); } } updateStatus(status); }
From source file:org.org.eclipse.core.utils.jdt.tools.JavaProjectClasspathHelper.java
License:Open Source License
/** * This helper methods replaces a variable name with another in all matching entries of a project. If the target classpath variable doesn't exist, it is created on the fly. * /* w ww . j av a 2 s .c om*/ * @param originalName * @param targetName * @param javaProject * @param monitor */ public static void changeClasspathVariable(String originalName, String targetName, IJavaProject javaProject, IProgressMonitor monitor) { try { if (javaProject == null) { throw new JavaProjectInteractionException("Project should not be null."); } if (JavaCore.getClasspathVariable(targetName) == null) { JavaCore.setClasspathVariable(targetName, JavaCore.getClasspathVariable(originalName), monitor); } IClasspathEntry[] classpathEntries = getRawClasspath(javaProject); List<IClasspathEntry> targetClasspathEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry classpathEntry : classpathEntries) { if (!JavaProjectClasspathHelper.isVariableEntry(classpathEntry)) { targetClasspathEntries.add(classpathEntry); } else { IPath sourceAttachmentPath = classpathEntry.getSourceAttachmentPath(); IClasspathAttribute javadocClasspathAttribute = null; for (IClasspathAttribute classpathAttribute : classpathEntry.getExtraAttributes()) { if (classpathAttribute.getName() .equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) { javadocClasspathAttribute = classpathAttribute; } } IPath javadocPath = null; if (javadocClasspathAttribute != null && javadocClasspathAttribute.getValue() != null) { javadocPath = JavaProjectClasspathHelper .pathFromJavadocAttributeValue(javadocClasspathAttribute); } ClasspathEntryDefinition classpathEntryWrapper = new ClasspathEntryDefinition( classpathEntry.getPath(), sourceAttachmentPath, javadocPath, EntryType.VARIABLE); targetClasspathEntries.add(ClasspathHelper.createVariableEntryWithDifferentVariableName( classpathEntryWrapper, targetName, monitor)); } } JavaProjectClasspathHelper.updateRawClasspath(javaProject, targetClasspathEntries, new SubProgressMonitor(monitor, 1)); } catch (Exception e) { throw new JavaProjectInteractionException(e); } }
From source file:org.robovm.eclipse.RoboVMPlugin.java
License:Open Source License
private static void getSourcePaths(Set<String> paths, IJavaProject javaProject) throws CoreException { try {//from www .ja v a 2 s. co m // add the source jars of rt/objc/cocoatouch etc. File libDir = new File(RoboVMPlugin.getRoboVMHome().getBinDir().getParentFile(), "lib"); paths.add(new File(libDir, "robovm-cocoatouch-sources.jar").getAbsolutePath()); paths.add(new File(libDir, "robovm-objc-sources.jar").getAbsolutePath()); paths.add(new File(libDir, "robovm-rt-sources.jar").getAbsolutePath()); } catch (IOException e) { RoboVMPlugin.consoleError("Couldn't retrieve lib/ directory"); } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { IPath path = null; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IResource resource = root.findMember(entry.getPath()); if (resource != null) { path = resource.getLocation(); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (entry.getSourceAttachmentPath() != null) { path = entry.getSourceAttachmentPath(); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().toString()); if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { getSourcePaths(paths, JavaCore.create(project)); } } if (path != null) { paths.add(path.toOSString()); } } }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil.java
License:Open Source License
private static List<CPE> createCpes(Set<String> systemLibs, IJavaProject javaProject, IClasspathEntry entry) throws MalformedURLException, JavaModelException { String kind = toContentKind(entry); switch (kind) { case Classpath.ENTRY_KIND_BINARY: { String path = entry.getPath().toString(); CPE cpe = CPE.binary(path);/* w w w . jav a 2s .c om*/ if (systemLibs.contains(path)) { cpe.setSystem(true); } IPath sp = entry.getSourceAttachmentPath(); if (sp != null) { cpe.setSourceContainerUrl(sp.toFile().toURI().toURL()); // TODO: // IPath srp = entry.getSourceAttachmentRootPath(); // if (srp!=null) { // // } } return Collections.singletonList(cpe); } case Classpath.ENTRY_KIND_SOURCE: { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = entry.getPath(); return resolveDependencyProjectCPEs(projectPath); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { CPE cpe = createSourceCPE(javaProject, entry); cpe.setOwn(true); return cpe == null ? null : Collections.singletonList(cpe); } } default: break; } return Collections.emptyList(); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertJarEntry(IJavaProject project, String jarName, boolean expectSource) throws JavaModelException { IClasspathEntry[] classpath = project.getResolvedClasspath(false); StringBuffer seen = new StringBuffer(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { seen.append(entry.getPath() + "\n"); if (entry.getPath().toString().endsWith(jarName)) { //Found the jar! IPath sourcePath = entry.getSourceAttachmentPath(); if (expectSource) { assertNotNull(entry.getPath() + " has no source attachement", sourcePath); assertTrue(/*from ww w . j av a 2 s. com*/ entry.getPath() + " has source attachement " + sourcePath + " but it doesn't exist", sourcePath.toFile().exists()); } return; //OK } } } fail("Jar entry not found: " + jarName + "\nfound: " + seen.toString()); }
From source file:org.teavm.eclipse.debugger.TeaVMSourcePathComputerDelegate.java
License:Apache License
@Override public ISourceContainer[] computeSourceContainers(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException { List<ISourceContainer> sourceContainers = new ArrayList<>(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (!project.isOpen()) { continue; }// w ww . j a v a 2 s. c o m if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) { if (fragmentRoot.getResource() instanceof IFolder) { sourceContainers.add(new FolderSourceContainer((IFolder) fragmentRoot.getResource(), true)); } } for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: sourceContainers.add(new ClasspathContainerSourceContainer(entry.getPath())); break; case IClasspathEntry.CPE_LIBRARY: sourceContainers.add(new ExternalArchiveSourceContainer(entry.getPath().toString(), true)); if (entry.getSourceAttachmentPath() != null) { System.out.println(entry.getSourceAttachmentPath()); sourceContainers.add(new ExternalArchiveSourceContainer( entry.getSourceAttachmentPath().toString(), true)); sourceContainers .add(new DirectorySourceContainer(entry.getSourceAttachmentPath(), true)); } break; case IClasspathEntry.CPE_SOURCE: sourceContainers.add(new DirectorySourceContainer(entry.getPath(), true)); break; } } } } IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(config); IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, config); sourceContainers.addAll(Arrays.asList(JavaRuntime.getSourceContainers(resolved))); return sourceContainers.toArray(new ISourceContainer[sourceContainers.size()]); }
From source file:org.teavm.eclipse.TeaVMProjectBuilder.java
License:Apache License
private void prepareClassPath() throws CoreException { classPath = new URL[0]; sourceContainers = new IContainer[0]; sourceProviders = new SourceFileProvider[0]; IProject project = getProject();/*from w ww . j av a 2s . c om*/ if (!project.hasNature(JavaCore.NATURE_ID)) { return; } IJavaProject javaProject = JavaCore.create(project); PathCollector collector = new PathCollector(); SourcePathCollector srcCollector = new SourcePathCollector(); SourcePathCollector binCollector = new SourcePathCollector(); SourceFileCollector sourceFileCollector = new SourceFileCollector(); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); try { if (javaProject.getOutputLocation() != null) { IContainer container = (IContainer) workspaceRoot.findMember(javaProject.getOutputLocation()); collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } Queue<IJavaProject> projectQueue = new ArrayDeque<>(); projectQueue.add(javaProject); Set<IJavaProject> visitedProjects = new HashSet<>(); while (!projectQueue.isEmpty()) { javaProject = projectQueue.remove(); if (!visitedProjects.add(javaProject)) { continue; } IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: try { collector.addPath(entry.getPath()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } if (entry.getSourceAttachmentPath() != null) { sourceFileCollector.addFile(entry.getSourceAttachmentPath()); } break; case IClasspathEntry.CPE_SOURCE: if (entry.getOutputLocation() != null) { try { IResource res = workspaceRoot.findMember(entry.getOutputLocation()); if (res != null) { collector.addPath(res.getLocation()); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } IContainer srcContainer = (IContainer) workspaceRoot.findMember(entry.getPath()); if (srcContainer != null) { srcCollector.addContainer(srcContainer); sourceFileCollector.addFile(srcContainer.getLocation()); try { collector.addPath(srcContainer.getLocation()); } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } break; case IClasspathEntry.CPE_PROJECT: { IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); IProject depProject = resource.getProject(); if (!depProject.hasNature(JavaCore.NATURE_ID)) { break; } IJavaProject depJavaProject = JavaCore.create(depProject); if (depJavaProject.getOutputLocation() != null) { try { IContainer container = (IContainer) workspaceRoot .findMember(depJavaProject.getOutputLocation()); if (container != null) { collector.addPath(container.getLocation()); binCollector.addContainer(container); } } catch (MalformedURLException e) { TeaVMEclipsePlugin.logError(e); } } projectQueue.add(depJavaProject); break; } } } } classPath = collector.getUrls(); sourceContainers = srcCollector.getContainers(); classFileContainers = binCollector.getContainers(); sourceProviders = sourceFileCollector.getProviders(); }
From source file:runjettyrun.tabs.action.AddClassFolderAction.java
License:Open Source License
/** * Adds all exported entries defined by <code>proj</code> to the list * <code>runtimeEntries</code>. * * @param proj// ww w . j av a2s.c o m * @param runtimeEntries * @throws JavaModelException */ protected void collectExportedEntries(IJavaProject proj, List<IRuntimeClasspathEntry> runtimeEntries) throws CoreException { IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.isExported()) { IRuntimeClasspathEntry rte = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), proj); int kind = 0; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: kind = IRuntimeClasspathEntry.USER_CLASSES; break; case IClasspathContainer.K_SYSTEM: kind = IRuntimeClasspathEntry.BOOTSTRAP_CLASSES; break; case IClasspathContainer.K_DEFAULT_SYSTEM: kind = IRuntimeClasspathEntry.STANDARD_CLASSES; break; } rte = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), kind, proj); break; case IClasspathEntry.CPE_LIBRARY: rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); rte.setSourceAttachmentPath(entry.getSourceAttachmentPath()); rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath()); break; case IClasspathEntry.CPE_PROJECT: String name = entry.getPath().segment(0); IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (p.exists()) { IJavaProject jp = JavaCore.create(p); if (jp.exists()) { rte = JavaRuntime.newProjectRuntimeClasspathEntry(jp); } } break; case IClasspathEntry.CPE_VARIABLE: rte = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); break; default: break; } if (rte != null) { if (!runtimeEntries.contains(rte)) { runtimeEntries.add(rte); } } } } }