List of usage examples for org.eclipse.jdt.core IClasspathEntry getSourceAttachmentRootPath
IPath getSourceAttachmentRootPath();
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 .java 2s . c om*/ 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.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. *///from w w w .j a va2s. 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.project.core.PluginClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { final String key = PluginClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());/*from ww w. j a v a 2 s .co m*/ final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); cpDecorations.clearAllDecorations(key); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); cpDecorations.setDecorations(key, eid, dec); } } cpDecorations.save(); IPath portalDir = null; String javadocURL = null; IPath sourceLocation = null; if (containerSuggestion instanceof PluginClasspathContainer) { portalDir = ((PluginClasspathContainer) containerSuggestion).getPortalDir(); javadocURL = ((PluginClasspathContainer) containerSuggestion).getJavadocURL(); sourceLocation = ((PluginClasspathContainer) containerSuggestion).getSourceLocation(); } else { portalDir = ServerUtil.getPortalDir(project); try { ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject()); if (liferayRuntime != null) { javadocURL = liferayRuntime.getJavadocURL(); sourceLocation = liferayRuntime.getSourceLocation(); } } catch (Exception e) { ProjectCore.logError(e); } } if (portalDir != null) { IClasspathContainer newContainer = getCorrectContainer(containerPath, containerPath.segment(1), project, portalDir, javadocURL, sourceLocation); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { newContainer }, null); } }
From source file:com.liferay.ide.project.core.SDKClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { final String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());//from w w w .j a v a 2 s.c om final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); cpDecorations.clearAllDecorations(key); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); cpDecorations.setDecorations(key, eid, dec); } } cpDecorations.save(); IPath portalDir = null; IPath portalGlobalDir = null; String javadocURL = null; IPath sourceLocation = null; IPath bundleDir = null; IPath[] bundleDependencyJarPaths = null; PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject()); boolean containerChanged = true; if (containerSuggestion instanceof SDKClasspathContainer) { portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir(); bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir(); portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir(); javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL(); sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation(); bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath(); if (bundle != null && bundle.getAppServerPortalDir().equals(portalDir)) { containerChanged = false; } } if (containerChanged == true) { if (bundle == null) { return; } portalDir = bundle.getAppServerPortalDir(); portalGlobalDir = bundle.getAppServerLibGlobalDir(); bundleDependencyJarPaths = bundle.getBundleDependencyJars(); } IPath[] sdkDependencyPaths = getSDKDependencies(project); if (portalDir != null && portalGlobalDir != null) { IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { newContainer }, null); } }
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 w w .j a v a 2 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 a2s .c om*/ 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.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; }//from w w w. j a v a 2 s . c om 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//from w w w. j av a 2 s .c o 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()); }
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//ww w.ja va 2 s. c om * @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 w w w. j a va 2 s . co 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()); }