List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT
int CPE_PROJECT
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.
Click Source Link
From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java
License:Open Source License
private static String getModuleName(IClasspathEntryDescriptor entry, IProgressMonitor monitor) { String module = null;//from w w w . j a va2 s . c o m if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) { module = getModuleNameFromJar(entry.getPath().toFile()); } else if (IClasspathEntry.CPE_PROJECT == entry.getEntryKind()) { module = getModuleNameFromProject(entry.getPath(), monitor); } return module; }
From source file:org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.java
License:Open Source License
private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved, IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope, IProgressMonitor monitor) throws CoreException { IJavaProject javaProject = JavaRuntime.getJavaProject(configuration); MavenJdtPlugin plugin = MavenJdtPlugin.getDefault(); IClasspathManager buildpathManager = plugin.getBuildpathManager(); IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor); for (IClasspathEntry entry : cp) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration, monitor);//ww w. j a v a 2s . c o m break; case IClasspathEntry.CPE_LIBRARY: resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath())); break; // case IClasspathEntry.CPE_SOURCE: // resolved.add(newSourceClasspathEntry(javaProject, cp[i])); // break; } } }
From source file:org.eclipse.m2e.jdt.internal.launch.MavenRuntimeClasspathProvider.java
License:Open Source License
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(path.segment(0)); IMavenProjectFacade projectFacade = projectManager.create(project, monitor); if (projectFacade == null) { return;//from w ww . j a v a2 s .c o m } ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); if (configuration == null) { return; } IJavaProject javaProject = JavaCore.create(project); boolean projectResolved = false; for (IClasspathEntry entry : javaProject.getRawClasspath()) { IRuntimeClasspathEntry rce = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!projectResolved) { IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault() .getMavenClassifierManager(); IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager .getClassifierClasspathProvider(projectFacade, classifier); if (IClasspathManager.CLASSPATH_TEST == scope) { classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor); } else { classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor); } projectResolved = true; } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); break; // case IClasspathContainer.K_DEFAULT_SYSTEM: // unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES, javaProject)); // break; // case IClasspathContainer.K_SYSTEM: // unresolved.add(JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.BOOTSTRAP_CLASSES, javaProject)); // break; } } break; case IClasspathEntry.CPE_LIBRARY: rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); break; case IClasspathEntry.CPE_VARIABLE: if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); } break; case IClasspathEntry.CPE_PROJECT: IProject res = root.getProject(entry.getPath().segment(0)); if (res != null) { IJavaProject otherProject = JavaCore.create(res); if (otherProject != null) { rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); } } break; default: break; } if (rce != null) { addStandardClasspathEntries(resolved, rce, launchConfiguration); } } }
From source file:org.eclipse.m2e.jdt.internal.MavenClasspathContainerSaveHelper.java
License:Open Source License
public void writeContainer(IClasspathContainer container, OutputStream output) throws IOException { ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(output)) { {//from w w w . j a v a2s. c o m enableReplaceObject(true); } protected Object replaceObject(Object o) throws IOException { if (o instanceof IClasspathEntry) { IClasspathEntry e = (IClasspathEntry) o; if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { return new ProjectEntryReplace(e); } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return new LibraryEntryReplace(e); } } else if (o instanceof IClasspathAttribute) { return new ClasspathAttributeReplace((IClasspathAttribute) o); } else if (o instanceof IAccessRule) { return new AccessRuleReplace((IAccessRule) o); } else if (o instanceof IPath) { return new PathReplace((IPath) o); } return super.replaceObject(o); } }; os.writeObject(container); os.flush(); }
From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java
License:Open Source 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(); IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager(); ResolverConfiguration configuration = new ResolverConfiguration(); configurationManager.enableMavenNature(project1, configuration, monitor); // buildpathManager.updateSourceFolders(project1, monitor); configurationManager.enableMavenNature(project2, configuration, monitor); // buildpathManager.updateSourceFolders(project2, monitor); // waitForJob("Initializing " + project1.getProject().getName()); // waitForJob("Initializing " + project2.getProject().getName()); try {//from w w w .j av a 2 s . c om project1.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); project2.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); } catch (Exception ex) { throw ex; } waitForJobsToComplete(); WorkspaceHelpers.assertNoErrors(project1); // IClasspathEntry[] project1entries = getMavenContainerEntries(project1); // assertEquals(1, project1entries.length); // assertEquals(IClasspathEntry.CPE_LIBRARY, project1entries[0].getEntryKind()); // assertEquals("junit-4.1.jar", project1entries[0].getPath().lastSegment()); IClasspathEntry[] project2entries = getMavenContainerEntries(project2); assertEquals(2, project2entries.length); assertEquals(IClasspathEntry.CPE_PROJECT, project2entries[0].getEntryKind()); assertEquals("MNGECLIPSE-248parent", project2entries[0].getPath().segment(0)); assertEquals(IClasspathEntry.CPE_LIBRARY, project2entries[1].getEntryKind()); assertEquals("junit-4.1.jar", project2entries[1].getPath().lastSegment()); configurationManager.updateProjectConfiguration(project2, monitor); waitForJobsToComplete(); WorkspaceHelpers.assertNoErrors(project2); }
From source file:org.eclipse.m2e.tests.jdt.internal.MavenClasspathContainerSaveHelperTest.java
License:Open Source License
public void testClasspathContainerSace() throws Exception { IClasspathEntry[] entries = new IClasspathEntry[2]; {// w ww .j a v a2 s .c om IAccessRule[] accessRules = new IAccessRule[1]; accessRules[0] = JavaCore.newAccessRule(new Path("aa/**"), IAccessRule.K_ACCESSIBLE); IClasspathAttribute[] attributes = new IClasspathAttribute[2]; attributes[0] = JavaCore.newClasspathAttribute("foo", "11"); attributes[1] = JavaCore.newClasspathAttribute("moo", "22"); entries[0] = JavaCore.newProjectEntry(new Path("/foo"), accessRules, true, attributes, false); } { IAccessRule[] accessRules = new IAccessRule[1]; accessRules[0] = JavaCore.newAccessRule(new Path("bb/**"), IAccessRule.K_DISCOURAGED); IClasspathAttribute[] attributes = new IClasspathAttribute[1]; attributes[0] = JavaCore.newClasspathAttribute("foo", "aa"); entries[1] = JavaCore.newLibraryEntry(new Path("/foo/moo.jar"), new Path("/foo/moo-sources.jar"), new Path("/foo/moo-javadoc.jar"), accessRules, attributes, false); } ByteArrayOutputStream os = new ByteArrayOutputStream(); helper.writeContainer(new MavenClasspathContainer(new Path(IClasspathManager.CONTAINER_ID), entries), os); os.close(); IClasspathContainer container = helper.readContainer(new ByteArrayInputStream(os.toByteArray())); assertEquals(IClasspathManager.CONTAINER_ID, container.getPath().toString()); IClasspathEntry[] classpathEntries = container.getClasspathEntries(); assertEquals(2, classpathEntries.length); { IClasspathEntry entry = classpathEntries[0]; assertEquals(IClasspathEntry.CPE_PROJECT, entry.getEntryKind()); assertEquals("/foo", entry.getPath().toString()); assertEquals(false, entry.isExported()); assertEquals(true, entry.combineAccessRules()); IAccessRule[] accessRules = entry.getAccessRules(); assertEquals(1, accessRules.length); assertEquals(IAccessRule.K_ACCESSIBLE, accessRules[0].getKind()); assertEquals("aa/**", accessRules[0].getPattern().toString()); IClasspathAttribute[] attributes = entry.getExtraAttributes(); assertEquals(2, attributes.length); assertEquals("foo", attributes[0].getName()); assertEquals("11", attributes[0].getValue()); assertEquals("moo", attributes[1].getName()); assertEquals("22", attributes[1].getValue()); } { IClasspathEntry entry = classpathEntries[1]; assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind()); assertEquals("/foo/moo.jar", entry.getPath().toString()); assertEquals(false, entry.isExported()); IAccessRule[] accessRules = entry.getAccessRules(); assertEquals(1, accessRules.length); assertEquals(IAccessRule.K_DISCOURAGED, accessRules[0].getKind()); assertEquals("bb/**", accessRules[0].getPattern().toString()); IClasspathAttribute[] attributes = entry.getExtraAttributes(); assertEquals(1, attributes.length); assertEquals("foo", attributes[0].getName()); assertEquals("aa", attributes[0].getValue()); } }
From source file:org.eclipse.osee.framework.ui.ws.AJavaProject.java
License:Open Source License
public static ArrayList<File> getJavaProjectProjectDependancies(IJavaProject javaProject) { ArrayList<File> urls = new ArrayList<File>(); try {//from www . java 2 s . c o m IClasspathEntry[] paths = localGetResolvedClasspath(javaProject); for (int i = 0; i < paths.length; i++) { if (paths[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (paths[i].getPath().toFile().exists()) { // urls.add(paths[i].getPath().toFile()); } else { File file = null; file = new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toOSString())); if (file.exists()) { urls.add(file); } } } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { urls.add(new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toFile().getPath() .concat(File.separator + "bin" + File.separator)))); } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { File projectlocation = javaProject.getProject().getLocation().toFile(); File projecttricky = javaProject.getProject().getFullPath().toFile(); IPath output = paths[i].getOutputLocation(); File fileLocation; if (output == null) { fileLocation = new File(paths[i].getPath().toFile().getPath().replace("src", "bin")); } else { fileLocation = paths[i].getOutputLocation().toFile(); } String realLocation = fileLocation.toString().replace(projecttricky.toString(), projectlocation.toString()); urls.add(new File(realLocation)); } } } catch (JavaModelException ex) { ex.printStackTrace(); } return urls; }
From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java
License:Open Source License
/** * Returns the complete listing of required projects from the classpath of * the backing project/*from w w w . ja v a 2 s .c o m*/ * * @param includeBinaryPrerequisites * @return the list of projects required * @throws CoreException */ IProject[] getRequiredProjects(boolean includebinaries) throws CoreException { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); if (this.currentproject == null || workspaceRoot == null) { return new IProject[0]; } ArrayList<IProject> projects = new ArrayList<IProject>(); try { IJavaProject javaProject = JavaCore.create(this.currentproject); HashSet<IPath> blocations = new HashSet<IPath>(); blocations.add(javaProject.getOutputLocation()); this.output_locs.put(this.currentproject, blocations); HashSet<IPath> slocations = new HashSet<IPath>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].isArchive()) { continue; } slocations.add(roots[i].getPath()); } this.src_locs.put(this.currentproject, slocations); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { p = workspaceRoot.getProject(path.lastSegment()); // missing // projects // are // considered // too if (isOptional(entry) && !p.hasNature(ApiPlugin.NATURE_ID)) {// except // if // entry // is // optional p = null; } break; } case IClasspathEntry.CPE_LIBRARY: { if (includebinaries && path.segmentCount() > 1) { // some binary resources on the class path can come // from projects that are not included in the // project references IResource resource = workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) { p = (IProject) resource; } } break; } case IClasspathEntry.CPE_SOURCE: { IPath entrypath = entry.getOutputLocation(); if (entrypath != null) { blocations.add(entrypath); } break; } default: { break; } } if (p != null && !projects.contains(p)) { projects.add(p); // try to derive all of the output locations for each of the // projects javaProject = JavaCore.create(p); HashSet<IPath> bins = new HashSet<IPath>(); HashSet<IPath> srcs = new HashSet<IPath>(); if (javaProject.exists()) { bins.add(javaProject.getOutputLocation()); IClasspathEntry[] source = javaProject.getRawClasspath(); IPath entrypath = null; for (int j = 0; j < source.length; j++) { if (source[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcs.add(source[j].getPath()); entrypath = source[j].getOutputLocation(); if (entrypath != null) { bins.add(entrypath); } } } this.output_locs.put(p, bins); this.src_locs.put(p, srcs); } } } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.eclipse.pde.internal.ui.wizards.plugin.NewLibraryPluginCreationOperation.java
License:Open Source License
private static boolean isPluginProjectEntry(IClasspathEntry entry) { if (IClasspathEntry.CPE_PROJECT != entry.getEntryKind()) return false; IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject other = workspaceRoot.getProject(entry.getPath().segment(0)); if (!PDE.hasPluginNature(other)) return false; if (PDEProject.getFragmentXml(other).exists()) return false; try {//from ww w . j ava 2 s . c om InputStream is = PDEProject.getManifest(other).getContents(); try { Manifest mf = new Manifest(is); if (mf.getMainAttributes().getValue(Constants.FRAGMENT_HOST) != null) return false; } finally { is.close(); } } catch (IOException e) { // assume "not a fragment" } catch (CoreException e) { // assume "not a fragment" } return true; }
From source file:org.eclipse.stardust.modeling.validation.util.ProjectClassLoader.java
License:Open Source License
private List resolveClasspath(IProject project, Set compareStrings) { List classpath = new ArrayList(); IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { IPath projectPath = project.getFullPath(); IPath projectLocation = project.getLocation().removeLastSegments(projectPath.segmentCount()); try {//from w w w. jav a 2 s.c om IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); // we are guaranteed that no variables or containers are present in the classpath entries for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { // add recursively the entries from the referenced projects classpath.addAll(resolveClasspath(findProject(entries[i].getPath()), compareStrings)); } else { IPath entryPath = entries[i].getPath(); if (projectPath.isPrefixOf(entryPath)) { // if it's a project relative location, prepend it with the project location entryPath = projectLocation.append(entryPath); } addClasspathEntry(classpath, compareStrings, entryPath); } } } catch (JavaModelException e) { // e.printStackTrace(); } } return classpath; }