Java Code Examples for org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries()

The following examples show how to use org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries() . 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: NewMavenBasedAppEngineProjectWizardTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
static IClasspathEntry[] getAppEngineServerRuntimeClasspathEntries(IProject project) {
  IJavaProject javaProject = JavaCore.create(project);
  IPath containerPath = new Path(
      "org.eclipse.jst.server.core.container/com.google.cloud.tools.eclipse.appengine.standard.runtimeClasspathProvider");
  try {
    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
          && containerPath.isPrefixOf(entry.getPath())) {
        // resolve and return the entries
        IClasspathContainer container =
            JavaCore.getClasspathContainer(entry.getPath(), javaProject);
        return container.getClasspathEntries();
      }
    }
  } catch (JavaModelException ex) {
    fail(ex.toString());
    /* NOTREACHED */
  }
  fail("AppEngine Server Runtime classpath container not found");
  return null;
}
 
Example 2
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void convertContainer(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) {
	try {
		IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), project);
		if (container == null) {
			return;
		}

		IClasspathEntry[] entries= container.getClasspathEntries();
		boolean hasChange= false;
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry curr= entries[i];
			IClasspathEntry updatedEntry= getConvertedEntry(curr, project, oldLocationMap);
			if (updatedEntry != null) {
				entries[i]= updatedEntry;
				hasChange= true;
			}
		}
		if (hasChange) {
			BuildPathSupport.requestContainerUpdate(project, container, entries);
		}
	} catch (CoreException e) {
		// ignore
	}
}
 
Example 3
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void updateContainerClasspath(IJavaProject jproject, IPath containerPath, IClasspathEntry newEntry, String[] changedAttributes, IProgressMonitor monitor) throws CoreException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (container == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Container " + containerPath + " cannot be resolved", null));  //$NON-NLS-1$//$NON-NLS-2$
	}
	IClasspathEntry[] entries= container.getClasspathEntries();
	IClasspathEntry[] newEntries= new IClasspathEntry[entries.length];
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		if (curr.getEntryKind() == newEntry.getEntryKind() && curr.getPath().equals(newEntry.getPath())) {
			newEntries[i]= getUpdatedEntry(curr, newEntry, changedAttributes, jproject);
		} else {
			newEntries[i]= curr;
		}
	}
	requestContainerUpdate(jproject, container, newEntries);
	monitor.worked(1);
}
 
Example 4
Source File: CPUserLibraryElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public CPUserLibraryElement(String name, IClasspathContainer container, IJavaProject project) {
	fName= name;
	fChildren= new ArrayList<CPListElement>();
	if (container != null) {
		IClasspathEntry[] entries= container.getClasspathEntries();
		CPListElement[] res= new CPListElement[entries.length];
		for (int i= 0; i < res.length; i++) {
			IClasspathEntry curr= entries[i];
			CPListElement elem= CPListElement.createFromExisting(this, curr, project);
			//elem.setAttribute(CPListElement.SOURCEATTACHMENT, curr.getSourceAttachmentPath());
			//elem.setAttribute(CPListElement.JAVADOC, JavaUI.getLibraryJavadocLocation(curr.getPath()));
			fChildren.add(elem);
		}
		fIsSystemLibrary= container.getKind() == IClasspathContainer.K_SYSTEM;
	} else {
		fIsSystemLibrary= false;
	}
}
 
Example 5
Source File: CPUserLibraryElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean hasChanges(IClasspathContainer oldContainer) {
	if (oldContainer == null || (oldContainer.getKind() == IClasspathContainer.K_SYSTEM) != fIsSystemLibrary) {
		return true;
	}
	IClasspathEntry[] oldEntries= oldContainer.getClasspathEntries();
	if (fChildren.size() != oldEntries.length) {
		return true;
	}
	for (int i= 0; i < oldEntries.length; i++) {
		CPListElement child= fChildren.get(i);
		if (!child.getClasspathEntry().equals(oldEntries[i])) {
			return true;
		}
	}
	return false;
}
 
Example 6
Source File: ImportNativeAppEngineStandardProjectTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static boolean hasAppEngineApi(IProject project) throws JavaModelException {
  IJavaProject javaProject = JavaCore.create(project);
  IClasspathContainer masterContainer =
      JavaCore.getClasspathContainer(BuildPath.MASTER_CONTAINER_PATH, javaProject);

  for (IClasspathEntry entry : masterContainer.getClasspathEntries()) {
    if (entry.getPath().lastSegment().startsWith("appengine-api-1.0-sdk")) {
      return true;
    }
  }
  return false;
}
 
Example 7
Source File: GWTRuntimeContainerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void testGetClasspathEntries() throws JavaModelException {
  IClasspathEntry[] expectedCpEntries = specificRuntime.getClasspathEntries();
  IClasspathContainer specificRuntimeContainer = getClasspathContainer(
      specificRuntime, getTestProject(), SdkClasspathContainer.Type.NAMED);
  IClasspathEntry[] actualCpEntries = specificRuntimeContainer.getClasspathEntries();
  assertEquals(expectedCpEntries.length, actualCpEntries.length);

  for (int i = 0; i < actualCpEntries.length; i++) {
    assertEquals(expectedCpEntries[i].getPath(), actualCpEntries[i].getPath());
  }
}
 
Example 8
Source File: GWTRuntimeContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected SdkClasspathContainer<GwtSdk> updateClasspathContainer(IPath containerPath, GwtSdk sdk, String description,
    IJavaProject project, IClasspathContainer containerSuggestion) {

  // TODO: Persist the changes to the container

  return new GWTRuntimeContainer(containerPath, sdk, containerSuggestion.getClasspathEntries(), description);
}
 
Example 9
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds an entry in a container. <code>null</code> is returned if the entry can not be found
 * @param container The container
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 */
public static IClasspathEntry findEntryInContainer(IClasspathContainer container, IPath libPath) {
	IClasspathEntry[] entries= container.getClasspathEntries();
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		IClasspathEntry resolved= JavaCore.getResolvedClasspathEntry(curr);
		if (resolved != null && libPath.equals(resolved.getPath())) {
			return curr; // return the real entry
		}
	}
	return null; // attachment not possible
}
 
Example 10
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CPListElement(Object parent, IJavaProject project, int entryKind, IPath path, boolean newElement, IResource res, IPath linkTarget) {
	fProject= project;

	fEntryKind= entryKind;
	fPath= path;
	fOrginalPath= newElement ? null : path;
	fLinkTarget= linkTarget;
	fOrginalLinkTarget= linkTarget;
	fChildren= new ArrayList<Object>();
	fResource= res;
	fIsExported= false;

	fIsMissing= false;
	fCachedEntry= null;
	fParentContainer= parent;

	switch (entryKind) {
		case IClasspathEntry.CPE_SOURCE:
			createAttributeElement(OUTPUT, null, true);
			createAttributeElement(INCLUSION, new Path[0], true);
			createAttributeElement(EXCLUSION, new Path[0], true);
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			createAttributeElement(IGNORE_OPTIONAL_PROBLEMS, null, false);
			break;
		case IClasspathEntry.CPE_LIBRARY:
		case IClasspathEntry.CPE_VARIABLE:
			createAttributeElement(SOURCEATTACHMENT, null, true);
			createAttributeElement(JAVADOC, null, false);
			createAttributeElement(SOURCE_ATTACHMENT_ENCODING, null, false);
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			break;
		case IClasspathEntry.CPE_PROJECT:
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			createAttributeElement(COMBINE_ACCESSRULES, Boolean.FALSE, true); // not rendered
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			break;
		case IClasspathEntry.CPE_CONTAINER:
			createAttributeElement(ACCESSRULES, new IAccessRule[0], true);
			try {
				IClasspathContainer container= JavaCore.getClasspathContainer(fPath, fProject);
				if (container != null) {
					IClasspathEntry[] entries= container.getClasspathEntries();
					if (entries != null) { // catch invalid container implementation
						for (int i= 0; i < entries.length; i++) {
							IClasspathEntry entry= entries[i];
							if (entry != null) {
								CPListElement curr= createFromExisting(this, entry, fProject);
								fChildren.add(curr);
							} else {
								JavaPlugin.logErrorMessage("Null entry in container '" + fPath + "'");  //$NON-NLS-1$//$NON-NLS-2$
							}
						}
					} else {
						JavaPlugin.logErrorMessage("container returns null as entries: '" + fPath + "'");  //$NON-NLS-1$//$NON-NLS-2$
					}
				}
			} catch (JavaModelException e) {
			}
			createAttributeElement(NATIVE_LIB_PATH, null, false);
			break;
		default:
	}
}