List of usage examples for org.eclipse.jdt.core IClasspathContainer getKind
int getKind();
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPUserLibraryElement.java
License:Open Source License
public CPUserLibraryElement(String name, IClasspathContainer container, IJavaProject project) { fName = name;/* w w w.ja v a 2 s. co m*/ 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; } }
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPUserLibraryElement.java
License:Open Source License
public boolean hasChanges(IClasspathContainer oldContainer) { if (oldContainer == null || (oldContainer.getKind() == IClasspathContainer.K_SYSTEM) != fIsSystemLibrary) { return true; }//from ww w.ja va2 s . c om 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; }
From source file:com.android.ide.eclipse.adt.internal.build.BuildHelper.java
License:Open Source License
private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, ResourceMarker resMarker) {/*w ww . jav a2 s . c o m*/ // if this is a classpath variable reference, we resolve it. if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject refProject = wsRoot.getProject(entry.getPath().lastSegment()); try { // ignore if it's an Android project, or if it's not a Java Project if (refProject.hasNature(JavaCore.NATURE_ID) && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { IJavaProject refJavaProject = JavaCore.create(refProject); // get the output folder IPath path = refJavaProject.getOutputLocation(); IResource outputResource = wsRoot.findMember(path); if (outputResource != null && outputResource.getType() == IResource.FOLDER) { mCompiledCodePaths.add(outputResource.getLocation().toOSString()); } } } catch (CoreException exception) { // can't query the project nature? ignore } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { handleClasspathLibrary(entry, wsRoot, resMarker); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); // ignore the system and default_system types as they represent // libraries that are part of the runtime. if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { IClasspathEntry[] entries = container.getClasspathEntries(); for (IClasspathEntry cpe : entries) { handleCPE(cpe, javaProject, wsRoot, resMarker); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }
From source file:com.android.ide.eclipse.adt.internal.project.LibraryClasspathContainerInitializer.java
License:Open Source License
/** * Processes a {@link IClasspathEntry} and add it to one of the list if applicable. * @param entry the entry to process// w w w. ja va 2 s . c o m * @param javaProject the {@link IJavaProject} from which this entry came. * @param wsRoot the {@link IWorkspaceRoot} * @param projects the project list to add to * @param jarFiles the jar list to add to * @param includeJarFiles whether to include jar files or just projects. This is useful when * calling on an Android project (value should be <code>false</code>) */ private static void processCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, Set<IProject> projects, Set<File> jarFiles, boolean includeJarFiles) { // if this is a classpath variable reference, we resolve it. if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject refProject = wsRoot.getProject(entry.getPath().lastSegment()); try { // ignore if it's an Android project, or if it's not a Java Project if (refProject.hasNature(JavaCore.NATURE_ID) && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { // add this project to the list projects.add(refProject); // also get the dependency from this project. getDependencyListFromClasspath(refProject, projects, jarFiles, true /*includeJarFiles*/); } } catch (CoreException exception) { // can't query the project nature? ignore } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (includeJarFiles) { handleClasspathLibrary(entry, wsRoot, jarFiles); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container and its content try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); // ignore the system and default_system types as they represent // libraries that are part of the runtime. if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { IClasspathEntry[] entries = container.getClasspathEntries(); for (IClasspathEntry cpe : entries) { processCPE(cpe, javaProject, wsRoot, projects, jarFiles, includeJarFiles); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }
From source file:com.android.ide.eclipse.adt.internal.resources.manager.ProjectClassLoader.java
License:Open Source License
/** * Returns an array of external jar files used by the project. * @return an array of OS-specific absolute file paths *//*from w w w . j ava 2 s . c om*/ private final URL[] getExternalJars() { // get a java project from it IJavaProject javaProject = JavaCore.create(mJavaProject.getProject()); ArrayList<URL> oslibraryList = new ArrayList<URL>(); IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // if this is a classpath variable reference, we resolve it. if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { e = JavaCore.getResolvedClasspathEntry(e); } handleClassPathEntry(e, oslibraryList); } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container. try { IClasspathContainer container = JavaCore.getClasspathContainer(e.getPath(), javaProject); // ignore the system and default_system types as they represent // libraries that are part of the runtime. if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { IClasspathEntry[] entries = container.getClasspathEntries(); for (IClasspathEntry entry : entries) { // TODO: Xav -- is this necessary? if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } handleClassPathEntry(entry, oslibraryList); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", e.getPath()); } } } } return oslibraryList.toArray(new URL[oslibraryList.size()]); }
From source file:com.android.ide.eclipse.auidt.internal.build.BuildHelper.java
License:Open Source License
private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, ResourceMarker resMarker) {//from ww w. j av a2 s .co m // if this is a classpath variable reference, we resolve it. if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject refProject = wsRoot.getProject(entry.getPath().lastSegment()); try { // ignore if it's an Android project, or if it's not a Java Project if (refProject.hasNature(JavaCore.NATURE_ID) && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { IJavaProject refJavaProject = JavaCore.create(refProject); // get the output folder IPath path = refJavaProject.getOutputLocation(); IResource outputResource = wsRoot.findMember(path); if (outputResource != null && outputResource.getType() == IResource.FOLDER) { mCompiledCodePaths.add(outputResource.getLocation().toOSString()); } } } catch (CoreException exception) { // can't query the project nature? ignore } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { handleClasspathLibrary(entry, wsRoot, resMarker); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); // ignore the system and default_system types as they represent // libraries that are part of the runtime. if (container.getKind() == IClasspathContainer.K_APPLICATION) { IClasspathEntry[] entries = container.getClasspathEntries(); for (IClasspathEntry cpe : entries) { handleCPE(cpe, javaProject, wsRoot, resMarker); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add a path to current java search scope or all project fragment roots if null. * Use project resolved classpath to retrieve and store access restriction on each classpath entry. * Recurse if dependent projects are found. * * @param javaProject// w w w .ja v a 2 s. c o m * Project used to get resolved classpath entries * @param pathToAdd * Path to add in case of single element or null if user want to add all project package fragment roots * @param includeMask * Mask to apply on classpath entries * @param projectsToBeAdded * Set to avoid infinite recursion * @param visitedProjects * Set to avoid adding twice the same project * @param referringEntry * Project raw entry in referring project classpath * @throws org.eclipse.jdt.core.JavaModelException * May happen while getting java model info */ void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { // IProject project = javaProject.getProject(); // if (!project.isAccessible() || !visitedProjects.add(project)) return; IPath projectPath = javaProject.getFullPath(); String projectPathString = projectPath.toString(); addEnclosingProjectOrJar(projectPath); IClasspathEntry[] entries = javaProject.getResolvedClasspath(); // IJavaModel model = javaProject.getJavaModel(); // JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; AccessRuleSet access = null; ClasspathEntry cpEntry = (ClasspathEntry) entry; if (referringEntry != null) { // Add only exported entries. // Source folder are implicitly exported. if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry); // cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry); } access = cpEntry.getAccessRuleSet(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IClasspathEntry rawEntry = null; // Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries; // if (rootPathToRawEntries != null) { // rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath()); // } // if (rawEntry == null) break; rawKind: switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: if ((includeMask & APPLICATION_LIBRARIES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { // Object target = JavaModel.getTarget(path, false/*don't check existence*/); // if (target instanceof IFolder) // case of an external folder // path = ((IFolder)target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject); if (container == null) break; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind; break; case IClasspathContainer.K_SYSTEM: case IClasspathContainer.K_DEFAULT_SYSTEM: if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind; break; default: break rawKind; } IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } break; } break; case IClasspathEntry.CPE_PROJECT: // if ((includeMask & REFERENCED_PROJECTS) != 0) { // IPath path = entry.getPath(); // if (pathToAdd == null || pathToAdd.equals(path)) { // JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment()); // if (!projectsToBeAdded // .contains(referencedProject)) { // do not recurse if depending project was used to create the scope // add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry); // } // } // } break; case IClasspathEntry.CPE_SOURCE: if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { add(projectPath.toString(), Util.relativePath(path, 1/*remove project segment*/), projectPathString, false/*not a package*/, access); } } break; } } }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerInitializerTest.java
License:Open Source License
public void testInitialize() throws Exception { // Start with gwt-user.jar and gwt-dev-PLAT.jar on the classpath for this // test// w w w. j av a2s. c o m removeGWTRuntimeFromTestProject(); // Add the default GWT runtime to the test project (this implicitly calls // the GWTRuntimeContainerInitializer.intialize(...) method. IJavaProject project = getTestProject(); GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(project, null, GWTPreferences.getDefaultRuntime(), UpdateType.DEFAULT_CONTAINER, null); command.execute(); JobsUtilities.waitForIdle(); // Verify the bound classpath container IClasspathContainer container = JavaCore.getClasspathContainer(defaultRuntimePath, project); assertEquals(IClasspathContainer.K_APPLICATION, container.getKind()); assertEquals(defaultRuntimePath, container.getPath()); }
From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java
License:Open Source License
@Override protected void resolveClasspathEntry(IJavaProject project, IClasspathEntry entry, ILoader loader, boolean includeSource, boolean cpeFromMainProject) { entry = JavaCore.getResolvedClasspathEntry(entry); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { resolveSourcePathEntry(includeSource ? JavaSourceLoader.SOURCE : Loader.APPLICATION, includeSource, cpeFromMainProject, entry.getPath(), entry.getOutputLocation(), entry.getExclusionPatterns(), "java"); break;//from w ww.ja v a 2 s.co m } case IClasspathEntry.CPE_LIBRARY: { resolveLibraryPathEntry(loader, entry.getPath()); break; } case IClasspathEntry.CPE_PROJECT: { resolveProjectPathEntry(loader, includeSource, entry.getPath()); break; } case IClasspathEntry.CPE_CONTAINER: { try { IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project); IClasspathEntry[] entries = cont.getClasspathEntries(); resolveClasspathEntries(project, Arrays.asList(entries), cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL, includeSource, false); } catch (CoreException e) { System.err.println(e); Assertions.UNREACHABLE(); } } } }
From source file:com.mountainminds.eclemma.core.ScopeUtils.java
License:Open Source License
/** * Remove all JRE runtime entries from the given set * /*from ww w .java 2s .c o m*/ * @param scope * set to filter * @return filtered set without JRE runtime entries */ public static Set<IPackageFragmentRoot> filterJREEntries(Collection<IPackageFragmentRoot> scope) throws JavaModelException { final Set<IPackageFragmentRoot> filtered = new HashSet<IPackageFragmentRoot>(); for (final IPackageFragmentRoot root : scope) { final IClasspathEntry entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: filtered.add(root); break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject()); if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { filtered.add(root); } break; } } return filtered; }