Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#getExtraAttributes()

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry#getExtraAttributes() . 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: UtilitiesTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Test
public void newLibraryEntry_precomputedPath_nullJavadocMapping() {
	//
	Bundle bundle = Platform.getBundle("io.sarl.lang.core");
	Assume.assumeNotNull(bundle);
	//
	IPath precomputedPath = BundleUtil.getBundlePath(bundle);
	//
	IClasspathEntry entry = Utilities.newLibraryEntry(bundle, precomputedPath, null);
	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);
	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 2
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: SourceAttachmentBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 4
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 6
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 7
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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 8
Source File: JavaDocLocations.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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 9
Source File: ProjectCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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 10
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Test
public void newLibraryEntry_nullPath_javadocMapping() {
	Bundle bundle = Platform.getBundle("io.sarl.lang.core");
	Assume.assumeNotNull(bundle);
	//
	IClasspathEntry entry = Utilities.newLibraryEntry(bundle, null, (b) -> "http://fake.org");
	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);
	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 11
Source File: GWTJarsRuntimeTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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"));
  }
}
 
Example 12
Source File: GWTProjectUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
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 13
Source File: JdtUtils.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * There is an issue on IClasspathEntry#isTest: it will return true if the scope is runtime, so we will this method for testing whether
 * the classpath entry is for test only.
 *
 * @param classpathEntry classpath entry
 * @return whether this classpath entry is only used in test
 */
public static boolean isTest(final IClasspathEntry classpathEntry) {
    for (IClasspathAttribute attribute : classpathEntry.getExtraAttributes()) {
        if (GRADLE_SCOPE_ATTRIBUTE.equals(attribute.getName()) || MAVEN_SCOPE_ATTRIBUTE.equals(attribute.getName())) {
            return TEST_SCOPE.equals(attribute.getValue());
        }
    }
    return classpathEntry.isTest();
}
 
Example 14
Source File: SourceAttachmentCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static String getSourceAttachmentEncoding(IClasspathEntry entry) {
	if (entry != null && entry.getExtraAttributes() != null) {
		for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
			if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attribute.getName())) {
				return attribute.getValue();
			}
		}
	}

	return null;
}
 
Example 15
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isIgnoringOptionalProblems(IClasspathEntry entry) {
	if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
		IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
		for (int i= 0; i < extraAttributes.length; i++) {
			IClasspathAttribute attrib= extraAttributes[i];
			if (IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS.equals(attrib.getName())) {
				return "true".equals(attrib.getValue()); //$NON-NLS-1$
			}
		}
	}
	return false;
}
 
Example 16
Source File: NativeLibrariesPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 17
Source File: OptionsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IClasspathEntry getSourceFolderIgnoringOptionalProblems() {
	if (fProject == null) {
		return null;
	}
	IJavaProject javaProject= JavaCore.create(fProject);
	if (javaProject == null) {
		return null;
	}
	try {
		IClasspathEntry[] classpathEntries= javaProject.getRawClasspath();
		for (int i= 0; i < classpathEntries.length; i++) {
			IClasspathEntry entry= classpathEntries[i];
			if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
				IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
				for (int j= 0; j < extraAttributes.length; j++) {
					IClasspathAttribute attrib= extraAttributes[j];
					if (IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS.equals(attrib.getName())) {
						if ("true".equals(attrib.getValue())) { //$NON-NLS-1$
							return entry;
						} else {
							break;
						}
					}
				}
			}
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example 18
Source File: BinFolderConfigurator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * IClasspathEntry.isTest is not avaiable on Oxygen.
 */
@Deprecated
private boolean isTest(IClasspathEntry entry) {
	for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
		if ("test".equals(attribute.getName()) && "true".equals(attribute.getValue())) //$NON-NLS-1$
			return true;
	}
	return false;
}
 
Example 19
Source File: CreateAppEngineFlexWtpProjectTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private boolean hasNonDependencyAttribute(File jar) throws JavaModelException {
  IJavaProject javaProject = JavaCore.create(project);
  for (IClasspathEntry entry : javaProject.getRawClasspath()) {
    if (entry.getPath().toFile().equals(jar)) {
      for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
        if (isNonDependencyAttribute(attribute)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example 20
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement, IJavaProject project) {
	IPath path= curr.getPath();
	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();

	// get the resource
	IResource res= null;
	boolean isMissing= false;
	IPath linkTarget= null;

	switch (curr.getEntryKind()) {
		case IClasspathEntry.CPE_CONTAINER:
			try {
				isMissing= project != null && (JavaCore.getClasspathContainer(path, project) == null);
			} catch (JavaModelException e) {
				isMissing= true;
			}
			break;
		case IClasspathEntry.CPE_VARIABLE:
			IPath resolvedPath= JavaCore.getResolvedVariablePath(path);
			isMissing=  root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
			break;
		case IClasspathEntry.CPE_LIBRARY:
			res= root.findMember(path);
			if (res == null) {
				if (!ArchiveFileFilter.isArchivePath(path, true)) {
					if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
							&& root.getProject(path.segment(0)).exists()) {
						res= root.getFolder(path);
					}
				}

				IPath rawPath= path;
				if (project != null) {
					IPackageFragmentRoot[] roots= project.findPackageFragmentRoots(curr);
					if (roots.length == 1)
						rawPath= roots[0].getPath();
				}
				isMissing= !rawPath.toFile().exists(); // look for external JARs and folders
			} else if (res.isLinked()) {
				linkTarget= res.getLocation();
			}
			break;
		case IClasspathEntry.CPE_SOURCE:
			path= path.removeTrailingSeparator();
			res= root.findMember(path);
			if (res == null) {
				if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
					res= root.getFolder(path);
				}
				isMissing= true;
			} else if (res.isLinked()) {
				linkTarget= res.getLocation();
			}
			break;
		case IClasspathEntry.CPE_PROJECT:
			res= root.findMember(path);
			isMissing= (res == null);
			break;
	}
	CPListElement elem= new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res, linkTarget);
	elem.setExported(curr.isExported());
	elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
	elem.setAttribute(OUTPUT, curr.getOutputLocation());
	elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
	elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
	elem.setAttribute(ACCESSRULES, curr.getAccessRules());
	elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

	IClasspathAttribute[] extraAttributes= curr.getExtraAttributes();
	for (int i= 0; i < extraAttributes.length; i++) {
		IClasspathAttribute attrib= extraAttributes[i];
		CPListElementAttribute attribElem= elem.findAttributeElement(attrib.getName());
		if (attribElem == null) {
			elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
		} else {
			attribElem.setValue(attrib.getValue());
		}
	}

	elem.setIsMissing(isMissing);
	return elem;
}