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.springframework.ide.eclipse.core.java.ProjectClassLoaderCache.java
License:Open Source License
/** * Add {@link URL}s to the given set of <code>paths</code>. *//* w w w . j av a 2 s .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.springsource.ide.eclipse.commons.ui.SpringPropertyTester.java
License:Open Source License
public static boolean isSpringJar(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath();/*from w ww . j av a 2 s . c o m*/ String name = path.lastSegment(); return name.endsWith(".jar") && name.startsWith("spring-context"); } return false; }
From source file:org.springsource.ide.eclipse.gradle.core.ClassPath.java
License:Open Source License
/** * Removes all library entries from this classpath. */ public void removeLibraryEntries() { entryMap.remove(IClasspathEntry.CPE_LIBRARY); }
From source file:org.springsource.ide.eclipse.gradle.core.ClassPath.java
License:Open Source License
public IClasspathEntry[] getLibraryEntries() { Collection<IClasspathEntry> entries = getEntries(IClasspathEntry.CPE_LIBRARY); return entries.toArray(new IClasspathEntry[entries.size()]); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleImportTests.java
License:Open Source License
/** * Verify that project classpath does not have plain jar entries on it (all jars are managed in classpath containers). * @throws JavaModelException // w ww . j a va 2 s . c o m */ public static void assertNoRawLibraryEntries(IJavaProject project) throws JavaModelException { IClasspathEntry[] classpath = project.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { fail("Raw classpath of project " + project.getElementName() + " has a library entry: " + entry); } } }
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(/* ww w . j av a 2s . co m*/ 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 assertClasspathJarEntry(String jarFile, IClasspathEntry[] resolvedClasspath) { StringBuilder msg = new StringBuilder(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath();//w ww . ja v a 2 s. c o m if (jarFile.equals(path.lastSegment())) { return; //OK } msg.append(e + "\n"); } } fail("Not found '" + jarFile + "':\n" + msg.toString()); }
From source file:org.springsource.ide.eclipse.gradle.core.test.GradleTest.java
License:Open Source License
public static void assertNoClasspathJarEntry(String jarFile, IClasspathEntry[] resolvedClasspath) { for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath();//from w w w .j a va 2s .co m if (jarFile.equals(path.lastSegment())) { fail("Found '" + jarFile + "'\n"); } } } //ok! }
From source file:org.switchyard.tools.cxf.Activator.java
License:Open Source License
static ClassLoader getProjectBuildClassLoader(IJavaProject javaProject) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(//w w w .j a va 2s . c o m new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-1$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = classpathEntry.getPath(); if (!BLACKLIST.matcher(path.lastSegment()).find()) { urls.add(new File(path.toOSString()).toURI().toURL()); } } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), Activator.class.getClassLoader()); }
From source file:org.switchyard.tools.cxf.Java2WSDLOperation.java
License:Open Source License
private ClassLoader getProjectBuildClassLoader(IType interfaceType) throws Exception { IJavaProject javaProject = interfaceType.getJavaProject(); IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(// w ww .jav a2 s . co m new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }