List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.StandaloneRuntimeResolver.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *//*from w ww. j a va 2 s. com*/ protected Collection<IClasspathEntry> getSourceEntries(boolean istest) { try { IClasspathEntry[] rawEntries = javaProject.getRawClasspath(); if (rawEntries != null) { Collection<IClasspathEntry> sourceEntries = new HashSet<IClasspathEntry>(); for (IClasspathEntry entry : rawEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path != null) { boolean isTestSource = isTestSource(path.toOSString()); if ((istest && isTestSource) || (!istest && !isTestSource)) { sourceEntries.add(entry); } } } } return sourceEntries; } } catch (JavaModelException e) { CloudFoundryPlugin.log(e); } return Collections.emptyList(); }
From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.startcommand.JavaTypeUIAdapter.java
License:Open Source License
public IPackageFragment getDefaultPackageFragment(IJavaProject javaProject) { if (javaProject == null) { return null; }/* w ww.ja va2 s . com*/ List<IPackageFragmentRoot> packFragRoots = new ArrayList<IPackageFragmentRoot>(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); if (roots != null) { for (IPackageFragmentRoot rt : roots) { if (!packFragRoots.contains(rt)) { packFragRoots.add(rt); } } } } } } catch (JavaModelException e) { CloudFoundryPlugin.log(e); } IPackageFragment fragment = null; for (IPackageFragmentRoot root : packFragRoots) { try { IJavaElement[] members = root.getChildren(); if (members != null) { for (IJavaElement element : members) { if (element instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) element; if (frag.isDefaultPackage()) { fragment = frag; break; } } } } if (fragment != null) { break; } } catch (JavaModelException e) { CloudFoundryPlugin.log(e); } } return fragment; }
From source file:org.cloudfoundry.ide.eclipse.server.ui.internal.CloudRebelUIHandler.java
License:Open Source License
protected List<String> getClasspathSourceOutputPaths(IProject project) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); List<String> outputPaths = new ArrayList<String>(); if (javaProject != null) { try {/*w ww.ja v a 2s .c o m*/ IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); if (classpath != null) { for (IClasspathEntry entry : classpath) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation().toString() : null; if (outputPath != null && !outputPaths.contains(outputPath) && !outputPath.contains("target/test-classes")) {//$NON-NLS-1$ outputPaths.add(outputPath); } } } } String outputPath = javaProject.getOutputLocation() != null ? javaProject.getOutputLocation().toString() : null; if (outputPath != null && !outputPaths.contains(outputPath)) { outputPaths.add(outputPath); } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } } return outputPaths; }
From source file:org.codehaus.aspectwerkz.ide.eclipse.core.AwCorePlugin.java
License:Open Source License
/** * Build the list of URL for the given project * Resolve container (ie JRE jars) and dependancies and project output folder * /*from w w w. j a v a 2 s . c o m*/ * @param project * @return */ public List getProjectClassPathURLs(IJavaProject project) { List paths = new ArrayList(); try { // configured classpath IClasspathEntry classpath[] = project.getResolvedClasspath(false); for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; URL urlEntry = null; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); Object target = JavaModel.getTarget(workspaceRoot, path.getPath(), false); if (target != null) { // inside the workspace if (target instanceof IResource) { urlEntry = ((IResource) target).getLocation().toFile().toURL(); } else if (target instanceof File) { urlEntry = ((File) target).toURL(); } } } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outPath = path.getOutputLocation(); if (outPath != null) { //TODO : don't know if I ll have absolute path here urlEntry = outPath.toFile().toURL(); } } if (urlEntry != null) { paths.add(urlEntry); } else { AwLog.logTrace("project loader - ignored " + path.toString()); } } // project build output IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); paths.add(outputPath.toFile().toURL()); } catch (Exception e) { AwLog.logError("Could not build project path", e); } return paths; }
From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java
License:Apache License
/** * Need to recursively walk the classpath and visit all dependent projects * Not looking at classpath containers yet. * * @param javaProject// ww w.j a v a 2 s . c o m * @param entries */ private void addClasspathEntriesForProject(IJavaProject javaProject, SortedSet<String> sourceEntries, SortedSet<String> binEntries) { List<IJavaProject> dependingProjects = new ArrayList<IJavaProject>(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { int kind = entry.getEntryKind(); switch (kind) { case IClasspathEntry.CPE_LIBRARY: IPath libPath = entry.getPath(); if (!isPathInWorkspace(libPath)) { sourceEntries.add(libPath.toOSString()); break; } //$FALL-THROUGH$ case IClasspathEntry.CPE_SOURCE: IPath srcPath = entry.getPath(); String sloc = getProjectLocation(srcPath); if (srcPath.segmentCount() > 1) { sloc += File.separator + srcPath.removeFirstSegments(1).toOSString(); } sourceEntries.add(sloc); IPath outPath = entry.getOutputLocation(); if (outPath != null) { String bloc = getProjectLocation(outPath); if (outPath.segmentCount() > 1) { bloc += File.separator + outPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } break; case IClasspathEntry.CPE_PROJECT: dependingProjects.add(javaProject.getJavaModel().getJavaProject(entry.getPath().lastSegment())); break; } } IPath defaultOutPath = javaProject.getOutputLocation(); if (defaultOutPath != null) { String bloc = getProjectLocation(javaProject); if (defaultOutPath.segmentCount() > 1) { bloc += File.separator + defaultOutPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } } catch (JavaModelException e) { GroovyCore.logException("Exception generating classpath for launching groovy script", e); } // recur through dependent projects for (IJavaProject dependingProject : dependingProjects) { if (dependingProject.getProject().isAccessible()) { addClasspathEntriesForProject(dependingProject, sourceEntries, binEntries); } } }
From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java
License:Open Source License
private Map<IContainer, IContainer> generateSourceToOut(IJavaProject project) throws JavaModelException { IProject p = project.getProject();/* www . j a v a2 s. c om*/ IWorkspaceRoot root = (IWorkspaceRoot) p.getParent(); IClasspathEntry[] cp = project.getRawClasspath(); // determine default out folder IPath defaultOutPath = project.getOutputLocation(); IContainer defaultOutContainer; if (defaultOutPath.segmentCount() > 1) { defaultOutContainer = root.getFolder(defaultOutPath); } else { defaultOutContainer = p; } Map<IContainer, IContainer> sourceToOut = new TreeMap<IContainer, IContainer>(comparator); for (IClasspathEntry cpe : cp) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // determine source folder IContainer sourceContainer; IPath sourcePath = cpe.getPath(); if (sourcePath.segmentCount() > 1) { sourceContainer = root.getFolder(sourcePath); } else { sourceContainer = p; } // determine out folder IPath outPath = cpe.getOutputLocation(); IContainer outContainer; if (outPath == null) { outContainer = defaultOutContainer; } else if (outPath.segmentCount() > 1) { outContainer = root.getFolder(outPath); } else { outContainer = p; } // if the two containers are equal, that means no copying should be done // do not add to map if (!sourceContainer.equals(outContainer)) { sourceToOut.put(sourceContainer, outContainer); } } } return sourceToOut; }
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;/*from w ww . j a va 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.compiere.mfg_scm.eclipse.db.DbfProject.java
License:Apache License
public void clearDefaultSourceEntries() throws CoreException { IClasspathEntry[] entries = javaProject.getRawClasspath(); List cp = new ArrayList(entries.length + 1); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) { cp.add(entries[i]);/*from w w w . j a v a 2 s. c om*/ } } javaProject.setRawClasspath((IClasspathEntry[]) cp.toArray(new IClasspathEntry[cp.size()]), null); }
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 *///from www.j a v a 2 s. com 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.datanucleus.ide.eclipse.jobs.LaunchUtilities.java
License:Open Source License
/** * Convenience method to get all source parts of the CLASSPATH. * @param javaProject The java project// w ww . j av a2s . co m * @return The source parts of the classpath */ protected static List getSourcePaths(IJavaProject javaProject) { List paths = new ArrayList(); IClasspathEntry entries[]; try { entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { paths.add(entries[i].getPath()); } } } catch (JavaModelException e) { e.printStackTrace(); } return paths; }