Java Code Examples for org.eclipse.jdt.core.IClasspathEntry

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry. These examples are extracted from open source projects. 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 Project: sarl   Source File: JavaClasspathParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *
 * @param kindStr
 *            - string to test
 * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc.
 */
@SuppressWarnings("checkstyle:equalsavoidnull")
private static int kindFromString(String kindStr) {

    if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_PROJECT;
    }
    if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_VARIABLE;
    }
    if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_CONTAINER;
    }
    if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_SOURCE;
    }
    if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_LIBRARY;
    }
    if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$
        return ClasspathEntry.K_OUTPUT;
    }
    return -1;
}
 
Example 2
private void detectLibraries(ArrayList<IClasspathEntry> cpEntries, IPath outputLocation) {
	ArrayList<IClasspathEntry> res= new ArrayList<IClasspathEntry>();
	Set<IPath> sourceFolderSet= fSourceFolders.keySet();
	for (Iterator<IPath> iter= fJARFiles.iterator(); iter.hasNext();) {
		IPath path= iter.next();
		if (isNested(path, sourceFolderSet.iterator())) {
			continue;
		}
		if (outputLocation != null && outputLocation.isPrefixOf(path)) {
			continue;
		}
		IClasspathEntry entry= JavaCore.newLibraryEntry(path, null, null);
		res.add(entry);
	}
	Collections.sort(res, new CPSorter());
	cpEntries.addAll(res);
}
 
Example 3
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example 4
Source Project: hybris-commerce-eclipse-plugin   Source File: Importer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sometimes the project configuration is corrupt and a Java runtime is not on the classpath
 * @param monitor
 * @param javaProject
 * @throws JavaModelException
 */
private void fixMissingJavaRuntime(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException {
	
	if (!javaProject.getProject().getName().equals("config")) {
		IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
		boolean found = false;
		for (IClasspathEntry classpathEntry : classPathEntries) {
			// fix missing runtime
			if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				if (classpathEntry.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
					found = true;
					break;
				}
			}
		}
		
		if (!found) {
			IClasspathEntry entry = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"),
					false);
			Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(classPathEntries));
			entries.add(entry);
			FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject,
					monitor);
		}
	}
}
 
Example 5
Source Project: sarl   Source File: FixedFatJarExportPage.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example 6
public static void addToClassPath(IResource res, int type, IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException
{
	Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(javaProject.getRawClasspath()));
	IClasspathEntry entry = null;
	switch (type) {
	case IClasspathEntry.CPE_SOURCE: 
		entry = JavaCore.newSourceEntry(res.getFullPath());
		break;
	case IClasspathEntry.CPE_LIBRARY: 
		entry = JavaCore.newLibraryEntry(res.getFullPath(), null, null, true);
		break;
	case IClasspathEntry.CPE_PROJECT: 
		entry = JavaCore.newProjectEntry(res.getFullPath(), true);
		break;
	}
		
	entries.add(entry);
	setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);
}
 
Example 7
@Test
public void testCached_noResolver() {
  IRuntime runtime = mock(IRuntime.class);
  IClasspathEntry[] entries = new IClasspathEntry[0];

  AtomicReference<IClasspathEntry[]> requestedUpdate = new AtomicReference<>(null);
  fixture =
      new ServletClasspathProvider(resolver) {
        @Override
        protected void requestClasspathContainerUpdate(
            IProject project, IRuntime runtime, IClasspathEntry[] entries) {
          requestedUpdate.set(entries);
        }
      };
  fixture.libraryEntries.put(WebFacetUtils.WEB_31, entries);

  IClasspathEntry[] result =
      fixture.resolveClasspathContainer(projectCreator.getProject(), runtime);
  assertSame(entries, result);
  assertNull(requestedUpdate.get());
  verifyNoMoreInteractions(resolver);
}
 
Example 8
private static IRunnableWithProgress getRunnable(final Shell shell, final IJavaElement elem, final URL javadocLocation, final IClasspathEntry entry, final IPath containerPath) {
	return new IRunnableWithProgress() {
		public void run(IProgressMonitor monitor) throws InvocationTargetException {
			try {
				IJavaProject project= elem.getJavaProject();
				if (elem instanceof IPackageFragmentRoot) {
					CPListElement cpElem= CPListElement.createFromExisting(entry, project);
					String loc= javadocLocation != null ? javadocLocation.toExternalForm() : null;
					cpElem.setAttribute(CPListElement.JAVADOC, loc);
					IClasspathEntry newEntry= cpElem.getClasspathEntry();
					String[] changedAttributes= { CPListElement.JAVADOC };
					BuildPathSupport.modifyClasspathEntry(shell, newEntry, changedAttributes, project, containerPath, entry.getReferencingEntry() != null, monitor);
				} else {
					JavaUI.setProjectJavadocLocation(project, javadocLocation);
				}
			} catch (CoreException e) {
				throw new InvocationTargetException(e);
			}
		}
	};
}
 
