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.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Constructor for ImprovedClasspathHandler * @param project the Java project that we will generate a build file for * @param root the ImprovedClasspathHandler object for the project (this is the root of the recursive tree that we build from projects having dependencies) * @param exclSysLibs if true, Java system libraries get copied into the package at submission * @param subMonitor submonitor for tracking progress *//* w w w. j a va2 s .c o m*/ public ImprovedClasspathHandler(IJavaProject project, ImprovedClasspathHandler root, boolean exclSysLibs, SubMonitor subMonitor) { this.excludeSysLibs = exclSysLibs; sources = new ArrayList<IClasspathEntry>(); libs = new ArrayList<IClasspathEntry>(); systemLibs = new ArrayList<IClasspathEntry>(); dependentProjects = new ArrayList<ImprovedClasspathHandler>(); exportedEntries = new ArrayList<IClasspathEntry>(); this.project = project; this.srcVersion = this.project.getOption(SOURCE_VERSION_OPTION, true); this.targetVersion = this.project.getOption(TARGET_VERSION_OPTION, true); if (root == null) { this.root = this; this.subMonitor = subMonitor; this.subMonitor.setWorkRemaining(100); visitedProjects = new HashMap<String, ImprovedClasspathHandler>(); SWAMPBIN_PATH = setupBinDir(project.getProject()); filesToArchive = new HashSet<String>(); } else { this.root = root; visitedProjects = root.visitedProjects; SWAMPBIN_PATH = root.SWAMPBIN_PATH; filesToArchive = root.filesToArchive; } try { project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, null); } catch (CoreException e1) { // TODO Auto-generated catch block System.err.println("Unable to do a clean build on the project for some reason"); e1.printStackTrace(); } IClasspathEntry[] entries = null; try { entries = project.getRawClasspath(); if (entries == null || entries.length == 0) { return; } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); try { for (IClasspathEntry entry : entries) { int kind = entry.getEntryKind(); if (this.subMonitor != null) { if (this.subMonitor.isCanceled()) { System.out.println("Sub monitor got cancelled!"); } this.subMonitor.split(100 / SwampSubmitter.CLASSPATH_ENTRY_TICKS); } if (kind == IClasspathEntry.CPE_SOURCE) { handleSource(entry, wsRoot); } else if (kind == IClasspathEntry.CPE_LIBRARY) { handleLibrary(entry, wsRoot); } else if (kind == IClasspathEntry.CPE_PROJECT) { handleProject(entry, wsRoot); } else if (kind == IClasspathEntry.CPE_VARIABLE) { handleVariable(entry, wsRoot); } else { // kind == IClasspathEntry.CPE_CONTAINER handleContainer(entry, wsRoot); } } } catch (IOException | JavaModelException e) { // TODO Report this error! This is very bad e.printStackTrace(); } if (hasSwampbinDependencies) { filesToArchive.add(SWAMPBIN_PATH.toOSString()); } }
From source file:org.drools.eclipse.builder.DroolsBuilder.java
License:Apache License
private IProject[] getRequiredProjects(IProject project) { IJavaProject javaProject = JavaCore.create(project); List projects = new ArrayList(); try {/*from ww w. j a v a2 s .c o m*/ IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = project.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); // missing projects are considered too if (p != null && !projects.contains(p)) { projects.add(p); } } } } catch (JavaModelException e) { return new IProject[0]; } return (IProject[]) projects.toArray(new IProject[projects.size()]); }
From source file:org.ebayopensource.turmeric.eclipse.buildsystem.utils.BuilderUtil.java
License:Open Source License
/** * Returns the required project for any given project. Scans the build bath * and finds all the project references and returns it back. * * @param project the project// w w w . ja v a 2 s. c o m * @param natureIds the nature ids * @return the required projects */ public static IProject[] getRequiredProjects(IProject project, String... natureIds) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) return new IProject[0]; ArrayList<IProject> projects = new ArrayList<IProject>(); try { for (final IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject reqProject = WorkspaceUtil.getProject(entry.getPath()); if (reqProject != null && !projects.contains(reqProject)) { if (natureIds != null) { for (String natureId : natureIds) { if (reqProject.hasNature(natureId)) { projects.add(reqProject); break; } } } else { projects.add(reqProject); } } } } } catch (Exception e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
private static void resolveClasspathToURLs(final IJavaProject javaProject, final Set<URL> resolvedEntries, final Set<String> visited) throws JavaModelException, IOException { if (javaProject == null || !javaProject.exists()) return;//w w w. ja v a 2 s . co m final String projectName = javaProject.getProject().getName(); if (visited.contains(projectName)) return; visited.add(projectName); for (final IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { resolveClasspathToURLs(JavaCore.create(WorkspaceUtil.getProject(entry.getPath())), resolvedEntries, visited); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { resolvedEntries.add(WorkspaceUtil.getLocation(entry.getPath()).toFile().toURI().toURL()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); if (location.toString().startsWith(WorkspaceUtil.PATH_SEPERATOR + projectName)) { //it happens that the path is not absolute location = javaProject.getProject().getFolder(location.removeFirstSegments(1)).getLocation(); } resolvedEntries.add(location.toFile().toURI().toURL()); } } }
From source file:org.ebayopensource.vjet.eclipse.core.ClassPathUtils.java
License:Open Source License
public static URL[] getProjectDependencyUrls(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }/*w w w . j av a 2 s . 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); for (IClasspathEntry entry : entries) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURI().toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (projectDependencyUrlList.contains(entryUrl) == false) { projectDependencyUrlList.add(entryUrl); } break; 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(); // throw new EclipseProjectNotFoundException( // projectName, // MessageFormat // .format( // "The dependent project {0} of project {1} is not // available.\nPlease update your workspace to include // this project", // projectName, parentProjectName)); } 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(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; default: break; } } IPath path = project.getOutputLocation(); IPath projectResourceLocation = project.getResource().getLocation(); File projectFilePath = projectResourceLocation.append(path.removeFirstSegments(1)).toFile(); URL projectOutputUrl; projectOutputUrl = projectFilePath.toURI().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 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>(); }// w ww . j a v a 2s .c o 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;//from w w w . ja va2 s.c om 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
public static void getTransitiveClosureProjectDependnecyList(IJavaProject javaProject, Map<String, IJavaProject> transitiveClosureProjectList) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true); if (classPathEntries != null) { for (IClasspathEntry classPathEntry : classPathEntries) { if (classPathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IResource classPathProject = ResourcesPlugin.getWorkspace().getRoot() .findMember(classPathEntry.getPath()); if (classPathProject != null) { if (!transitiveClosureProjectList.containsKey(classPathProject.getName())) { IJavaProject subJavaProject = getJavaProject(classPathProject); transitiveClosureProjectList.put(classPathProject.getName(), subJavaProject); getTransitiveClosureProjectDependnecyList(subJavaProject, transitiveClosureProjectList); }//from w w w . jav a 2 s . c o m } } } } }
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./* ww w . ja 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.// w w w .ja va 2s .c o m */ 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); } }