List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
From source file:org.maven.ide.eclipse.tests.BuildPathManagerTest.java
License:Apache License
public void testEnableMavenNature() throws Exception { deleteProject("MNGECLIPSE-248parent"); deleteProject("MNGECLIPSE-248child"); final IProject project1 = createProject("MNGECLIPSE-248parent", "projects/MNGECLIPSE-248parent/pom.xml"); final IProject project2 = createProject("MNGECLIPSE-248child", "projects/MNGECLIPSE-248child/pom.xml"); NullProgressMonitor monitor = new NullProgressMonitor(); BuildPathManager buildpathManager = Maven2Plugin.getDefault().getBuildpathManager(); ResolverConfiguration configuration = new ResolverConfiguration(); buildpathManager.enableMavenNature(project1, configuration, monitor); // buildpathManager.updateSourceFolders(project1, monitor); buildpathManager.enableMavenNature(project2, configuration, monitor); // buildpathManager.updateSourceFolders(project2, monitor); // waitForJob("Initializing " + project1.getProject().getName()); // waitForJob("Initializing " + project2.getProject().getName()); waitForJobsToComplete();/*w ww . j a va 2s .com*/ IClasspathEntry[] project1entries = getMavenContainerEntries(project1); assertEquals(1, project1entries.length); assertEquals(IClasspathEntry.CPE_LIBRARY, project1entries[0].getEntryKind()); assertTrue(project1entries[0].getPath().lastSegment().equals("junit-4.1.jar")); IClasspathEntry[] project2entries = getMavenContainerEntries(project2); assertEquals(2, project2entries.length); assertEquals(IClasspathEntry.CPE_PROJECT, project2entries[0].getEntryKind()); assertTrue(project2entries[0].getPath().segment(0).equals("MNGECLIPSE-248parent")); assertEquals(IClasspathEntry.CPE_LIBRARY, project2entries[1].getEntryKind()); assertTrue(project2entries[1].getPath().lastSegment().equals("junit-4.1.jar")); }
From source file:org.maven.ide.eclipse.tests.BuildPathManagerTest.java
License:Apache License
public void testEnableMavenNatureWithNoWorkspace() throws Exception { deleteProject("MNGECLIPSE-248parent"); deleteProject("MNGECLIPSE-248child"); final IProject project1 = createProject("MNGECLIPSE-248parent", "projects/MNGECLIPSE-248parent/pom.xml"); final IProject project2 = createProject("MNGECLIPSE-248child", "projects/MNGECLIPSE-248child/pom.xml"); NullProgressMonitor monitor = new NullProgressMonitor(); BuildPathManager buildpathManager = Maven2Plugin.getDefault().getBuildpathManager(); ResolverConfiguration configuration = new ResolverConfiguration(NO_MODULES, NO_WORKSPACE, ""); buildpathManager.enableMavenNature(project1, configuration, monitor); buildpathManager.enableMavenNature(project2, configuration, monitor); // buildpathManager.updateSourceFolders(project1, monitor); // buildpathManager.updateSourceFolders(project2, monitor); // waitForJob("Initializing " + project1.getProject().getName()); // waitForJob("Initializing " + project2.getProject().getName()); waitForJobsToComplete();// w w w . j a va 2 s. co m IClasspathEntry[] project1entries = getMavenContainerEntries(project1); assertEquals(1, project1entries.length); assertEquals(IClasspathEntry.CPE_LIBRARY, project1entries[0].getEntryKind()); assertTrue(project1entries[0].getPath().lastSegment().equals("junit-4.1.jar")); IClasspathEntry[] project2entries = getMavenContainerEntries(project2); assertEquals(2, project2entries.length); assertEquals(IClasspathEntry.CPE_LIBRARY, project2entries[0].getEntryKind()); assertTrue(project2entries[0].getPath().lastSegment().equals("junit-4.1.jar")); assertEquals(IClasspathEntry.CPE_LIBRARY, project2entries[1].getEntryKind()); assertTrue(project2entries[1].getPath().lastSegment().equals("MNGECLIPSE-248parent-1.0.0.jar")); }
From source file:org.mobicents.eclipslee.servicecreation.ui.ExternalComponentsPropertyPage.java
License:Apache License
private void removeFromClasspath(IFolder folder) { try {/*from w ww . ja va2 s. co m*/ Vector entries = new Vector(); IResource resources[] = folder.members(); for (int i = 0; i < resources.length; i++) { if (resources[i].getType() == IResource.FILE && resources[i].getName().endsWith(".jar")) entries.add(resources[i]); if (resources[i].getType() == IResource.FOLDER) removeFromClasspath((IFolder) resources[i]); } IProject project = getProject(); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry old[] = javaProject.getRawClasspath(); Vector newCP = new Vector(); for (int i = 0; i < old.length; i++) { // Get the IPath of the jar file in this classpath entry IPath jarPath = old[i].getPath(); // Is this a LIBRARY entry if (old[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // Is this LIBRARY entry in this folder if (folder.getFullPath().isPrefixOf(jarPath)) { continue; // Don't add this jar file back to the path. } } // Add this jar file back into the path. newCP.add(old[i]); } IClasspathEntry newEntries[] = (IClasspathEntry[]) newCP.toArray(new IClasspathEntry[newCP.size()]); javaProject.setRawClasspath(newEntries, null); removeFromBuildFile(javaProject, entries); } catch (CoreException e) { ServiceCreationPlugin.log(e); } }
From source file:org.mobicents.eclipslee.servicecreation.util.BaseFinder.java
License:Apache License
/** * Searches the specified project's classpath for Jar file containing components. * /*from w w w . ja v a 2 s. com*/ * @param projectName * @return */ private Vector<DTDXML> getComponentsFromClassPath(String projectName) { Vector<DTDXML> components = new Vector<DTDXML>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); IJavaElement ele = JavaCore.create(project); if (ele instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) JavaCore.create(project); try { IClasspathEntry entry[] = javaProject.getResolvedClasspath(true); for (int j = 0; j < entry.length; j++) { if (entry[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry[j].getPath(); components.addAll(getComponentsFromJar(path)); } } } catch (JavaModelException e) { } } return components; }
From source file:org.mobicents.eclipslee.servicecreation.util.BaseFinder.java
License:Apache License
/** * Searches the classpath of every project for component jars. * //from w w w . ja v a 2 s .c o m * @return */ private Vector<DTDXML> getComponentsFromClassPath() { Vector<DTDXML> components = new Vector<DTDXML>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject projects[] = root.getProjects(); for (int i = 0; i < projects.length; i++) { IJavaElement ele = JavaCore.create(projects[i]); if (ele instanceof IJavaProject) { IJavaProject project = (IJavaProject) JavaCore.create(projects[i]); try { IClasspathEntry entry[] = project.getResolvedClasspath(true); for (int j = 0; j < entry.length; j++) { if (entry[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry[j].getPath(); components.addAll(getComponentsFromJar(path)); } } } catch (JavaModelException e) { } } } return components; }
From source file:org.mybatis.generator.eclipse.ui.actions.RunGeneratorThread.java
License:Apache License
private void setClassLoader() { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject javaProject = getJavaProject(); try {//from ww w . j a v a 2 s . c om if (javaProject != null) { List<URL> entries = new ArrayList<URL>(); IPath path = javaProject.getOutputLocation(); IResource iResource = root.findMember(path); path = iResource.getLocation(); path = path.addTrailingSeparator(); entries.add(path.toFile().toURI().toURL()); IClasspathEntry[] cpEntries = javaProject.getRawClasspath(); for (IClasspathEntry cpEntry : cpEntries) { switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: path = cpEntry.getOutputLocation(); if (path != null) { iResource = root.findMember(path); path = iResource.getLocation(); path = path.addTrailingSeparator(); entries.add(path.toFile().toURI().toURL()); } break; case IClasspathEntry.CPE_LIBRARY: iResource = root.findMember(cpEntry.getPath()); if (iResource == null) { // resource is not in workspace, must be an external JAR path = cpEntry.getPath(); } else { path = iResource.getLocation(); } entries.add(path.toFile().toURI().toURL()); break; } } ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); URL[] entryArray = new URL[entries.size()]; entries.toArray(entryArray); ClassLoader newCl = new URLClassLoader(entryArray, oldCl); Thread.currentThread().setContextClassLoader(newCl); oldClassLoader = oldCl; } } catch (Exception e) { // ignore - something too complex is wrong ; } }
From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java
License:Apache License
private static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls, Set<IJavaProject> visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;//from w w w . j av a2s . com visited.add(javaProject); IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject()); if (outPath != null) { outPath = outPath.addTrailingSeparator(); URL out = createFileURL(outPath); urls.add(out); } IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return; } IClasspathEntry entry; for (int i = 0; i < entries.length; i++) { entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathURLs(getJavaProject(entry), urls, visited, false); break; } } } }
From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java
License:Apache License
private static void collectClasspathIPath(IJavaProject javaProject, List<IPath> urls, Set<IJavaProject> visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;// ww w . ja va 2 s. c o m visited.add(javaProject); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return; } IClasspathEntry entry; for (int i = 0; i < entries.length; i++) { entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: addJarToList(entry.getPath(), urls); break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_SOURCE: break; case IClasspathEntry.CPE_VARIABLE: addJarToList(entry.getPath(), urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathIPath(getJavaProject(entry), urls, visited, false); break; } } } }
From source file:org.nuxeo.ide.sdk.java.ClasspathEditor.java
License:Open Source License
public void removeLibraries() { Iterator<IClasspathEntry> it = entries.iterator(); while (it.hasNext()) { IClasspathEntry entry = it.next(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: it.remove();/*from ww w.j a va 2 s. c o m*/ dirty = true; } } }
From source file:org.objectstyle.wolips.eomodeler.eclipse.EclipseEOModelGroupFactory.java
License:Open Source License
protected void addModelsFromProject(EOModelGroup modelGroup, IProject project, Set<Object> searchedResources, Set<IProject> searchedProjects, Set<EOModelVerificationFailure> failures, boolean skipOnDuplicates, IProgressMonitor progressMonitor, int depth) throws IOException, EOModelException, CoreException { if (!searchedProjects.contains(project)) { progressMonitor.setTaskName("Adding models from " + project.getName() + " ..."); searchedProjects.add(project);//from w ww. j a va2s .c o m if (!project.exists()) { failures.add(new EOModelVerificationFailure(null, "The dependent project '" + project.getName() + "' does not exist.", false)); } else if (!project.isOpen()) { failures.add(new EOModelVerificationFailure(null, "The dependent project '" + project.getName() + "' exists but is not open.", false)); } else { boolean visitedProject = false; boolean isJavaProject = project.getNature(JavaCore.NATURE_ID) != null; IClasspathEntry[] classpathEntries = null; if (isJavaProject) { IJavaProject javaProject = JavaCore.create(project); classpathEntries = javaProject.getResolvedClasspath(true); } else { classpathEntries = new IClasspathEntry[0]; } boolean showProgress = (depth == 0); if (showProgress) { progressMonitor.beginTask("Scanning " + project.getName() + " classpath ...", classpathEntries.length + 1); } for (int classpathEntryNum = 0; classpathEntryNum < classpathEntries.length; classpathEntryNum++) { IClasspathEntry entry = classpathEntries[classpathEntryNum]; int entryKind = entry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_LIBRARY) { List<IPath> jarPaths = new LinkedList<IPath>(); IPath path = entry.getPath(); IPath frameworkPath = null; while (frameworkPath == null && path.lastSegment() != null) { String lastSegment = path.lastSegment(); if (lastSegment != null && lastSegment.endsWith(".framework")) { frameworkPath = path; } else { if (lastSegment != null && lastSegment.endsWith(".jar")) { // MS: This is really annoying, but it appears that a jar in your project looks the // same as an absolute jar path reference outside your project. I don't know // how to tell them apart, so I check to see if the jar is in your project // before we fallback to the old way. IFile jarInProject = project.getWorkspace().getRoot().getFile(path); if (jarInProject.exists()) { jarPaths.add(jarInProject.getLocation()); } else { jarPaths.add(path); } } path = path.removeLastSegments(1); } } if (frameworkPath != null) { File resourcesFolder = frameworkPath.append("Resources").toFile(); if (!searchedResources.contains(resourcesFolder) && resourcesFolder.exists()) { searchedResources.add(resourcesFolder); modelGroup.loadModelsFromURL(resourcesFolder.toURL(), 1, failures, skipOnDuplicates, progressMonitor); } } for (IPath jarPath : jarPaths) { URL jarResourcesURL = new URL("jar:" + jarPath.toFile().toURL() + "!/Resources"); if (!searchedResources.contains(jarResourcesURL) && URLUtils.exists(jarResourcesURL)) { modelGroup.loadModelsFromURL(jarResourcesURL, 1, failures, skipOnDuplicates, progressMonitor); } } } else if (entryKind == IClasspathEntry.CPE_PROJECT) { IPath path = entry.getPath(); IProject dependsOnProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(path.lastSegment()); addModelsFromProject(modelGroup, dependsOnProject, searchedResources, searchedProjects, failures, skipOnDuplicates, progressMonitor, depth + 1); } else if (entryKind == IClasspathEntry.CPE_SOURCE) { visitedProject = true; project.accept(new ModelVisitor(project, modelGroup, searchedResources, failures, skipOnDuplicates, progressMonitor), IResource.DEPTH_INFINITE, IContainer.EXCLUDE_DERIVED); } if (showProgress) { progressMonitor.worked(1); } } if (!visitedProject) { project.accept(new ModelVisitor(project, modelGroup, searchedResources, failures, skipOnDuplicates, progressMonitor), IResource.DEPTH_INFINITE, IContainer.EXCLUDE_DERIVED); if (showProgress) { progressMonitor.worked(1); } } } } }