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.eclipse.m2e.jdt.internal.BuildPathManager.java
License:Open Source License
void attachSourcesAndJavadoc(IPackageFragmentRoot fragment, File sources, File javadoc, IProgressMonitor monitor) {/* w w w .j a v a 2 s .co m*/ IJavaProject javaProject = fragment.getJavaProject(); IPath srcPath = sources != null ? Path.fromOSString(sources.getAbsolutePath()) : null; String javaDocUrl = getJavaDocUrl(javadoc); try { IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { IClasspathEntry entry = cp[i]; if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind() && entry.equals(fragment.getRawClasspathEntry())) { List<IClasspathAttribute> attributes = new ArrayList<IClasspathAttribute>( Arrays.asList(entry.getExtraAttributes())); if (srcPath == null) { // configure javadocs if available if (javaDocUrl != null) { attributes.add(JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl)); } } cp[i] = JavaCore.newLibraryEntry(entry.getPath(), srcPath, null, entry.getAccessRules(), // attributes.toArray(new IClasspathAttribute[attributes.size()]), // entry.isExported()); break; } } javaProject.setRawClasspath(cp, monitor); } catch (CoreException e) { log.error(e.getMessage(), e); } }
From source file:org.eclipse.m2e.jdt.internal.ClasspathDescriptor.java
License:Open Source License
public ClasspathEntryDescriptor addLibraryEntry(IPath entryPath) { ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(IClasspathEntry.CPE_LIBRARY, entryPath); addEntryDescriptor(entry);//from w ww . j a v a 2 s. c om return entry; }
From source file:org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor.java
License:Open Source License
public IClasspathEntry toClasspathEntry() { Map<String, String> attributes = new LinkedHashMap<String, String>(this.attributes); if (artifactKey != null) { attributes.put(IClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); attributes.put(IClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); attributes.put(IClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); if (artifactKey.getClassifier() != null) { attributes.put(IClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); }// w ww.j a v a 2s . c o m } if (scope != null) { attributes.put(IClasspathManager.SCOPE_ATTRIBUTE, scope); } IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()]; int attributeIndex = 0; for (Map.Entry<String, String> attribute : attributes.entrySet()) { attributesArray[attributeIndex++] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue()); } IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); IClasspathEntry entry; switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, // sourceAttachmentPath, // sourceAttachmentRootPath, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_SOURCE: entry = JavaCore.newSourceEntry(path, // getInclusionPatterns(), // getExclusionPatterns(), // outputLocation, // attributesArray); break; case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, // accessRulesArray, // combineAccessRules, // attributesArray, // exported); break; default: throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ } return entry; }
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;/*w ww .j av a 2 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);/*from w ww. j a v a 2s .c om*/ 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;// ww w . j av a2s . 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 ww w .j a v a 2 s.c om 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 ww . ja v 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.BuildPathManagerTest.java
License:Open Source 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"); IProjectConfigurationManager importManager = MavenPlugin.getProjectConfigurationManager(); ResolverConfiguration configuration = new ResolverConfiguration(); configuration.setResolveWorkspaceProjects(false); configuration.setSelectedProfiles(""); importManager.enableMavenNature(project1, configuration, monitor); importManager.enableMavenNature(project2, configuration, monitor); waitForJobsToComplete();/* www.j av a 2 s . com*/ IClasspathEntry[] project2entries = getMavenContainerEntries(project2); assertEquals(Arrays.asList(project2entries).toString(), 1, project2entries.length); assertEquals(IClasspathEntry.CPE_LIBRARY, project2entries[0].getEntryKind()); assertEquals("MNGECLIPSE-248parent-1.0.0.jar", project2entries[0].getPath().lastSegment()); }
From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java
License:Open Source License
public void testCreateSimpleProject() throws CoreException { IProject project = createSimpleProject("simple-project", null); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); assertEquals(Arrays.toString(rawClasspath), 6, rawClasspath.length); assertEquals("/simple-project/src/main/java", rawClasspath[0].getPath().toString()); assertEquals("/simple-project/src/main/resources", rawClasspath[1].getPath().toString()); assertEquals("/simple-project/src/test/java", rawClasspath[2].getPath().toString()); assertEquals("/simple-project/src/test/resources", rawClasspath[3].getPath().toString()); assertEquals(// ww w. j a va2 s.c o m "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5", rawClasspath[4].getPath().toString()); assertEquals("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER", rawClasspath[5].getPath().toString()); IClasspathEntry[] entries = getMavenContainerEntries(project); assertEquals(Arrays.toString(entries), 1, entries.length); assertEquals(IClasspathEntry.CPE_LIBRARY, entries[0].getEntryKind()); assertEquals("junit-3.8.1.jar", entries[0].getPath().lastSegment()); assertTrue(project.getFile("pom.xml").exists()); assertTrue(project.getFolder("src/main/java").exists()); assertTrue(project.getFolder("src/test/java").exists()); assertTrue(project.getFolder("src/main/resources").exists()); assertTrue(project.getFolder("src/test/resources").exists()); }