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: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); }/* www . 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 w ww . jav a 2s . c o 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:com.microsoft.javapkgbuild.Tasks.java
License:MIT License
public static void exportReferences(String projectName, String outputFileName) throws JavaModelException { try {//from w w w. j a va 2s. com IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); IJavaProject javaProject = JavaCore.create(project); DocumentBuilderFactory xFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = xFactory.newDocumentBuilder(); Document doc = builder.newDocument(); Element mainRoot = doc.createElement("classpath"); mainRoot.setAttribute("projectName", projectName); doc.appendChild(mainRoot); IClasspathEntry[] classPathList = javaProject.getResolvedClasspath(true); for (IClasspathEntry cp : classPathList) { Element cpNode = doc.createElement("classpathentry"); cpNode.setAttribute("path", cp.getPath().toOSString()); cpNode.setAttribute("kind", getClassPathType(cp)); cpNode.setAttribute("exported", Boolean.toString(cp.isExported())); IPath sourceFolder = cp.getSourceAttachmentPath(); if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY && sourceFolder != null) cpNode.setAttribute("sourcepath", sourceFolder.toOSString()); mainRoot.appendChild(cpNode); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); FileOutputStream fos = new FileOutputStream(outputFileName); StreamResult outFile = new StreamResult(fos); transformer.transform(source, outFile); fos.close(); System.out.println("Output file is: " + outputFileName); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesContainer.java
License:Apache License
private Collection<IClasspathEntry> findModuleArchivePaths(IJavaProject javaProject, IProject project, TypeChecker typeChecker) throws JavaModelException, CoreException { final Map<String, IClasspathEntry> paths = new TreeMap<String, IClasspathEntry>(); Context context = typeChecker.getContext(); RepositoryManager provider = context.getRepositoryManager(); Set<Module> modulesToAdd = context.getModules().getListOfModules(); //modulesToAdd.add(projectModules.getLanguageModule()); for (Module module : modulesToAdd) { JDTModule jdtModule = (JDTModule) module; String name = module.getNameAsString(); if (name.equals(Module.DEFAULT_MODULE_NAME) || JDKUtils.isJDKModule(name) || JDKUtils.isOracleJDKModule(name) || module.equals(module.getLanguageModule()) || isProjectModule(javaProject, module) || !module.isAvailable()) { continue; }/*from ww w.ja va 2s . co m*/ IPath modulePath = getModuleArchive(provider, jdtModule); if (modulePath != null) { IPath srcPath = null; for (IProject p : project.getReferencedProjects()) { if (p.isAccessible() && p.getLocation().isPrefixOf(modulePath)) { //the module belongs to a referenced //project, so use the project source srcPath = p.getLocation(); break; } } if (srcPath == null) { for (IClasspathEntry entry : classpathEntries) { if (entry.getPath().equals(modulePath)) { srcPath = entry.getSourceAttachmentPath(); break; } } } if (srcPath == null && !modulesWithSourcesAlreadySearched.contains(module.toString())) { //otherwise, use the src archive srcPath = getSourceArchive(provider, jdtModule); } modulesWithSourcesAlreadySearched.add(module.toString()); IClasspathEntry newEntry = newLibraryEntry(modulePath, srcPath, null); paths.put(newEntry.toString(), newEntry); } else { // FIXME: ideally we should find the module.java file and put the marker there, but // I've no idea how to find it and which import is the cause of the import problem // as it could be transitive IMarker marker = project.createMarker(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, "no module archive found for classpath container: " + module.getNameAsString() + "/" + module.getVersion()); marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); } } if (isExplodeModulesEnabled(project)) { IClasspathEntry newEntry = newLibraryEntry(getCeylonClassesOutputFolder(project).getFullPath(), project.getFullPath(), null, false); paths.put(newEntry.toString(), newEntry); } return asList(paths.values().toArray(new IClasspathEntry[paths.size()])); }
From source file:com.siteview.mde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addLibraryEntry(IProject project, IMonitorLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException { String name = ClasspathUtilCore.expandLibraryName(library.getName()); IResource jarFile = project.findMember(name); if (jarFile == null) return;/*ww w . j a v a 2 s . c om*/ IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry oldEntry = root.getRawClasspathEntry(); // If we have the same binary root but new or different source, we should recreate the entry if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null) || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) { if (!result.contains(oldEntry)) { result.add(oldEntry); return; } } } IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); if (!result.contains(entry)) result.add(entry); }
From source file:com.siteview.mde.internal.launching.sourcelookup.PDESourceLookupDirector.java
License:Open Source License
private IRuntimeClasspathEntry convertClasspathEntry(IClasspathEntry entry) { if (entry == null) return null; IPath srcPath = entry.getSourceAttachmentPath(); if (srcPath != null && srcPath.segmentCount() > 0) { IRuntimeClasspathEntry rte = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); rte.setSourceAttachmentPath(srcPath); rte.setSourceAttachmentRootPath(entry.getSourceAttachmentRootPath()); return rte; }// w ww. j a v a 2s .com return null; }
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//w w w . j a v a2 s .com * @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()); }
From source file:de.ovgu.featureide.aspectj.AspectJComposer.java
License:Open Source License
/** * Set the unselected aspect files to be excluded * @param e The ClasspathEntry to set/*from w ww . j a v a 2 s . c o m*/ * @return The set entry */ private IClasspathEntry setSourceEntry(IClasspathEntry e) { IPath[] excludedAspects = new IPath[unSelectedFeatures.size()]; int i = 0; for (String f : unSelectedFeatures) { excludedAspects[i++] = new Path(f.replaceAll("_", "/") + ".aj"); } return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath(), e.getInclusionPatterns(), excludedAspects, e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }
From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java
License:Open Source License
/** * Set the source path of the given <code>ClasspathEntry</code> * @param buildPath The new build path//from www.j a v a 2 s. c o m * @param e The entry to set * @return The entry with the new source path */ public IClasspathEntry setSourceEntry(String buildPath, IClasspathEntry e) { return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path(buildPath), e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); }
From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java
License:Open Source License
private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) { try {//from w w w. j a va 2s. co m final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); if (index >= 0) { final IClasspathEntry e = classpathEntrys[index]; if (!e.getPath().equals(path)) { final IPath formerSourcePath = e.getPath(); classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); javaProject.setRawClasspath(classpathEntrys, null); return formerSourcePath; } } else { final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length); newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); javaProject.setRawClasspath(newEntrys, null); } } catch (JavaModelException e) { MPLPlugin.getDefault().logError(e); } return null; }