List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath
IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;
From source file:org.springframework.ide.eclipse.boot.core.BootPropertyTester.java
License:Open Source License
public static boolean isBootProject(IProject project) { if (project == null || !project.isAccessible()) { return false; }//from ww w. java 2 s . co m try { if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(project); IClasspathEntry[] classpath = jp.getResolvedClasspath(true); //Look for a 'spring-boot' jar entry for (IClasspathEntry e : classpath) { if (isBootJar(e)) { return true; } } } } catch (Exception e) { CorePlugin.log(e); } return false; }
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. *///from w ww .j a v a 2s . 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.util.JavaProjectUtil.java
License:Open Source License
/** * Retrieve the source folders in a given IJavaProject. Note that the source folders * might not all be IFolder instances because it is possible for an IJavaProject's root to * be a source folder. In this case the 'folder' will be an IProject instance instead of * a IFolder./*from w w w .ja v a 2 s .c om*/ */ public static IContainer[] getSourceFolders(IJavaProject jp) { try { ArrayList<IContainer> sourceFolders = new ArrayList<IContainer>(); IClasspathEntry[] cp = jp.getResolvedClasspath(true); for (IClasspathEntry cpe : cp) { try { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IContainer sf = getProjectOrFolder(cpe.getPath()); if (sf != null) { sourceFolders.add(sf); } } } catch (Exception e) { BootActivator.log(e); } } return sourceFolders.toArray(new IContainer[sourceFolders.size()]); } catch (Exception e) { BootActivator.log(e); return new IContainer[0]; } }
From source file:org.springframework.ide.eclipse.core.java.ProjectClassLoaderCache.java
License:Open Source License
/** * Add {@link URL}s to the given set of <code>paths</code>. *///from w w w. j a va 2s . c o m private static void addClassPathUrls(IProject project, List<URL> paths, Set<IProject> resolvedProjects) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // add project to local cache to prevent adding its classpaths multiple times if (resolvedProjects.contains(project)) { return; } else { resolvedProjects.add(project); } try { if (JdtUtils.isJavaProject(project)) { IJavaProject jp = JavaCore.create(project); // configured classpath IClasspathEntry[] classpath = jp.getResolvedClasspath(true); // add class path entries for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = path.getPath(); File file = entryPath.toFile(); if (file.exists()) { paths.add(file.toURI().toURL()); } else { // case for project relative links String projectName = entryPath.segment(0); IProject pathProject = root.getProject(projectName); covertPathToUrl(pathProject, paths, entryPath); } } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // add source path as well for non java resources IPath sourcePath = path.getPath(); covertPathToUrl(project, paths, sourcePath); // add source output locations for different source // folders IPath sourceOutputPath = path.getOutputLocation(); covertPathToUrl(project, paths, sourceOutputPath); } } // add all depending java projects for (IJavaProject p : JdtUtils.getAllDependingJavaProjects(jp)) { addClassPathUrls(p.getProject(), paths, resolvedProjects); } // get default output directory IPath outputPath = jp.getOutputLocation(); covertPathToUrl(project, paths, outputPath); } else { for (IProject p : project.getReferencedProjects()) { addClassPathUrls(p, paths, resolvedProjects); } } } catch (Exception e) { // ignore } }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil.java
License:Open Source License
public static Classpath resolve(IJavaProject javaProject, Logger logger) throws Exception { //log("resolving classpath " + javaProject.getElementName() +" ..."); List<CPE> cpEntries = new ArrayList<>(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); Set<String> systemLibs = getSystemLibraryPaths(javaProject); if (entries != null) { for (IClasspathEntry entry : entries) { try { cpEntries.addAll(createCpes(systemLibs, javaProject, entry)); } catch (Exception e) { logger.log(e);/* w ww . jav a 2 s. c o m*/ } } } Classpath classpath = new Classpath(cpEntries); logger.log("classpath=" + classpath.getEntries().size() + " entries"); return classpath; }
From source file:org.springsource.ide.eclipse.commons.tests.util.StsTestUtil.java
License:Open Source License
public static void dumpClasspathInfo(IJavaProject javaProject, PrintStream out) throws JavaModelException { out.println(">>>>> classpath for " + javaProject.getElementName()); out.println("RAW classpath for " + javaProject.getElementName()); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry e : entries) { out.println(e);//from w w w. j ava 2 s . com } out.println("RESOLVED classpath for " + javaProject.getElementName()); entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry e : entries) { out.println(e); } out.println("<<<<<< classpath for " + javaProject.getElementName()); }
From source file:org.springsource.ide.eclipse.commons.ui.SpringPropertyTester.java
License:Open Source License
public static boolean isSpringProject(IProject project) { if (project == null || !project.isAccessible()) { return false; }/*w w w. j a v a 2 s . co m*/ try { if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(project); IClasspathEntry[] classpath = jp.getResolvedClasspath(true); // Look for a 'spring-boot' jar or project entry for (IClasspathEntry e : classpath) { if (isSpringJar(e) || isSpringProject(e)) { return true; } } } } catch (Exception e) { CorePlugin.log(e); } return false; }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleImportTests.java
License:Open Source License
public void testSTS2185AddWebAppLibrariesContainerToWTPProjects() throws Exception { String[] projectNames = { "sts2185", "A", "B" }; importTestProject(projectNames[0]);// w w w . ja v a 2 s. c o m assertProjects(projectNames); new ACondition("testSTS2185AddWebAppLibrariesContainerToWTPProjects") { @Override public boolean test() throws Exception { ///////////////////// //Check project A: { IJavaProject project = getJavaProject("A"); IClasspathEntry[] rawClasspath = project.getRawClasspath(); IClasspathEntry[] resolvedClasspath = project.getResolvedClasspath(false); //Can we find the expected class path container? assertClasspathContainer(rawClasspath, WTPUtil.JST_J2EE_WEB_CONTAINER); //Can we find 'junk.jar' from the WEB-INF/lib directory of project A. assertClasspathJarEntry("junk.jar", resolvedClasspath); } ///////////////////// //Check project B: { IJavaProject project = getJavaProject("B"); IClasspathEntry[] rawClasspath = project.getRawClasspath(); //It is a WTP project... assertTrue(WTPUtil.isWTPProject(project.getProject())); //... but shouldn't have libraries container because not a jst.web project. assertNoClasspathContainer(rawClasspath, WTPUtil.JST_J2EE_WEB_CONTAINER); } return true; } }.waitFor(10000); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertJarEntry(IJavaProject project, String jarName, boolean expectSource) throws JavaModelException { IClasspathEntry[] classpath = project.getResolvedClasspath(false); StringBuffer seen = new StringBuffer(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { seen.append(entry.getPath() + "\n"); if (entry.getPath().toString().endsWith(jarName)) { //Found the jar! IPath sourcePath = entry.getSourceAttachmentPath(); if (expectSource) { assertNotNull(entry.getPath() + " has no source attachement", sourcePath); assertTrue(/* w ww.j av a 2 s . c om*/ entry.getPath() + " has source attachement " + sourcePath + " but it doesn't exist", sourcePath.toFile().exists()); } return; //OK } } } fail("Jar entry not found: " + jarName + "\nfound: " + seen.toString()); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertNoClasspathJarEntry(String string, IJavaProject jp) throws JavaModelException { assertNoClasspathJarEntry(string, jp.getResolvedClasspath(true)); }