org.eclipse.jdt.core.IClasspathAttribute Java Examples
The following examples show how to use
org.eclipse.jdt.core.IClasspathAttribute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnresolvedTypesQuickFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testDontImportTestClassesInMainCode() throws Exception { IPackageFragmentRoot testSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src-tests", new Path[0], new Path[0], "bin-tests", new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") }); IPackageFragment pack1 = fSourceFolder.createPackageFragment("pp", false, null); StringBuilder buf1 = new StringBuilder(); buf1.append("package pp;\n"); buf1.append("public class C1 {\n"); buf1.append(" Tests at=new Tests();\n"); buf1.append("}\n"); ICompilationUnit cu1 = pack1.createCompilationUnit("C1.java", buf1.toString(), false, null); IPackageFragment pack2 = testSourceFolder.createPackageFragment("pt", false, null); StringBuilder buf2 = new StringBuilder(); buf2.append("package pt;\n"); buf2.append("public class Tests {\n"); buf2.append("}\n"); pack2.createCompilationUnit("Tests.java", buf2.toString(), false, null); assertCodeActionNotExists(cu1, "Import 'Tests' (pt)"); }
Example #2
Source File: LibraryClasspathContainerResolverService.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private static IClasspathAttribute[] getClasspathAttributes( LibraryFile libraryFile, Artifact artifact) throws CoreException { List<IClasspathAttribute> attributes = MavenCoordinatesHelper.createClasspathAttributes( libraryFile.getMavenCoordinates(), artifact.getVersion()); if (libraryFile.isExport()) { attributes.add(UpdateClasspathAttributeUtil.createDependencyAttribute(true /* isWebApp */)); } else { attributes.add(UpdateClasspathAttributeUtil.createNonDependencyAttribute()); } if (libraryFile.getSourceUri() != null) { addUriAttribute(attributes, CLASSPATH_ATTRIBUTE_SOURCE_URL, libraryFile.getSourceUri()); } if (libraryFile.getJavadocUri() != null) { addUriAttribute( attributes, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, libraryFile.getJavadocUri()); } return attributes.toArray(new IClasspathAttribute[0]); }
Example #3
Source File: JavadocContentAccess2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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(); } } } } return encoding; }
Example #4
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } 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; }
Example #5
Source File: MavenCoordinatesHelper.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
public static List<IClasspathAttribute> createClasspathAttributes(MavenCoordinates mavenCoordinates, String actualVersion) { List<IClasspathAttribute> attributes = Lists.newArrayList( JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_REPOSITORY, mavenCoordinates.getRepository()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_GROUP_ID, mavenCoordinates.getGroupId()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_ARTIFACT_ID, mavenCoordinates.getArtifactId()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_TYPE, mavenCoordinates.getType()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_VERSION, actualVersion) ); if (mavenCoordinates.getClassifier() != null) { attributes.add(JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_CLASSIFIER, mavenCoordinates.getClassifier())); } return attributes; }
Example #6
Source File: JavadocConfigurationPropertyPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException { ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false))); return null; } String containerName= container.getDescription(); IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName)); return null; } IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName)); fIsReadOnly= true; return entry; } Assert.isNotNull(entry); setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description); return entry; }
Example #7
Source File: OptionsConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected Link createIgnoreOptionalProblemsLink(Composite parent) { final IClasspathEntry sourceFolderEntry= getSourceFolderIgnoringOptionalProblems(); if (sourceFolderEntry != null) { Link link= new Link(parent, SWT.NONE); link.setText(PreferencesMessages.OptionsConfigurationBlock_IgnoreOptionalProblemsLink); link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { HashMap<Object, Object> data= new HashMap<Object, Object>(1); data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY, sourceFolderEntry); data.put(BuildPathsPropertyPage.DATA_REVEAL_ATTRIBUTE_KEY, IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS); getPreferenceContainer().openPage(BuildPathsPropertyPage.PROP_ID, data); } }); return link; } return null; }
Example #8
Source File: UtilitiesTest.java From sarl with Apache License 2.0 | 6 votes |
@Test public void newLibraryEntry_precomputedPath_javadocMapping() { // Bundle bundle = Platform.getBundle("io.sarl.lang.core"); Assume.assumeNotNull(bundle); // IPath precomputedPath = BundleUtil.getBundlePath(bundle); // IClasspathEntry entry = Utilities.newLibraryEntry(bundle, precomputedPath, (b) -> "http://fake.org"); assertNotNull(entry); assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind()); assertEquals(IPackageFragmentRoot.K_BINARY, entry.getContentKind()); assertEquals(precomputedPath, entry.getPath()); assertEquals(BundleUtil.getSourceBundlePath(bundle, BundleUtil.getBundlePath(bundle)), entry.getSourceAttachmentPath()); IClasspathAttribute[] extras = entry.getExtraAttributes(); assertNotNull(extras); assertEquals(1, extras.length); assertEquals("javadoc_location", extras[0].getName()); if (isEclipseRuntimeEnvironment()) { assertTrue(extras[0].getValue().endsWith("io.sarl.lang.core/")); } else { assertEquals("http://fake.org", extras[0].getValue()); } }
Example #9
Source File: CPListElementAttribute.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public ClasspathAttributeAccess getClasspathAttributeAccess() { if (fCachedAccess == null) { fCachedAccess= new ClasspathAttributeAccess() { @Override public IClasspathAttribute getClasspathAttribute() { return CPListElementAttribute.this.getClasspathAttribute(); } @Override public IJavaProject getJavaProject() { return getParent().getJavaProject(); } @Override public IClasspathEntry getParentClasspassEntry() { return getParent().getClasspathEntry(); } }; } return fCachedAccess; }
Example #10
Source File: ClasspathEntry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * This function computes the URL of the index location for this classpath entry. It returns null if the URL is * invalid. */ public URL getLibraryIndexLocation() { switch(getEntryKind()) { case IClasspathEntry.CPE_LIBRARY : case IClasspathEntry.CPE_VARIABLE : break; default : return null; } if (this.extraAttributes == null) return null; for (int i= 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attrib= this.extraAttributes[i]; if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { return null; } } } return null; }
Example #11
Source File: JavadocAttributeConfiguration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public IClasspathAttribute performEdit(Shell shell, ClasspathAttributeAccess attribute) { String initialLocation= attribute.getClasspathAttribute().getValue(); String elementName= attribute.getParentClasspassEntry().getPath().lastSegment(); try { URL locationURL= initialLocation != null ? new URL(initialLocation) : null; URL[] result= BuildPathDialogAccess.configureJavadocLocation(shell, elementName, locationURL); if (result != null) { URL newURL= result[0]; String string= newURL != null ? newURL.toExternalForm() : null; return JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, string); } } catch (MalformedURLException e) { // todo } return null; }
Example #12
Source File: SourceAttachmentBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static String getSourceAttachmentEncoding(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } 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.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); } } return null; }
Example #13
Source File: MavenCoordinatesHelperTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public void testCreateClasspathAttributesWithClassifier() { MavenCoordinates mavenCoordinates = builder.setClassifier("classifier").build(); List<IClasspathAttribute> classpathAttributes = MavenCoordinatesHelper.createClasspathAttributes(mavenCoordinates, "1.0.0"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.repository", "testRepo"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.groupid", "groupId"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.artifactId", "artifactId"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.type", "war"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.version", "1.0.0"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.classifier", "classifier"); }
Example #14
Source File: ProjectCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static boolean isTestClasspathEntry(IClasspathEntry entry) { if (entry.getEntryKind() != ClasspathEntry.CPE_SOURCE) { return false; } if (entry.isTest()) { return true; } for (final IClasspathAttribute attribute : entry.getExtraAttributes()) { String attributeName = attribute.getName(); // attribute name could be "maven.scope" for Maven, "gradle_scope" or "gradle_used_by_scope" for Gradle if (attributeName.contains("scope")) { // the attribute value could be "test" or "integrationTest" return attribute.getValue() != null && attribute.getValue().toLowerCase().contains(TEST_SCOPE_VALUE); } } return false; }
Example #15
Source File: UtilitiesTest.java From sarl with Apache License 2.0 | 6 votes |
@Test public void newLibraryEntry_nullPath_nullJavadocMapping() { Bundle bundle = Platform.getBundle("io.sarl.lang.core"); Assume.assumeNotNull(bundle); // IClasspathEntry entry = Utilities.newLibraryEntry(bundle, null, null); assertNotNull(entry); assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind()); assertEquals(IPackageFragmentRoot.K_BINARY, entry.getContentKind()); assertEquals(BundleUtil.getBundlePath(bundle), entry.getPath()); assertEquals(BundleUtil.getSourceBundlePath(bundle, BundleUtil.getBundlePath(bundle)), entry.getSourceAttachmentPath()); IClasspathAttribute[] extras = entry.getExtraAttributes(); assertNotNull(extras); if (isEclipseRuntimeEnvironment()) { assertEquals(1, extras.length); assertEquals("javadoc_location", extras[0].getName()); assertTrue(extras[0].getValue().endsWith("io.sarl.lang.core/")); } else { assertEquals(0, extras.length); } }
Example #16
Source File: JavaDocLocations.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } 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; }
Example #17
Source File: MainProjectWizardPage.java From sarl with Apache License 2.0 | 6 votes |
@Override public void putDefaultClasspathEntriesIn(Collection<IClasspathEntry> classpathEntries) { final IPath newPath = this.jreGroup.getJREContainerPath(); if (newPath != null) { classpathEntries.add(JavaCore.newContainerEntry(newPath)); } else { final IClasspathEntry[] entries = PreferenceConstants.getDefaultJRELibrary(); classpathEntries.addAll(Arrays.asList(entries)); } final IClasspathEntry sarlClasspathEntry = JavaCore.newContainerEntry( SARLClasspathContainerInitializer.CONTAINER_ID, new IAccessRule[0], new IClasspathAttribute[0], true); classpathEntries.add(sarlClasspathEntry); }
Example #18
Source File: CreateAppEngineFlexWtpProject.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private static void addDependenciesToClasspath(IProject project, IFolder folder, IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> newEntries = new ArrayList<>(); IClasspathAttribute[] nonDependencyAttribute = new IClasspathAttribute[] {UpdateClasspathAttributeUtil.createNonDependencyAttribute()}; // Add all the jars under lib folder to the classpath File libFolder = folder.getLocation().toFile(); for (File file : libFolder.listFiles()) { IPath path = Path.fromOSString(file.toPath().toString()); newEntries.add(JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0], nonDependencyAttribute, false /* isExported */)); } ClasspathUtil.addClasspathEntries(project, newEntries, monitor); }
Example #19
Source File: ClasspathEntry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) { if (attributes == null) return NO_EXTRA_ATTRIBUTES; int length = attributes.getLength(); if (length == 0) return NO_EXTRA_ATTRIBUTES; IClasspathAttribute[] result = new IClasspathAttribute[length]; int index = 0; for (int i = 0; i < length; ++i) { Node node = attributes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element attribute = (Element)node; String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME); if (name == null) continue; String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE); if (value == null) continue; result[index++] = new ClasspathAttribute(name, value); } } if (index != length) System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index); return result; }
Example #20
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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(); } } } } return encoding; }
Example #21
Source File: XtendClasspathContainer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private void addEntry(final List<IClasspathEntry> cpEntries, final String bundleId) { Bundle bundle = Platform.getBundle(bundleId); if (bundle != null) { IPath bundlePath = bundlePath(bundle); IPath sourceBundlePath = calculateSourceBundlePath(bundle, bundlePath); IClasspathAttribute[] extraAttributes = null; if (XtendClasspathContainer.XTEXT_XBASE_LIB_BUNDLE_ID.equals(bundleId) || XtendClasspathContainer.XTEND_LIB_BUNDLE_ID.equals(bundleId) || XtendClasspathContainer.XTEND_LIB_MACRO_BUNDLE_ID.equals(bundleId)) { extraAttributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, calculateJavadocURL()) }; } cpEntries.add(JavaCore.newLibraryEntry(bundlePath, sourceBundlePath, null, new IAccessRule[] {}, extraAttributes, false)); } }
Example #22
Source File: BuildPathBasePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected boolean removeCustomAttribute(CPListElementAttribute elem) { ClasspathAttributeConfiguration config= fAttributeDescriptors.get(elem.getKey()); if (config != null) { IClasspathAttribute result= config.performRemove(elem.getClasspathAttributeAccess()); if (result != null) { elem.setValue(result.getValue()); return true; } } return false; }
Example #23
Source File: GWTProjectUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private static boolean isOptional(IClasspathEntry entry) { IClasspathAttribute[] attributes = entry.getExtraAttributes(); for (IClasspathAttribute attribute : attributes) { if (IClasspathAttribute.OPTIONAL.equals(attribute.getName()) && "true".equals(attribute.getValue())) //$NON-NLS-1$ return true; } return false; }
Example #24
Source File: ClasspathEntry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
void encodeExtraAttributes(XMLWriter writer, boolean indent, boolean newLine) { writer.startTag(TAG_ATTRIBUTES, indent); for (int i = 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attribute = this.extraAttributes[i]; HashMap parameters = new HashMap(); parameters.put(TAG_ATTRIBUTE_NAME, attribute.getName()); parameters.put(TAG_ATTRIBUTE_VALUE, attribute.getValue()); writer.printTag(TAG_ATTRIBUTE, parameters, indent, newLine, true); } writer.endTag(TAG_ATTRIBUTES, indent, true/*insert new line*/); }
Example #25
Source File: ClasspathEntry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ClasspathEntry( int contentKind, int entryKind, IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath, IPath specificOutputLocation, boolean isExported, IAccessRule[] accessRules, boolean combineAccessRules, IClasspathAttribute[] extraAttributes) { this( contentKind, entryKind, path, inclusionPatterns, exclusionPatterns, sourceAttachmentPath, sourceAttachmentRootPath, specificOutputLocation, null, isExported, accessRules, combineAccessRules, extraAttributes); }
Example #26
Source File: NativeLibAttributeConfiguration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public IClasspathAttribute performEdit(Shell shell, ClasspathAttributeAccess attribute) { NativeLibrariesDialog dialog= new NativeLibrariesDialog(shell, attribute.getClasspathAttribute().getValue(), attribute.getParentClasspassEntry()); if (dialog.open() == Window.OK) { return JavaCore.newClasspathAttribute(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY, dialog.getNativeLibraryPath()); } return null; }
Example #27
Source File: NativeLibrariesPropertyPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static String getNativeLibrariesPath(IClasspathEntry entry) { IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { if (extraAttributes[i].getName().equals(JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY)) { return extraAttributes[i].getValue(); } } return null; }
Example #28
Source File: JavaClasspathParser.java From sarl with Apache License 2.0 | 5 votes |
@SuppressWarnings("checkstyle:innerassignment") private static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) { if (attributes == null) { return ClasspathEntry.NO_EXTRA_ATTRIBUTES; } final int length = attributes.getLength(); if (length == 0) { return ClasspathEntry.NO_EXTRA_ATTRIBUTES; } IClasspathAttribute[] result = new IClasspathAttribute[length]; int index = 0; for (int i = 0; i < length; ++i) { final Node node = attributes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element attribute = (Element) node; final String name = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_NAME); if (name == null) { continue; } final String value = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_VALUE); if (value == null) { continue; } result[index++] = new ClasspathAttribute(name, value); } } if (index != length) { System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index); } return result; }
Example #29
Source File: GWTJarsRuntime.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
@Override public IClasspathEntry[] getClasspathEntries() { // Note that the GWT SDK puts the javadoc in "doc/javadoc" IPath gwtJavadocLocation = getInstallationPath().append(new Path("doc/javadoc")); IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0]; if (gwtJavadocLocation.toFile().exists()) { extraAttributes = new IClasspathAttribute[] {JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, gwtJavadocLocation.toFile() .toURI().toString())}; } List<IClasspathEntry> buildClasspathEntries = new ArrayList<IClasspathEntry>(); if (validate().isOK()) { List<IPath> buildClasspaths = getBuildClasspaths(); for (IPath buildClasspath : buildClasspaths) { if (buildClasspath.lastSegment().startsWith("gwt-")) { buildClasspathEntries.add(JavaCore.newLibraryEntry(buildClasspath, null, null, new IAccessRule[0], extraAttributes, false)); } else { buildClasspathEntries.add(JavaCore.newLibraryEntry(buildClasspath, Util.findSourcesJarForClassesJar(buildClasspath), null, new IAccessRule[0], new IClasspathAttribute[0], false)); } } } return buildClasspathEntries.toArray(NO_ICLASSPATH_ENTRIES); }
Example #30
Source File: GWTJarsRuntimeTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void testGetClasspathEntries() throws Exception { IClasspathEntry[] cpEntries = runtime.getClasspathEntries(); // Look for the gwt-specific classpath entries List<IClasspathEntry> gwtCpEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry cpEntry : cpEntries) { if (isGWTJar(runtime, cpEntry.getPath().lastSegment())) { gwtCpEntries.add(cpEntry); } } // Make sure that there are two of them assertEquals(3, gwtCpEntries.size()); for (int i = 0; i < gwtCpEntries.size(); i++) { IClasspathEntry gwtClasspathEntry = gwtCpEntries.get(i); assertEquals(IClasspathEntry.CPE_LIBRARY, gwtClasspathEntry.getEntryKind()); assertEquals(IPackageFragmentRoot.K_BINARY, gwtClasspathEntry.getContentKind()); // Verify that our classpath entries point at the GWT javadoc. IClasspathAttribute[] extraAttributes = gwtClasspathEntry.getExtraAttributes(); assertTrue("No extra attributes seen for classpath entry: " + gwtClasspathEntry, extraAttributes.length > 0); assertEquals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, extraAttributes[0].getName()); /* * Entries should have their javadoc location point at a directory with "index.html". Strangely, the values of * these classpath attributes are specified as "file://" urls. */ File jdLocation = new File(new URL(extraAttributes[0].getValue()).getFile()); assertTrue("Javadoc file does not exist", jdLocation.exists()); List<String> files1 = Arrays.asList(jdLocation.list()); assertTrue("Javadoc file is not an index.html file.", files1.contains("index.html")); } }