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.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static URL[] getProjectDependencyUrls_bak(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }//from w w w .j a v a 2s. co m for (IJavaProject project : javaProjectList) { if (projectMap.containsKey(project.getElementName()) == true) { continue; } else { projectMap.put(project.getElementName(), project.getElementName()); } // Add the dependencies to the URL list // IClasspathEntry[] entries; // entries = project.getResolvedClasspath(true); IClasspathEntry[] entries2; entries2 = project.getRawClasspath(); for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToList(entry, projectDependencyUrlList); case IClasspathEntry.CPE_PROJECT: List<IJavaProject> subjavaProjectList = new ArrayList<IJavaProject>(); IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource == null) { String projectName = entry.getPath().toString(); String parentProjectName = project.getElementName(); } if (subResource != null && subResource.getType() == IResource.PROJECT) { IProject subProject = (IProject) subResource; IJavaProject subJavaProject = JavaCore.create(subProject); if (subJavaProject != null && subJavaProject.exists()) { subjavaProjectList.add(subJavaProject); // Recursively call our selves to populate the // project // dependency's for the sub projects. getProjectDependencyUrls_bak(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.toOSString())) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToList(entries[i], projectDependencyUrlList); } } } break; default: break; } } // // IPath path = project.getOutputLocation(); // IPath projectResourceLocation = // project.getResource().getLocation(); // File projectFilePath = projectResourceLocation.append( // path.removeFirstSegments(1)).toFile(); // URL projectOutputUrl; // projectOutputUrl = projectFilePath.toURL(); // // if (projectDependencyUrlList.contains(projectOutputUrl) == false) // { // projectDependencyUrlList.add(projectOutputUrl); // } } URL[] arrayList = new URL[projectDependencyUrlList.size()]; URL[] returnURLArray = projectDependencyUrlList.toArray(arrayList); return returnURLArray; }
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static List<IBuildpathEntry> fetchBuildEntryFromJavaProject(IJavaProject javaProject) { // Project entry List<IBuildpathEntry> vEntries = new ArrayList<IBuildpathEntry>(); List<String> duplicateChecker = new ArrayList<String>(); IClasspathEntry[] entries2;/*w w w . j a v a 2 s . c o m*/ try { entries2 = javaProject.getRawClasspath(); } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java prjoect classpath: " + javaProject.getElementName(), e, IStatus.WARNING); return Collections.emptyList(); } for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); String sPath = path.toString(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToVJETEntry(entry, vEntries, duplicateChecker); case IClasspathEntry.CPE_PROJECT: IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource != null && subResource.getType() == IResource.PROJECT) { addProjectEntry(entry.getPath(), vEntries, duplicateChecker); } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.segment(0))) { IClasspathContainer container; try { container = JavaCore.getClasspathContainer(path, javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToVJETEntry(entries[i], vEntries, duplicateChecker); } } } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java classpath container: " + sPath, e, IStatus.WARNING); } } break; default: break; } } return vEntries; }
From source file:org.ebayopensource.vjet.eclipse.internal.launching.LauncherUtil.java
License:Open Source License
private static void getProjectDependentJars(Set<String> jars, IClasspathEntry[] classPathEntries) { if (classPathEntries != null) { for (IClasspathEntry classPathEntry : classPathEntries) { if (classPathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || classPathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IPath path = JavaCore.getResolvedClasspathEntry(classPathEntry).getPath(); if (path != null) { String s = path.toString(); if (!StringUtils.isBlankOrEmpty(s)) { jars.add(s);/*from w w w. j av a 2 s . c om*/ } } } } } }
From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java
License:Open Source License
/** * Merge the supplied project's classpath with entries found in the specified * build file.//from w w w. j a v a 2 s.c o m * * @param project The project. * @param buildfile The path to the build file (pom.xml, ivy.xml, etc) * @return The classpath entries. */ protected IClasspathEntry[] mergeWithBuildfile(IJavaProject project, String buildfile) throws Exception { String filename = FileUtils.getBaseName(buildfile); Parser parser = PARSERS.get(filename); String var = parser.getClasspathVar(); Dependency[] dependencies = parser.parse(buildfile); IWorkspaceRoot root = project.getProject().getWorkspace().getRoot(); ArrayList<IClasspathEntry> results = new ArrayList<IClasspathEntry>(); // load the results with all the non library entries. IClasspathEntry[] entries = project.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY && entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) { results.add(entry); } else { IPath path = entry.getPath(); String prefix = path != null ? path.segment(0) : null; if ((!var.equals(prefix)) || preserve(entry)) { results.add(entry); } } } // merge the dependencies with the classpath entires. for (int ii = 0; ii < dependencies.length; ii++) { IClasspathEntry match = null; for (int jj = 0; jj < entries.length; jj++) { if (entries[jj].getEntryKind() == IClasspathEntry.CPE_LIBRARY || entries[jj].getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String path = entries[jj].getPath().toOSString(); String pattern = dependencies[ii].getName() + Dependency.VERSION_SEPARATOR; // exact match if (path.endsWith(dependencies[ii].toString())) { match = entries[jj]; results.add(entries[jj]); break; // different version match } else if (path.indexOf(pattern) != -1) { break; } } else if (entries[jj].getEntryKind() == IClasspathEntry.CPE_PROJECT) { String path = entries[jj].getPath().toOSString(); if (path.endsWith(dependencies[ii].getName())) { match = entries[jj]; break; } } } if (match == null) { IClasspathEntry entry = createEntry(root, project, dependencies[ii]); results.add(entry); } else { match = null; } } return (IClasspathEntry[]) results.toArray(new IClasspathEntry[results.size()]); }
From source file:org.eclim.plugin.jdt.util.ClasspathUtils.java
License:Open Source License
/** * Recursively collects classpath entries from the current and dependent * projects.//from w w w . ja v a2 s .c om */ private static void collect(IJavaProject javaProject, List<String> paths, Set<IJavaProject> visited, boolean isFirstProject) throws Exception { if (visited.contains(javaProject)) { return; } visited.add(javaProject); try { IPath out = javaProject.getOutputLocation(); paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } catch (JavaModelException ignore) { // ignore... just signals that no output dir was configured. } IProject project = javaProject.getProject(); String name = project.getName(); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException jme) { // this may or may not be a problem. logger.warn("Unable to retrieve resolved classpath for project: " + name, jme); return; } final List<IJavaProject> nextProjects = new ArrayList<IJavaProject>(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: String path = entry.getPath().toOSString().replace('\\', '/'); if (path.startsWith("/" + name + "/")) { path = ProjectUtils.getFilePath(project, path); } paths.add(path); break; case IClasspathEntry.CPE_PROJECT: if (isFirstProject || entry.isExported()) { javaProject = JavaUtils.getJavaProject(entry.getPath().segment(0)); if (javaProject != null) { // breadth first, not depth first, to preserve dependency ordering nextProjects.add(javaProject); } } break; case IClasspathEntry.CPE_SOURCE: IPath out = entry.getOutputLocation(); if (out != null) { paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } break; } } // depth second for (final IJavaProject nextProject : nextProjects) { collect(nextProject, paths, visited, false); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the aspect path *///from w ww . jav a2 s .c o m public static boolean isOnAspectpath(IProject project, String path) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(path)) { if (isOnAspectpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static List<IClasspathEntry> resolveClasspathContainer(IClasspathEntry classpathContainerEntry, IProject thisProject) throws JavaModelException { IJavaProject thisJavaProject = JavaCore.create(thisProject); IClasspathContainer container = JavaCore.getClasspathContainer(classpathContainerEntry.getPath(), thisJavaProject);/*from ww w .j a v a 2s . co m*/ if (container != null) { List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int i = 0; i < containerEntries.length; i++) { // projects must be resolved specially since the AspectJ doesn't understand the // concept of project switch (containerEntries[i].getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IProject requiredProj = thisProject.getWorkspace().getRoot() .getProject(containerEntries[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(thisProject.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(containerEntries[i], requiredProj)); } break; case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore .getResolvedClasspathEntry(containerEntries[i]); if (resolvedClasspathEntry != null) { actualEntries.add(resolvedClasspathEntry); } break; case IClasspathEntry.CPE_CONTAINER: // not sure if we can have this, but try anyway actualEntries.addAll(resolveClasspathContainer(containerEntries[i], thisProject)); break; case IClasspathEntry.CPE_LIBRARY: actualEntries.add(containerEntries[i]); break; default: // do nothing } } return actualEntries; } else { return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Resolves a single classpath entry//from w ww .j a va2 s .co m * @param entry the classpath entry to resolve * @param thisProject the java project that has this entry * @return the resolved list of classpath entries * @throws JavaModelException */ public static List<IClasspathEntry> resolveClasspath(IClasspathEntry entry, IProject thisProject) throws JavaModelException { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: return resolveClasspathContainer(entry, thisProject); case IClasspathEntry.CPE_LIBRARY: return Collections.singletonList(entry); case IClasspathEntry.CPE_PROJECT: IProject containedProj = thisProject.getWorkspace().getRoot() .getProject(entry.getPath().makeRelative().toPortableString()); if (!containedProj.getName().equals(thisProject.getName()) && containedProj.exists()) { return resolveDependentProjectClasspath(entry, containedProj); } else { return Collections.emptyList(); } case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(entry); if (resolvedClasspathEntry != null) { return Collections.singletonList(resolvedClasspathEntry); } else { return Collections.emptyList(); } default: return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the Inpath *//*from w w w . j ava2 s . co m*/ public static boolean isOnInpath(IProject project, String jarPath) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(jarPath)) { if (isOnInpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project/*from w ww . j a v a2 s . c o m*/ * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }