List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:org.eclipse.e4.xwt.ui.utils.LibraryBuilder.java
License:Open Source License
private void updateJavaClasspathLibs(String[] oldPaths, String[] newPaths) { IJavaProject jproject = JavaCore.create(project); try {/* w ww. j a v a 2s . c o m*/ IClasspathEntry[] entries = jproject.getRawClasspath(); ArrayList toBeAdded = new ArrayList(); int index = -1; entryLoop: for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (index == -1) index = i; // do not add the old paths (handling deletion/renaming) IPath path = entries[i].getPath().removeFirstSegments(1).removeTrailingSeparator(); for (int j = 0; j < oldPaths.length; j++) if (oldPaths[j] != null && path.equals(new Path(oldPaths[j]).removeTrailingSeparator())) continue entryLoop; } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) if (index == -1) index = i; toBeAdded.add(entries[i]); } if (index == -1) index = entries.length; // add paths for (int i = 0; i < newPaths.length; i++) { if (newPaths[i] == null) continue; IClasspathEntry entry = JavaCore.newLibraryEntry(project.getFullPath().append(newPaths[i]), null, null, true); if (!toBeAdded.contains(entry)) toBeAdded.add(index++, entry); } if (toBeAdded.size() == entries.length) return; IClasspathEntry[] updated = (IClasspathEntry[]) toBeAdded .toArray(new IClasspathEntry[toBeAdded.size()]); jproject.setRawClasspath(updated, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.edt.debug.core.java.filters.ClasspathEntryFilter.java
License:Open Source License
protected void processEntries(IClasspathEntry[] entries, IJavaProject project, Map<String, Object> classMap) throws CoreException { for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: processLibraryEntry(entry, classMap); break; case IClasspathEntry.CPE_CONTAINER: processContainerEntry(entry, project, classMap); break; case IClasspathEntry.CPE_SOURCE: processSourceEntry(entry, classMap); break; case IClasspathEntry.CPE_PROJECT: IProject depProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().lastSegment()); if (depProject.isAccessible() && depProject.hasNature(JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(depProject); processEntries(jp.getResolvedClasspath(true), jp, classMap); }//from www .j a va 2 s. c o m break; default: EDTDebugCorePlugin.log(new Status(IStatus.WARNING, EDTDebugCorePlugin.PLUGIN_ID, NLS.bind(EDTDebugCoreMessages.TypeFilterClasspathEntryNotSupported, new Object[] { entry.getEntryKind(), getId() }))); break; } } }
From source file:org.eclipse.edt.debug.core.java.filters.WorkspaceProjectClassFilter.java
License:Open Source License
@Override protected IClasspathEntry[] getCommonClasspathEntries() { String[] projects = getProjectNames(); if (projects != null && projects.length > 0) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); for (String project : projects) { IProject proj = root.getProject(project); try { if (proj.isAccessible() && proj.hasNature(JavaCore.NATURE_ID)) { for (IClasspathEntry entry : JavaCore.create(proj).getResolvedClasspath(true)) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (includeLibraries()) { list.add(entry); }//from w w w . j a v a 2 s . c o m break; case IClasspathEntry.CPE_PROJECT: if (includeReferencedProjects()) { list.add(entry); } break; case IClasspathEntry.CPE_CONTAINER: if (includeContainers()) { list.add(entry); } break; case IClasspathEntry.CPE_SOURCE: if (includeSource()) { list.add(entry); } break; } } } } catch (CoreException ce) { EDTDebugCorePlugin.log(ce); } } return list.toArray(new IClasspathEntry[list.size()]); } return null; }
From source file:org.eclipse.edt.ide.core.utils.EclipseUtilities.java
License:Open Source License
/** * Adds the runtime containers to the project if necessary. This does nothing if the project is * not a Java project./* ww w. j av a2 s. com*/ * * @param project The Java project. * @param generator The generator provider. * @param ctx The generation context. */ public static void addRuntimesToProject(IProject project, IGenerator generator, EglContext ctx) { EDTRuntimeContainer[] baseRuntimes = generator instanceof AbstractGenerator ? ((AbstractGenerator) generator).resolveBaseRuntimeContainers() : null; EDTRuntimeContainer[] containersToAdd; Set<String> requiredContainers = ctx.getRequiredRuntimeContainers(); if (requiredContainers.size() == 0) { if (baseRuntimes == null || baseRuntimes.length == 0) { return; } containersToAdd = baseRuntimes; } else { Set<EDTRuntimeContainer> containers = new HashSet<EDTRuntimeContainer>(10); if (baseRuntimes != null && baseRuntimes.length > 0) { containers.addAll(Arrays.asList(baseRuntimes)); } for (EDTRuntimeContainer container : generator.getRuntimeContainers()) { if (requiredContainers.contains(container.getId())) { containers.add(container); } } containersToAdd = containers.toArray(new EDTRuntimeContainer[containers.size()]); } if (containersToAdd == null || containersToAdd.length == 0) { return; } try { if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); List<IClasspathEntry> additions = new ArrayList<IClasspathEntry>(); for (int i = 0; i < containersToAdd.length; i++) { IPath path = containersToAdd[i].getPath(); boolean found = false; for (int j = 0; j < classpath.length; j++) { if (classpath[j].getEntryKind() == IClasspathEntry.CPE_CONTAINER && classpath[j].getPath().equals(path)) { found = true; break; } } if (!found) { additions.add(JavaCore.newContainerEntry(path)); } } if (additions.size() > 0) { IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + additions.size()]; System.arraycopy(classpath, 0, newEntries, 0, classpath.length); for (int i = 0; i < additions.size(); i++) { newEntries[classpath.length + i] = additions.get(i); } javaProject.setRawClasspath(newEntries, null); } } } catch (CoreException e) { EDTCoreIDEPlugin.log(e); } }
From source file:org.eclipse.edt.ide.deployment.rui.operation.CopyJavaRuntimeResourcesOperation.java
License:Open Source License
/** * Finds all the classpath entries on the Java build path, including referenced projects, that are of type {@link IClasspathEntry#CPE_CONTAINER}. * @throws CoreException/*from ww w . ja va 2s .c om*/ */ private void getClasspathContainers(IJavaProject project, Set<IJavaProject> seen, Set<IClasspathEntry> entries) throws CoreException { if (seen.contains(project)) { return; } seen.add(project); for (IClasspathEntry entry : project.getRawClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: entries.add(entry); break; case IClasspathEntry.CPE_PROJECT: IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); if (p.isAccessible() && p.hasNature(JavaCore.NATURE_ID)) { getClasspathContainers(JavaCore.create(p), seen, entries); } break; } } }
From source file:org.eclipse.emf.ecore.xcore.ui.XcoreJavaProjectProvider.java
License:Open Source License
public ClassLoader getClassLoader(ResourceSet resourceSet) { IJavaProject project = getJavaProject(resourceSet); if (project != null) { IProject iProject = project.getProject(); IWorkspaceRoot workspaceRoot = iProject.getWorkspace().getRoot(); List<URL> libraryURLs = new UniqueEList<URL>(); try {/* w ww . ja v a 2 s. c o m*/ getAllReferencedProjects(libraryURLs, new IProject[] { iProject }); IClasspathEntry[] classpath = project.getResolvedClasspath(true); if (classpath != null) { String projectName = iProject.getName(); for (int i = 0; i < classpath.length; ++i) { IClasspathEntry classpathEntry = classpath[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: { IPath path = classpathEntry.getPath(); if (path.segment(0).equals(projectName)) { path = iProject.getLocation().append(path.removeFirstSegments(1)); } libraryURLs.add(new URL(URI.createFileURI(path.toString()).toString())); break; } case IClasspathEntry.CPE_PROJECT: { IPath path = classpathEntry.getPath(); IProject referencedProject = workspaceRoot.getProject(path.segment(0)); IJavaProject referencedJavaProject = JavaCore.create(referencedProject); IContainer container = workspaceRoot .getFolder(referencedJavaProject.getOutputLocation()); libraryURLs.add(new URL( URI.createFileURI(container.getLocation().toString() + "/").toString())); IProjectDescription description = referencedProject.getDescription(); getAllReferencedProjects(libraryURLs, description.getReferencedProjects()); getAllReferencedProjects(libraryURLs, description.getDynamicReferences()); break; } case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_VARIABLE: default: { break; } } } } return new URLClassLoader(libraryURLs.toArray(new URL[libraryURLs.size()]), getClass().getClassLoader()); } catch (MalformedURLException exception) { exception.printStackTrace(); } catch (JavaModelException exception) { exception.printStackTrace(); } catch (CoreException exception) { exception.printStackTrace(); } } for (Resource resource : resourceSet.getResources()) { URI uri = resource.getURI(); if (uri.isPlatformPlugin()) { final Bundle bundle = Platform.getBundle(uri.segments()[1]); return new ClassLoader() { @Override public Enumeration<URL> findResources(String name) throws IOException { return bundle.getResources(name); } @Override public URL findResource(String name) { return bundle.getResource(name); } @Override public URL getResource(String name) { return findResource(name); } @Override public Class<?> findClass(String name) throws ClassNotFoundException { return bundle.loadClass(name); } @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz = findClass(name); if (resolve) { resolveClass(clazz); } return clazz; } }; } } return null; }
From source file:org.eclipse.emf.java.presentation.JavaEditor.java
License:Open Source License
public void setupClassLoader(IProject project) { JavaPackageResourceImpl javaPackageResource = (JavaPackageResourceImpl) editingDomain .loadResource(JavaUtil.JAVA_PACKAGE_RESOURCE); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); List<URL> libraryURLs = new UniqueEList<URL>(); List<String> sourceURIs = new ArrayList<String>(); try {/*from w ww .j av a2s .c om*/ IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); if (classpath != null) { for (int i = 0; i < classpath.length; ++i) { IClasspathEntry classpathEntry = classpath[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: { libraryURLs.add(new URL(URI.createFileURI(classpathEntry.getPath().toString()).toString())); break; } case IClasspathEntry.CPE_SOURCE: { sourceURIs.add( URI.createPlatformResourceURI(classpathEntry.getPath().toString(), true) + "/"); break; } case IClasspathEntry.CPE_PROJECT: { IProject referencedProject = workspaceRoot.getProject(classpathEntry.getPath().segment(0)); IJavaProject referencedJavaProject = JavaCore.create(referencedProject); IContainer container = workspaceRoot.getFolder(referencedJavaProject.getOutputLocation()); libraryURLs.add( new URL(URI.createFileURI(container.getLocation().toString() + "/").toString())); getAllReferencedProjects(libraryURLs, referencedProject.getDescription().getReferencedProjects()); getAllReferencedProjects(libraryURLs, referencedProject.getDescription().getDynamicReferences()); break; } case IClasspathEntry.CPE_VARIABLE: default: { break; } } } } javaPackageResource.setClassLoader(new URLClassLoader(libraryURLs.toArray(new URL[libraryURLs.size()]), new URLClassLoader(new URL[0], null))); javaPackageResource.getSourceURIs().addAll(sourceURIs); } catch (MalformedURLException exception) { exception.printStackTrace(); } catch (JavaModelException exception) { exception.printStackTrace(); } catch (CoreException exception) { exception.printStackTrace(); } }
From source file:org.eclipse.fx.ide.ui.preview.LivePreviewSynchronizer.java
License:Open Source License
private void resolveDataProject(IJavaProject project, Set<IPath> outputPath, Set<IPath> listRefLibraries) { // System.err.println("START RESOLVE: " + project.getElementName()); try {/*from w w w. ja v a2s . c o m*/ IClasspathEntry[] entries = project.getRawClasspath(); outputPath.add(project.getOutputLocation()); for (IClasspathEntry e : entries) { // System.err.println(e + " ====> " + e.getEntryKind()); if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // System.err.println("CPE_LIBRARY PUSHING: " + e.getPath()); listRefLibraries.add(e.getPath()); } else if ("org.eclipse.pde.core.requiredPlugins".equals(e.getPath().toString())) { IClasspathContainer cpContainer = JavaCore.getClasspathContainer(e.getPath(), project); for (IClasspathEntry cpEntry : cpContainer.getClasspathEntries()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot() .getProject(cpEntry.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // System.err.println("requiredPlugins & CPE_LIBRARY PUSHING: " + e.getPath()); listRefLibraries.add(cpEntry.getPath()); } } } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (!e.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER") && !e.getPath().toString().startsWith("org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER")) { // System.err.println("====> A container"); IClasspathContainer cp = JavaCore.getClasspathContainer(e.getPath(), project); for (IClasspathEntry ce : cp.getClasspathEntries()) { // System.err.println(ce.getEntryKind() + "=> " + ce); if (ce.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(ce.getPath()); } else if (ce.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot() .getProject(ce.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.err.println("END RESOLVE"); }
From source file:org.eclipse.imp.java.hosted.ProjectUtils.java
License:Open Source License
public void addExtenderForJavaHostedProjects(Language lang) { ModelFactory.getInstance().installExtender(new IFactoryExtender() { public void extend(ISourceProject project) { initializeBuildPathFromJavaProject(project); }/*from ww w . j a va 2 s . com*/ public void extend(ICompilationUnit unit) { } /** * Read the IJavaProject classpath configuration and populate the ISourceProject's * build path accordingly. */ public void initializeBuildPathFromJavaProject(ISourceProject project) { IJavaProject javaProject = JavaCore.create(project.getRawProject()); if (javaProject.exists()) { try { IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true); List<IPathEntry> buildPath = new ArrayList<IPathEntry>(cpEntries.length); for (int i = 0; i < cpEntries.length; i++) { IClasspathEntry entry = cpEntries[i]; IPathEntry.PathEntryType type; IPath path = entry.getPath(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: type = PathEntryType.CONTAINER; break; case IClasspathEntry.CPE_LIBRARY: type = PathEntryType.ARCHIVE; break; case IClasspathEntry.CPE_PROJECT: type = PathEntryType.PROJECT; break; case IClasspathEntry.CPE_SOURCE: type = PathEntryType.SOURCE_FOLDER; break; default: // case IClasspathEntry.CPE_VARIABLE: throw new IllegalArgumentException("Encountered variable class-path entry: " + entry.getPath().toPortableString()); } IPathEntry pathEntry = ModelFactory.createPathEntry(type, path); buildPath.add(pathEntry); } project.setBuildPath(buildPath); } catch (JavaModelException e) { ErrorHandler.reportError(e.getMessage(), e); } } } }, lang); }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
private IClasspathContainer initializeAllContainers(IJavaProject javaProjectToInit, IPath containerToInit) throws JavaModelException { if (CP_RESOLVE_VERBOSE_ADVANCED) verbose_batching_containers_initialization(javaProjectToInit, containerToInit); // collect all container paths final HashMap allContainerPaths = new HashMap(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0, length = projects.length; i < length; i++) { IProject project = projects[i];/* w ww .java 2 s . c om*/ if (!JavaProject.hasJavaNature(project)) continue; IJavaProject javaProject = new JavaProject(project, getJavaModel()); HashSet paths = (HashSet) allContainerPaths.get(javaProject); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (int j = 0, length2 = rawClasspath.length; j < length2; j++) { IClasspathEntry entry = rawClasspath[j]; IPath path = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && containerGet(javaProject, path) == null) { if (paths == null) { paths = new HashSet(); allContainerPaths.put(javaProject, paths); } paths.add(path); } } /* TODO (frederic) put back when JDT/UI dummy project will be thrown away... * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97524 * if (javaProject.equals(javaProjectToInit)) { if (paths == null) { paths = new HashSet(); allContainerPaths.put(javaProject, paths); } paths.add(containerToInit); } */ } // TODO (frederic) remove following block when JDT/UI dummy project will be thrown away... if (javaProjectToInit != null) { HashSet containerPaths = (HashSet) allContainerPaths.get(javaProjectToInit); if (containerPaths == null) { containerPaths = new HashSet(); allContainerPaths.put(javaProjectToInit, containerPaths); } containerPaths.add(containerToInit); } // end block // initialize all containers boolean ok = false; try { // if possible run inside an IWokspaceRunnable with AVOID_UPATE to avoid unwanted builds // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118507) IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { try { // Collect all containers Set entrySet = allContainerPaths.entrySet(); int length = entrySet.size(); if (monitor != null) monitor.beginTask("", length); //$NON-NLS-1$ Map.Entry[] entries = new Map.Entry[length]; // clone as the following will have a side effect entrySet.toArray(entries); for (int i = 0; i < length; i++) { Map.Entry entry = entries[i]; IJavaProject javaProject = (IJavaProject) entry.getKey(); HashSet pathSet = (HashSet) entry.getValue(); if (pathSet == null) continue; int length2 = pathSet.size(); IPath[] paths = new IPath[length2]; pathSet.toArray(paths); // clone as the following will have a side effect for (int j = 0; j < length2; j++) { IPath path = paths[j]; initializeContainer(javaProject, path); IClasspathContainer container = containerBeingInitializedGet(javaProject, path); if (container != null) { containerPut(javaProject, path, container); } } if (monitor != null) monitor.worked(1); } // Set all containers Map perProjectContainers = (Map) JavaModelManager.this.containersBeingInitialized.get(); if (perProjectContainers != null) { Iterator entriesIterator = perProjectContainers.entrySet().iterator(); while (entriesIterator.hasNext()) { Map.Entry entry = (Map.Entry) entriesIterator.next(); IJavaProject project = (IJavaProject) entry.getKey(); HashMap perPathContainers = (HashMap) entry.getValue(); Iterator containersIterator = perPathContainers.entrySet().iterator(); while (containersIterator.hasNext()) { Map.Entry containerEntry = (Map.Entry) containersIterator.next(); IPath containerPath = (IPath) containerEntry.getKey(); IClasspathContainer container = (IClasspathContainer) containerEntry.getValue(); SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }); operation.runOperation(monitor); } } JavaModelManager.this.containersBeingInitialized.set(null); } } finally { if (monitor != null) monitor.done(); } } }; IProgressMonitor monitor = this.batchContainerInitializationsProgress; IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace.isTreeLocked()) runnable.run(monitor); else workspace.run(runnable, null/*don't take any lock*/, IWorkspace.AVOID_UPDATE, monitor); ok = true; } catch (CoreException e) { // ignore Util.log(e, "Exception while initializing all containers"); //$NON-NLS-1$ } finally { if (!ok) { // if we're being traversed by an exception, ensure that that containers are // no longer marked as initialization in progress // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=66437) this.containerInitializationInProgress.set(null); } } return containerGet(javaProjectToInit, containerToInit); }