Example 9
/**
 * @see IJavaProject
 */
public IPath readOutputLocation() {
	// Read classpath file without creating markers nor logging problems
	IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
	if (classpath[0] == JavaProject.INVALID_CLASSPATH)
		return defaultOutputLocation();

	// extract the output location
	IPath outputLocation = null;
	if (classpath[0].length > 0) {
		IClasspathEntry entry = classpath[0][classpath[0].length - 1];
		if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
			outputLocation = entry.getPath();
		}
	}
	return outputLocation;
}
 
Example 10
private CPListElement[] addProjectDialog() {

		try {
			Object[] selectArr= getNotYetRequiredProjects();
			new JavaElementComparator().sort(null, selectArr);

			ListSelectionDialog dialog= new ListSelectionDialog(getShell(), Arrays.asList(selectArr), new ArrayContentProvider(), new JavaUILabelProvider(), NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message);
			dialog.setTitle(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_title);
			dialog.setHelpAvailable(false);
			if (dialog.open() == Window.OK) {
				Object[] result= dialog.getResult();
				CPListElement[] cpElements= new CPListElement[result.length];
				for (int i= 0; i < result.length; i++) {
					IJavaProject curr= (IJavaProject) result[i];
					cpElements[i]= new CPListElement(fCurrJProject, IClasspathEntry.CPE_PROJECT, curr.getPath(), curr.getResource());
				}
				return cpElements;
			}
		} catch (JavaModelException e) {
			return null;
		}
		return null;
	}
 
Example 11
@Test
public void testPreventMultipleContainers() {
  IClasspathEntry existingEntry = mock(IClasspathEntry.class);
  when(existingEntry.getEntryKind()).thenReturn(IClasspathEntry.CPE_CONTAINER);
  when(existingEntry.getPath()).thenReturn(MASTER_CONTAINER_PATH);
  assertTrue(LibraryClasspathContainer.isEntry(existingEntry));

  // explicitly configure App Engine and GCP libraries
  IJavaProject javaProject = plainJavaProjectCreator.getJavaProject();

  page.initialize(javaProject, new IClasspathEntry[] {existingEntry});
  page.setSelection(null);
  page.createControl(shellTestResource.getShell());

  assertTrue(page.finish()); // should be ok
  assertNull(page.getSelection()); // no new container created
}
 
Example 12
/**
 * Creates and adds a class folder to the class path.
 *
 * @param jproject
 *            The parent project
 * @param containerName
 * @param sourceAttachPath
 *            The source attachment path
 * @param sourceAttachRoot
 *            The source attachment root path
 * @return The handle of the created root
 * @throws CoreException
 */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath,
        IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
 
Example 13
protected void setProjectClasspath(IJavaProject javaProject, IFolder srcFolder, IProgressMonitor monitor)
    throws JavaModelException {
  List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
  classpathEntries.add(JavaCore.newSourceEntry(srcFolder.getFullPath()));

  // Add the "test" folder as a src path, if it exists
  IProject project = javaProject.getProject();
  IFolder testFolder = project.getFolder("test");
  if (testFolder.exists()) {
    classpathEntries.add(JavaCore.newSourceEntry(testFolder.getFullPath(), new IPath[0],
        project.getFullPath().append("test-classes")));
  }

  // Add our container entries to the path
  for (IPath containerPath : containerPaths) {
    classpathEntries.add(JavaCore.newContainerEntry(containerPath));
  }

  classpathEntries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));

  javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor);
}
 
Example 14
private boolean hasChange(IJavaProject project) throws JavaModelException {
	if (!project.getOutputLocation().equals(fOutputLocation))
           return true;

	IClasspathEntry[] currentEntries= project.getRawClasspath();
       if (currentEntries.length != fEntries.size())
           return true;

       int i= 0;
       for (Iterator<CPListElement> iterator= fEntries.iterator(); iterator.hasNext();) {
        CPListElement oldEntrie= iterator.next();
        if (!oldEntrie.getClasspathEntry().equals(currentEntries[i]))
        	return true;
        i++;
       }
       return false;
}
 
Example 15
Source Project: google-cloud-eclipse   Source File: SourceAttacherJob.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
LibraryClasspathContainer attachSource(IClasspathContainer container) throws Exception {
  if (!(container instanceof LibraryClasspathContainer)) {
    logger.log(Level.FINE, Messages.getString("ContainerClassUnexpected",
        container.getClass().getName(), LibraryClasspathContainer.class.getName()));
    return null;
  }

  LibraryClasspathContainer libraryClasspathContainer = (LibraryClasspathContainer) container;
  IPath sourceArtifactPath = sourceArtifactPathProvider.call();
  List<IClasspathEntry> newClasspathEntries = new ArrayList<>();

  for (IClasspathEntry entry : libraryClasspathContainer.getClasspathEntries()) {
    if (!entry.getPath().equals(libraryPath)) {
      newClasspathEntries.add(entry);
    } else {
      newClasspathEntries.add(JavaCore.newLibraryEntry(
          entry.getPath(), sourceArtifactPath, null /* sourceAttachmentRootPath */,
          entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()));
    }
  }

  return libraryClasspathContainer.copyWithNewEntries(newClasspathEntries);
}
 
Example 16
Source Project: eclipse.jdt.ls   Source File: ClasspathChange.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public ClasspathChange(IJavaProject project, IClasspathEntry[] newClasspath, IPath outputLocation) {
	fProject= project;
	fNewClasspath= newClasspath;
	fOutputLocation= outputLocation;

	setValidationMethod(VALIDATE_NOT_DIRTY | VALIDATE_NOT_READ_ONLY);
}
 
Example 17
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException {
	final IJavaProject project= root.getJavaProject();
	if (!project.exists()) {
		//				createJavaProject(project.getProject());
	}
	final IFolder folder= project.getProject().getFolder(root.getElementName());
	if (!folder.exists()) {
		ResourceUtil.createFolder(folder, true, true, new NullProgressMonitor());
	}
	final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath());
	list.add(JavaCore.newSourceEntry(folder.getFullPath()));
	project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor());
}
 
Example 18
private int getPageIndex(int entryKind) {
	switch (entryKind) {
		case IClasspathEntry.CPE_CONTAINER:
		case IClasspathEntry.CPE_LIBRARY:
		case IClasspathEntry.CPE_VARIABLE:
			return 2;
		case IClasspathEntry.CPE_PROJECT:
			return 1;
		case IClasspathEntry.CPE_SOURCE:
			return 0;
	}
	return 0;
}
 
Example 19
private static IClasspathEntry getConvertedEntry(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) {
	IPath path= null;
	switch (entry.getEntryKind()) {
		case IClasspathEntry.CPE_SOURCE:
		case IClasspathEntry.CPE_PROJECT:
			return null;
		case IClasspathEntry.CPE_CONTAINER:
			convertContainer(entry, project, oldLocationMap);
			return null;
		case IClasspathEntry.CPE_LIBRARY:
			path= entry.getPath();
			break;
		case IClasspathEntry.CPE_VARIABLE:
			path= JavaCore.getResolvedVariablePath(entry.getPath());
			break;
		default:
			return null;
	}
	if (path == null) {
		return null;
	}
	IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
	for (int i= 0; i < extraAttributes.length; i++) {
		if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(extraAttributes[i].getName())) {
			return null;
		}
	}
	String libraryJavadocLocation= oldLocationMap.get(path);
	if (libraryJavadocLocation != null) {
		CPListElement element= CPListElement.createFromExisting(entry, project);
		element.setAttribute(CPListElement.JAVADOC, libraryJavadocLocation);
		return element.getClasspathEntry();
	}
	return null;
}
 
Example 20
Source Project: gwt-eclipse-plugin   Source File: GWTRuntimeTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
 * gwt-user project. Note this test uses gwt-dev instead of gwt-dev-${PLAT} as
 * the dev project name.
 */
public void testFindSdkFor_GwtDevProject() throws Exception {
  GwtRuntimeTestUtilities.importGwtSourceProjects();
  try {
    IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
    IJavaProject javaProject = javaModel.getJavaProject("gwt-dev");
    GwtSdk sdk = GwtSdk.findSdkFor(javaProject);
    IClasspathEntry[] entries = sdk.getClasspathEntries();
    assertEquals(new IClasspathEntry[] {JavaCore.newSourceEntry(javaModel.getJavaProject(
        "gwt-dev").getPath().append("core/src"))}, entries);
  } finally {
    GwtRuntimeTestUtilities.removeGwtSourceProjects();
  }
}
 
Example 21
public void addElement(IClasspathEntry entry) {
	int pageIndex= getPageIndex(entry.getEntryKind());
	if (fTabFolder == null) {
		fPageIndex= pageIndex;
	} else {
		fTabFolder.setSelection(pageIndex);

		Object page=  fTabFolder.getItem(pageIndex).getData();
		if (page instanceof LibrariesWorkbookPage) {
			CPListElement element= CPListElement.create(entry, true, fCurrJProject);
			((LibrariesWorkbookPage) page).addElement(element);
		}
	}
}
 
Example 22
/**
 * For a given path, find the corresponding element in the list.
 *
 * @param path the path to found an entry for
 * @param elements a list of <code>CPListElement</code>s
 * @return the matched <code>CPListElement</code> or <code>null</code> if
 * no match could be found
 */
public static CPListElement getListElement(IPath path, List<CPListElement> elements) {
	for (int i= 0; i < elements.size(); i++) {
		CPListElement element= elements.get(i);
		if (element.getEntryKind() == IClasspathEntry.CPE_SOURCE && element.getPath().equals(path)) {
			return element;
		}
	}
	return null;
}
 
Example 23
@Test
public void should_create_set_raw_classpath_to_project_with_default_entries_if_classpath_doesnt_exists() throws Exception {
    doReturn(false).when(bonitaBPMProjectClasspath).classpathExists(repository);

    bonitaBPMProjectClasspath.create(repository, monitor);

    verify(javaProject).setRawClasspath(notNull(IClasspathEntry[].class), eq(true), eq(monitor));
}
 
Example 24
Source Project: Pydev   Source File: JavaZipModule.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the classpath entries used in this class
 */
private static synchronized IClasspathEntry[] getClasspathEntries(String path) {
    IClasspathEntry[] entry = classpathEntries.get(path);
    if (entry == null) {
        entry = new IClasspathEntry[] { JavaCore.newLibraryEntry(Path.fromOSString(path), null, null, true) };
        classpathEntries.put(path, entry);
    }
    return entry;
}
 
Example 25
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}
 
Example 26
Source Project: google-cloud-eclipse   Source File: ClasspathUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addClasspathEntries(IProject project, List<IClasspathEntry> toAdd,
    IProgressMonitor monitor) throws JavaModelException {
  IJavaProject javaProject = JavaCore.create(project);
  List<IClasspathEntry> entries = Lists.newArrayList(javaProject.getRawClasspath());
  entries.addAll(toAdd);
  javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), monitor);
}
 
Example 27
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 28
private static String getDefaultJRELibraries() {
	StringBuffer buf= new StringBuffer();
	IClasspathEntry cntentry= getJREContainerEntry();
	buf.append(encodeJRELibrary(PreferencesMessages.NewJavaProjectPreferencePage_jre_container_description, new IClasspathEntry[] { cntentry} ));
	buf.append(';');
	IClasspathEntry varentry= getJREVariableEntry();
	buf.append(encodeJRELibrary(PreferencesMessages.NewJavaProjectPreferencePage_jre_variable_description, new IClasspathEntry[] { varentry }));
	buf.append(';');
	return buf.toString();
}
 
Example 29
/**
 * Finds all the classpath containers in the specified project that match the
 * provided container ID.
 *
 * @param javaProject the project to query
 * @param containerId The container ID we are trying to match.
 * @return an array of matching classpath containers.
 */
public static IClasspathEntry[] findClasspathContainersWithContainerId(
    IJavaProject javaProject, final String containerId)
    throws JavaModelException {

  Predicate<IClasspathEntry> matchPredicate = new Predicate<IClasspathEntry>() {
    @Override
    public boolean apply(IClasspathEntry entry) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        IPath containerPath = entry.getPath();
        if (containerPath.segmentCount() > 0
            && containerPath.segment(0).equals(containerId)) {
          return true;
        }
      }
      return false;
    }
  };

  IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
  int matchCount = 0;

  for (int i = 0; i < classpathEntries.length; i++) {
    if (matchPredicate.apply(classpathEntries[i])) {
      matchCount++;
    }
  }

  IClasspathEntry[] matchingClasspathEntries = new IClasspathEntry[matchCount];
  int matchingClasspathEntriesIdx = 0;
  for (int i = 0; i < classpathEntries.length; i++) {
    if (matchPredicate.apply(classpathEntries[i])) {
      matchingClasspathEntries[matchingClasspathEntriesIdx] = classpathEntries[i];
      matchingClasspathEntriesIdx++;
    }
  }

  return matchingClasspathEntries;
}
 
Example 30
public ClassPathContainer(IJavaProject parent, IClasspathEntry entry) {
	super(parent);
	fClassPathEntry= entry;
	try {
		fContainer= JavaCore.getClasspathContainer(entry.getPath(), parent);
	} catch (JavaModelException e) {
		fContainer= null;
	}
}