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.sonarlint.eclipse.jdt.internal.JavaProjectConfiguratorTest.java
License:Open Source License
@Test public void shouldConfigureProjectsWithCircularDependencies() throws CoreException, IOException { // the bug appeared when at least 3 projects were involved: the first project depends on the second one which has a circular dependency // towards the second one Map<String, String> sonarProperties = new HashMap<>(); // mock three projects that depend on each other final String project1Name = "project1"; final String project2Name = "project2"; final String project3Name = "project3"; IJavaProject project1 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); IJavaProject project2 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); IJavaProject project3 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); // these are required during the call to configureJavaProject when(project1.getOption(JavaCore.COMPILER_SOURCE, true)).thenReturn("1.6"); when(project1.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)).thenReturn("1.6"); when(project1.getProject().getName()).thenReturn(project1Name); when(project2.getProject().getName()).thenReturn(project2Name); when(project3.getProject().getName()).thenReturn(project3Name); // create three classpathEntries, one for each Project IClasspathEntry entryProject1 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); IClasspathEntry entryProject2 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); IClasspathEntry entryProject3 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); when(entryProject1.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject1.getPath().segment(0)).thenReturn(project1Name); when(entryProject2.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject2.getPath().segment(0)).thenReturn(project2Name); when(entryProject3.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject3.getPath().segment(0)).thenReturn(project3Name); // project1 depends on project2, which depends on project3, which depends on project2 IClasspathEntry[] classpath1 = new IClasspathEntry[] { entryProject2 }; IClasspathEntry[] classpath2 = new IClasspathEntry[] { entryProject3 }; IClasspathEntry[] classpath3 = new IClasspathEntry[] { entryProject2 }; when(project1.getResolvedClasspath(true)).thenReturn(classpath1); when(project2.getResolvedClasspath(true)).thenReturn(classpath2); when(project3.getResolvedClasspath(true)).thenReturn(classpath3); // mock the JavaModel IJavaModel javaModel = mock(IJavaModel.class); when(javaModel.getJavaProject(project1Name)).thenReturn(project1); when(javaModel.getJavaProject(project2Name)).thenReturn(project2); when(javaModel.getJavaProject(project3Name)).thenReturn(project3); when(project1.getJavaModel()).thenReturn(javaModel); when(project2.getJavaModel()).thenReturn(javaModel); when(project3.getJavaModel()).thenReturn(javaModel); // this call should not fail (StackOverFlowError before patch) configurator.configureJavaProject(project1, sonarProperties); }
From source file:org.sonarlint.eclipse.jdt.internal.JdtUtils.java
License:Open Source License
/** * Adds the classpath of an eclipse project to the sonarProject recursively, i.e * it iterates all dependent projects. Libraries and output folders of dependent projects * are added, but no source folders./*w w w . j av a 2 s. c o m*/ * @param javaProject the eclipse project to get the classpath from * @param sonarProjectProperties the sonar project properties to add the classpath to * @param context * @param topProject indicate we are working on the project to be analyzed and not on a dependent project * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)} */ private static void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context, boolean topProject) throws JavaModelException { IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : classPath) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: processSourceEntry(entry, context, topProject); break; case IClasspathEntry.CPE_LIBRARY: processLibraryEntry(entry, javaProject, context, topProject); break; case IClasspathEntry.CPE_PROJECT: processProjectEntry(entry, javaProject, context); break; default: SonarLintLogger.get().info("Unhandled ClassPathEntry : " + entry); break; } } processOutputDir(javaProject.getOutputLocation(), context, topProject); }
From source file:org.sonarlint.eclipse.jdt.internal.JdtUtilsTest.java
License:Open Source License
@Test public void shouldConfigureProjectsWithCircularDependencies() throws CoreException, IOException { // the bug appeared when at least 3 projects were involved: the first project depends on the second one which has a circular dependency // towards the second one IPreAnalysisContext context = mock(IPreAnalysisContext.class); // mock three projects that depend on each other final String project1Name = "project1"; final String project2Name = "project2"; final String project3Name = "project3"; IJavaProject project1 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); IJavaProject project2 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); IJavaProject project3 = mock(IJavaProject.class, Mockito.RETURNS_DEEP_STUBS); // these are required during the call to configureJavaProject when(project1.getOption(JavaCore.COMPILER_SOURCE, true)).thenReturn("1.6"); when(project1.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)).thenReturn("1.6"); when(project1.getProject().getName()).thenReturn(project1Name); when(project2.getProject().getName()).thenReturn(project2Name); when(project3.getProject().getName()).thenReturn(project3Name); // create three classpathEntries, one for each Project IClasspathEntry entryProject1 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); IClasspathEntry entryProject2 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); IClasspathEntry entryProject3 = mock(IClasspathEntry.class, Mockito.RETURNS_DEEP_STUBS); when(entryProject1.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject1.getPath().segment(0)).thenReturn(project1Name); when(entryProject2.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject2.getPath().segment(0)).thenReturn(project2Name); when(entryProject3.getEntryKind()).thenReturn(IClasspathEntry.CPE_PROJECT); when(entryProject3.getPath().segment(0)).thenReturn(project3Name); // project1 depends on project2, which depends on project3, which depends on project2 IClasspathEntry[] classpath1 = new IClasspathEntry[] { entryProject2 }; IClasspathEntry[] classpath2 = new IClasspathEntry[] { entryProject3 }; IClasspathEntry[] classpath3 = new IClasspathEntry[] { entryProject2 }; when(project1.getResolvedClasspath(true)).thenReturn(classpath1); when(project2.getResolvedClasspath(true)).thenReturn(classpath2); when(project3.getResolvedClasspath(true)).thenReturn(classpath3); // mock the JavaModel IJavaModel javaModel = mock(IJavaModel.class); when(javaModel.getJavaProject(project1Name)).thenReturn(project1); when(javaModel.getJavaProject(project2Name)).thenReturn(project2); when(javaModel.getJavaProject(project3Name)).thenReturn(project3); when(project1.getJavaModel()).thenReturn(javaModel); when(project2.getJavaModel()).thenReturn(javaModel); when(project3.getJavaModel()).thenReturn(javaModel); // this call should not fail (StackOverFlowError before patch) jdtUtils.configureJavaProject(project1, context); }
From source file:org.sonatype.m2e.webby.internal.launch.WebbySourcePathProvider.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()); break; case IClasspathEntry.CPE_LIBRARY: resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath())); break; }/*from w ww.j a va2 s . co m*/ } }
From source file:org.sonatype.tycho.m2e.internal.launching.PDEBundleClasspathResolver.java
License:Open Source License
@Override public Map<IPath, Collection<IPath>> getAdditionalClasspathEntries(IJavaProject javaProject) { IProgressMonitor monitor = new NullProgressMonitor(); Map<IPath, Collection<IPath>> result = new LinkedHashMap<IPath, Collection<IPath>>(); List<IClasspathEntryDescriptor> cp = resolveMavenClasspath(javaProject, monitor); IProject project = javaProject.getProject(); if (cp.isEmpty()) { return result; }//www. j ava 2 s . c o m IWorkspaceRoot workspace = project.getWorkspace().getRoot(); Map<ArtifactKey, String> classpathMap = EmbeddedArtifacts.getEmbeddedArtifacts(project); for (IClasspathEntryDescriptor entry : cp) { String pathStr = getBundlePath(classpathMap, entry); if (pathStr != null && !".".equals(pathStr)) // inlined dependencies are not supported at the moment { IPath path = new Path(pathStr); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: addClasspathMap(result, path, getBuildOutputLocation(workspace, entry.getPath().segment(0))); break; case IClasspathEntry.CPE_LIBRARY: addClasspathMap(result, path, entry.getPath()); break; } } } return result; }
From source file:org.sonatype.tycho.m2e.internal.launching.PDEBundleClasspathResolver.java
License:Open Source License
@Override public Collection<IRuntimeClasspathEntry> getAdditionalSourceEntries(IJavaProject javaProject) { // igorf: Returned entries do not have attached sources. I am not actually sure this works. IProgressMonitor monitor = new NullProgressMonitor(); Set<IRuntimeClasspathEntry> resolved = new LinkedHashSet<IRuntimeClasspathEntry>(); List<IClasspathEntryDescriptor> cp = resolveMavenClasspath(javaProject, monitor); if (cp.isEmpty()) { return resolved; }/* w w w. j a v a 2 s.co m*/ Map<ArtifactKey, String> classpathMap = EmbeddedArtifacts.getEmbeddedArtifacts(javaProject.getProject()); for (IClasspathEntryDescriptor entry : cp) { if (isBundleClasspathEntry(classpathMap, entry)) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: addProjectEntries(resolved, entry.getPath(), CLASSPATH_SCOPE, getArtifactClassifier(entry), monitor); break; case IClasspathEntry.CPE_LIBRARY: resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath())); break; } } } return resolved; }
From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java
License:Open Source License
/** * Load the {@link ConfigMetadataRepository} with the metadata of the current * classpath using the {@link #DEFAULT_LOCATION_PATTERN}. If the same config * metadata items is held within different resources, the first that is * loaded is kept which means the result is not deterministic. *///w ww.j av a 2 s . com public ConfigurationMetadataRepository load(IJavaProject project) throws Exception { debug(">> load ConfigurationMetadataRepository for " + project.getElementName()); IClasspathEntry[] classpath = project.getResolvedClasspath(true); for (IClasspathEntry e : classpath) { int ekind = e.getEntryKind(); int ckind = e.getContentKind(); IPath path = e.getPath(); if (ekind == IClasspathEntry.CPE_LIBRARY && ckind == IPackageFragmentRoot.K_BINARY) { //jar file dependency File jarFile = path.toFile(); if (FileUtil.isJarFile(jarFile)) { loadFromJar(jarFile); } } else if (ekind == IClasspathEntry.CPE_PROJECT) { loadFromProjectDependency(e); } else { debug("Skipped: " + ekind(ekind) + " " + ckind(ckind) + ": " + path); } } loadFromOutputFolder(project); debug("<< load ConfigurationMetadataRepository for " + project.getElementName() + ": " + repository.getAllProperties().size() + " properties"); return repository; }
From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java
License:Open Source License
private String ekind(int ekind) { switch (ekind) { case IClasspathEntry.CPE_SOURCE: return "SRC"; case IClasspathEntry.CPE_LIBRARY: return "LIB"; case IClasspathEntry.CPE_PROJECT: return "PRJ"; case IClasspathEntry.CPE_VARIABLE: return "VAR"; case IClasspathEntry.CPE_CONTAINER: return "CON"; default://from w ww. j a v a2s . co m return "" + ekind; } }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil.java
License:Open Source License
private static List<CPE> createCpes(Set<String> systemLibs, IJavaProject javaProject, IClasspathEntry entry) throws MalformedURLException, JavaModelException { String kind = toContentKind(entry); switch (kind) { case Classpath.ENTRY_KIND_BINARY: { String path = entry.getPath().toString(); CPE cpe = CPE.binary(path);//from w ww .j a va 2 s . c om if (systemLibs.contains(path)) { cpe.setSystem(true); } IPath sp = entry.getSourceAttachmentPath(); if (sp != null) { cpe.setSourceContainerUrl(sp.toFile().toURI().toURL()); // TODO: // IPath srp = entry.getSourceAttachmentRootPath(); // if (srp!=null) { // // } } return Collections.singletonList(cpe); } case Classpath.ENTRY_KIND_SOURCE: { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = entry.getPath(); return resolveDependencyProjectCPEs(projectPath); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { CPE cpe = createSourceCPE(javaProject, entry); cpe.setOwn(true); return cpe == null ? null : Collections.singletonList(cpe); } } default: break; } return Collections.emptyList(); }
From source file:org.springsource.ide.eclipse.commons.ui.SpringPropertyTester.java
License:Open Source License
public static boolean isSpringProject(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath path = e.getPath();/*from www . ja va 2 s . c om*/ String name = path.lastSegment(); return name.startsWith("spring-context"); } return false; }