List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java
License:Apache License
private void getClassPathEntries(IJavaProject prj, ArrayList data, List selectedPaths, ArrayList visitedProjects) { IClasspathEntry[] entries = null;/*w ww. j a v a 2 s .c o m*/ IPath outputPath = null; try { outputPath = prj.getOutputLocation(); if (selectedPaths.contains(outputPath.toFile().toString().replace('\\', '/'))) { add(data, prj.getProject().getWorkspace().getRoot().findMember(outputPath)); } entries = prj.getRawClasspath(); } catch (JavaModelException e) { DbfLauncherPlugin.log(e); } if (entries == null) return; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { path = entry.getOutputLocation(); if (path == null) continue; } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = entry.getPath().lastSegment(); if (!visitedProjects.contains(prjName)) { visitedProjects.add(prjName); getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths, visitedProjects); } continue; } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/'))) continue; IClasspathEntry[] tmpEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { try { tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries(); } catch (JavaModelException e1) { DbfLauncherPlugin.log(e1); continue; } } else { tmpEntry = new IClasspathEntry[1]; tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry); } for (int j = 0; j < tmpEntry.length; j++) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath()); if (res != null) add(data, res); else add(data, tmpEntry[j].getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcPath = entry.getOutputLocation(); if (srcPath != null && !srcPath.equals(outputPath)) { add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath)); } } else { add(data, tmpEntry[j].getPath()); } } } }
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 av a2 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.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a variable entry in the classpath. A variable entry can be resolved to either a library entry or a project entry * @param entry the variable entry/*from w ww . j a v a 2 s . co m*/ * @param root the workspace entry * @throws IOException */ private void handleVariable(IClasspathEntry entry, IWorkspaceRoot root) throws IOException { IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(entry); if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { handleLibrary(resolvedEntry, root); } else { handleProject(resolvedEntry, root); } }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a container entry in the classpath. A container entry contains 1+ entries each of which is either a library entry or a project entry * @param entry the container entry//from ww w . j a v a 2 s.com * @param root the workspace root * @throws IOException * @throws JavaModelException */ public void handleContainer(IClasspathEntry entry, IWorkspaceRoot root) throws IOException, JavaModelException { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); System.out.println("Here's a container" + container); int kind = container.getKind(); if ((this.excludeSysLibs) && (kind == IClasspathContainer.K_APPLICATION || kind == IClasspathContainer.K_DEFAULT_SYSTEM)) { System.out.println("System library container"); System.out.println(entry.getPath()); return; } for (IClasspathEntry subEntry : container.getClasspathEntries()) { if (subEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { handleLibrary(subEntry, root); } else { handleProject(subEntry, root); } } }
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 {/* www .j a va 2 s .com*/ 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.drools.eclipse.util.ProjectClassLoader.java
License:Apache License
public static List<URL> getProjectClassPathURLs(IJavaProject project, List<String> alreadyLoadedProjects) { List<URL> pathElements = new ArrayList<URL>(); try {/*from www . j av a 2 s. co m*/ IClasspathEntry[] paths = project.getResolvedClasspath(true); Set<IPath> outputPaths = new HashSet<IPath>(); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = getRawLocationURL(path.getPath()); pathElements.add(url); } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = path.getOutputLocation(); if (path.getOutputLocation() != null) { outputPaths.add(output); } } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); for (IPath path : outputPaths) { outputPath = location.append(path.removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); } // also add classpath of required projects for (String projectName : project.getRequiredProjectNames()) { if (!alreadyLoadedProjects.contains(projectName)) { alreadyLoadedProjects.add(projectName); IProject reqProject = project.getProject().getWorkspace().getRoot().getProject(projectName); if (reqProject != null) { IJavaProject reqJavaProject = JavaCore.create(reqProject); pathElements.addAll(getProjectClassPathURLs(reqJavaProject, alreadyLoadedProjects)); } } } } catch (JavaModelException e) { DroolsEclipsePlugin.log(e); } catch (MalformedURLException e) { DroolsEclipsePlugin.log(e); } catch (Throwable t) { DroolsEclipsePlugin.log(t); } return pathElements; }
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 va2 s . co 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.errorlibrary.buildsystem.core.ErrorLibraryBuildSystemConfigurer.java
License:Open Source License
/** * Adds the java support.//w ww . ja v a 2 s. c o m * * @param errorLibraryProject the error library project * @param outputLocation the output location * @param monitor the monitor * @throws CoreException the core exception */ public static void addJavaSupport(SOAErrorLibraryProject errorLibraryProject, String outputLocation, IProgressMonitor monitor) throws CoreException { final IProject project = errorLibraryProject.getProject(); boolean changedClasspath = false; if (JDTUtil.addJavaNature(project, monitor)) { changedClasspath = true; } // Configuring the Java Project final IJavaProject javaProject = JavaCore.create(project); final List<IClasspathEntry> classpath = JDTUtil.rawClasspath(javaProject, true); final List<IClasspathEntry> classpathContainers = new ArrayList<IClasspathEntry>(); // TODO Lets see if we need this if (outputLocation.equals(javaProject.getOutputLocation()) == false) { final IFolder outputDirClasses = project.getFolder(outputLocation); javaProject.setOutputLocation(outputDirClasses.getFullPath(), monitor); changedClasspath = true; } // Dealing with the case where the root of the project is set to be the // src and bin destinations... bad... bad... for (final Iterator<IClasspathEntry> iterator = classpath.iterator(); iterator.hasNext();) { final IClasspathEntry entry = iterator.next(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { classpathContainers.add(entry); } if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE || !entry.getPath().equals(new Path("/" + project.getName()))) continue; iterator.remove(); changedClasspath |= true; } for (final SOAProjectSourceDirectory dir : errorLibraryProject.getSourceDirectories()) { if (!WorkspaceUtil.isDotDirectory(dir.getLocation())) { final IFolder source = project.getFolder(dir.getLocation()); // If the Java project existed previously, checking if // directories // already exist in // its classpath. boolean found = false; for (final IClasspathEntry entry : classpath) { if (!entry.getPath().equals(source.getFullPath())) continue; found = true; break; } if (found) continue; changedClasspath |= true; IPath[] excludePatterns = ClasspathEntry.EXCLUDE_NONE; if (dir.getExcludePatterns() != null) { int length = dir.getExcludePatterns().length; excludePatterns = new Path[length]; for (int i = 0; i < length; i++) { excludePatterns[i] = new Path(dir.getExcludePatterns()[i]); } } IPath outputPath = dir.getOutputLocation() != null ? project.getFolder(dir.getOutputLocation()).getFullPath() : null; final IClasspathEntry entry = JavaCore.newSourceEntry(source.getFullPath(), excludePatterns, outputPath); classpath.add(entry); } } ProgressUtil.progressOneStep(monitor); // Adding the runtime library boolean found = false; for (final IClasspathEntry entry : classpath) { // All JRE Containers should have a prefix of // org.eclipse.jdt.launching.JRE_CONTAINER if (JavaRuntime.newDefaultJREContainerPath().isPrefixOf(entry.getPath()) && JavaRuntime.newDefaultJREContainerPath().equals(entry.getPath())) { found = true; break; } } if (!found) { changedClasspath = true; classpath.add(JavaRuntime.getDefaultJREContainerEntry()); } // we want all classpath containers to be the end of .classpath file classpath.removeAll(classpathContainers); classpath.addAll(classpathContainers); ProgressUtil.progressOneStep(monitor); // Configuring the classpath of the Java Project if (changedClasspath) { javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), null); } }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
/** * Gets the maven2 classpath container.// w w w. j a va 2 s . com * * @param project the project * @return the maven2 classpath container * @throws JavaModelException the java model exception */ public static IClasspathContainer getMaven2ClasspathContainer(IJavaProject project) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && isMaven2ClasspathContainer(entry.getPath())) { return JavaCore.getClasspathContainer(entry.getPath(), project); } } return null; }
From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAConsumerUtil.java
License:Open Source License
/** * Fill metadata./*from w w w.j a va 2 s. co m*/ * * @param consumerProject the consumer project * @param serviceNames the service names * @return the sOA consumer project * @throws Exception the exception */ public static SOAConsumerProject fillMetadata(final SOAConsumerProject consumerProject, final List<String> serviceNames) throws Exception { final List<SOAProjectSourceDirectory> entries = new ArrayList<SOAProjectSourceDirectory>(); for (final IClasspathEntry entry : JDTUtil.rawClasspath(consumerProject.getProject(), false)) { if (entry == null || entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; final String path = entry.getPath().removeFirstSegments(1).toString(); entries.add(new SOAProjectSourceDirectory(path)); } consumerProject.setSourceDirectories(entries); if (serviceNames != null) { if (consumerProject instanceof SOAConsumerProject) { ((SOAConsumerProject) consumerProject).getMetadata().setServiceNames(serviceNames); } for (final String serviceName : serviceNames) { final IProject intfProject = WorkspaceUtil.getProject(serviceName); if (intfProject != null && intfProject.isAccessible()) { SOAIntfMetadata intfMetadata = SOAServiceUtil .getSOAIntfMetadata(SOAServiceUtil.getSOAEclipseMetadata(intfProject)); intfMetadata.setServiceName(serviceName); SOAIntfUtil.fillMetadata(intfProject, intfMetadata); consumerProject.getRequiredServices().put(serviceName, intfMetadata); } } } return consumerProject; }