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.objectstyle.wolips.jrebel.utils.WOProjectClassLoader.java
License:BSD License
private void addURLs(IJavaProject javaProject, boolean exportsOnly) { if (!javaProjects.contains(javaProject)) { javaProjects.add(javaProject);//from w w w . j a v a 2 s .co m try { // Add default output location addURL(javaProject.getOutputLocation()); // Add each classpath entry IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry classpathEntry : classpathEntries) { if (classpathEntry.isExported() || !exportsOnly) { switch (classpathEntry.getEntryKind()) { // Recurse on projects case IClasspathEntry.CPE_PROJECT: IProject project = javaProject.getProject().getWorkspace().getRoot() .getProject(classpathEntry.getPath().toString()); IJavaProject javaProj = JavaCore.create(project); if (javaProj != null) { addURLs(javaProj, true); } break; // Library case IClasspathEntry.CPE_LIBRARY: addURL(classpathEntry); break; // Only Source entries with custom output location need to be added case IClasspathEntry.CPE_SOURCE: IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null) { addURL(outputLocation); } break; // Variable and Container entries should not be happening, because // we've asked for resolved entries. case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: break; } } } } catch (JavaModelException e) { e.printStackTrace(); // log.debug("MalformedURLException occurred: " + e.getLocalizedMessage(),e); } } }
From source file:org.openoffice.ide.eclipse.java.JavaBuilder.java
License:LGPL
/** * Get the libraries in the classpath that are located in the project * directory or one of its subfolder./*from w w w . ja v a 2 s. c o m*/ * * @param pJavaPrj the project from which to extract the libraries * @return a list of all the File pointing to the libraries. */ private ArrayList<IFile> getLibs(IJavaProject pJavaPrj) { ArrayList<IFile> libs = new ArrayList<IFile>(); try { IClasspathEntry[] entries = pJavaPrj.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { /* * At first, add only the libraries located in the project * or one of its children. All others libraries have to be * managed y the user. */ IPath path = entry.getPath(); if (!new File(path.toOSString()).exists() && path.isAbsolute() && path.toString().startsWith("/" + pJavaPrj.getProject().getName())) { //$NON-NLS-1$ // Relative to the project IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file != null && file.exists()) { libs.add(file); } } } } } catch (JavaModelException e) { // Enable to add some missing library } return libs; }
From source file:org.org.eclipse.dws.core.internal.bridges.ProjectInteractionHelper.java
License:Open Source License
/** * Gets the classpath entries./* w w w .j av a 2s . c o m*/ * * @param javaProject the java project * * @return the classpath entries */ public static Set<DWSClasspathEntryDescriptor> getClasspathEntries(IJavaProject javaProject) { Set<DWSClasspathEntryDescriptor> classpathEntryDescriptors = new LinkedHashSet<DWSClasspathEntryDescriptor>(); try { if (javaProject.exists()) { for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) { DWSClasspathEntryDescriptor classpathEntryDescriptor = new DWSClasspathEntryDescriptor(); classpathEntryDescriptor .setEncodedClasspathEntry(javaProject.encodeClasspathEntry(classpathEntry)); classpathEntryDescriptor.setPath(classpathEntry.getPath().toPortableString()); classpathEntryDescriptor.setProjectName(javaProject.getElementName()); IJavaModelStatus javaModelStatus = JavaConventions.validateClasspathEntry(javaProject, classpathEntry, false); classpathEntryDescriptor.setValid(classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || classpathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE && javaModelStatus.isOK()); classpathEntryDescriptors.add(classpathEntryDescriptor); } } } catch (JavaModelException e) { throw new JavaProjectInteractionException( "An error occured while scanning for classpath entries in project:" + javaProject, e); } return classpathEntryDescriptors; }
From source file:org.org.eclipse.dws.ui.internal.wizards.pages.LookupJavadocAndSourcesForLibrariesInClasspathPage.java
License:Open Source License
/** * Misses javadoc./*from w w w .j a va 2 s. c o m*/ * * @param packageFragmentRoot * the package fragment root * * @return true, if successful * * @throws JavaModelException * the java model exception */ private boolean missesJavadoc(IPackageFragmentRoot packageFragmentRoot) throws JavaModelException { int entryKind = packageFragmentRoot.getRawClasspathEntry().getEntryKind(); boolean missesJavadoc = false; if (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE) { missesJavadoc = JavaUI.getLibraryJavadocLocation(packageFragmentRoot.getRawClasspathEntry()) == null; } if (entryKind == IClasspathEntry.CPE_CONTAINER) { missesJavadoc = JavaUI.getJavadocLocation(packageFragmentRoot.getPrimaryElement(), false) == null; } return missesJavadoc; }
From source file:org.polarsys.capella.groovy.CapellaScriptLaunchConfigurationDelegate.java
License:Open Source License
public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { WorkspaceJob job = new WorkspaceJob("Capella Groovy Script Execution") { @Override/* www .j a v a 2s. c o m*/ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { String location = configuration .getAttribute(CapellaGroovyConstants.LAUNCH_ATTR_SCRIPT_LOCATION.name(), (String) null); String[] args = configuration .getAttribute(CapellaGroovyConstants.LAUNCH_ATTR_PROGRAM_ARGS.name(), "").split("\\s+"); IFile capellaScriptFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(location)); Collection<URL> urls = new ArrayList<URL>(); if (capellaScriptFile.getProject().hasNature(JavaCore.NATURE_ID)) { IJavaProject project = JavaCore.create(capellaScriptFile.getProject()); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { try { urls.add(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocationURI().toURL()); } catch (MalformedURLException e) { CapellaGroovyPlugin.getInstance().getLog().log(new Status(IStatus.ERROR, CapellaGroovyPlugin.PLUGIN_ID, e.getMessage(), e)); } } } } try { final Reader reader = new BufferedReader( new InputStreamReader(capellaScriptFile.getContents())); CompilerConfiguration c = new CompilerConfiguration(); c.setScriptBaseClass("org.polarsys.capella.groovy.CapellaScriptBase"); c.addCompilationCustomizers(importCustomizer); ClassLoader loader = getClass().getClassLoader(); if (urls.size() > 0) { loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), loader); } final GroovyShell shell = new GroovyShell(loader, new Binding(args), c); shell.evaluate(reader); } catch (CoreException e) { throw new CoreException( new Status(IStatus.ERROR, CapellaGroovyPlugin.PLUGIN_ID, e.getMessage(), e)); } return Status.OK_STATUS; } }; job.schedule(); }
From source file:org.rascalmpl.eclipse.nature.ProjectEvaluatorFactory.java
License:Open Source License
private void collectClassPathForProject(IProject project, List<URL> classPath, List<String> compilerClassPath, Evaluator parser) {/*from w ww . java2s.c o m*/ try { if (!project.hasNature(JavaCore.NATURE_ID)) { for (IProject ref : project.getReferencedProjects()) { collectClassPathForProject(ref, classPath, compilerClassPath, parser); } } else { IJavaProject jProject = JavaCore.create(project); IPath binFolder = jProject.getOutputLocation(); String binLoc = project.getLocation() + "/" + binFolder.removeFirstSegments(1).toString(); compilerClassPath.add(binLoc); URL binURL = new URL("file", "", binLoc + "/"); parser.addClassLoader(new URLClassLoader(new URL[] { binURL }, getClass().getClassLoader())); classPath.add(binURL); if (!jProject.isOpen()) { return; } IClasspathEntry[] entries = jProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (entry.getPath().segment(0).equals(project.getName())) { String file = project.getLocation() + "/" + entry.getPath().removeFirstSegments(1).toString(); URL url = new URL("file", "", file); if (!classPath.contains(url)) { classPath.add(url); compilerClassPath.add(file); } } else { URL url = new URL("file", "", entry.getPath().toString()); if (!classPath.contains(url)) { classPath.add(url); compilerClassPath.add(entry.getPath().toString()); } } break; case IClasspathEntry.CPE_PROJECT: collectClassPathForProject( (IProject) project.getWorkspace().getRoot().findMember(entry.getPath()), classPath, compilerClassPath, parser); break; } } } } catch (CoreException e) { Activator.getInstance().logException("failed to configure classpath", e); } catch (MalformedURLException e) { Activator.getInstance().logException("failed to configure classpath", e); } }
From source file:org.robovm.eclipse.RoboVMPlugin.java
License:Open Source License
private static void getSourcePaths(Set<String> paths, IJavaProject javaProject) throws CoreException { try {// w w w.j av a 2 s. c om // add the source jars of rt/objc/cocoatouch etc. File libDir = new File(RoboVMPlugin.getRoboVMHome().getBinDir().getParentFile(), "lib"); paths.add(new File(libDir, "robovm-cocoatouch-sources.jar").getAbsolutePath()); paths.add(new File(libDir, "robovm-objc-sources.jar").getAbsolutePath()); paths.add(new File(libDir, "robovm-rt-sources.jar").getAbsolutePath()); } catch (IOException e) { RoboVMPlugin.consoleError("Couldn't retrieve lib/ directory"); } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { IPath path = null; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IResource resource = root.findMember(entry.getPath()); if (resource != null) { path = resource.getLocation(); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (entry.getSourceAttachmentPath() != null) { path = entry.getSourceAttachmentPath(); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().toString()); if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) { getSourcePaths(paths, JavaCore.create(project)); } } if (path != null) { paths.add(path.toOSString()); } } }
From source file:org.savara.tools.scenario.designer.simulate.ScenarioSimulationLauncher.java
License:Apache License
/** * This method derives the classpath required to run the * ScenarioTester utility.//from w w w . j av a 2 s . c o m * * @param configuration The launch configuation * @return The list of classpath entries */ public String[] getClasspath(ILaunchConfiguration configuration) { String[] ret = null; java.util.Vector<String> classpathEntries = new java.util.Vector<String>(); // Add classpath entry for current Java project String projnames = null; try { projnames = configuration.getAttribute(ScenarioSimulationLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); String[] projname = projnames.split(","); java.util.List<String> outputPaths = new java.util.Vector<String>(); for (int n = 0; n < projname.length; n++) { try { if (logger.isLoggable(Level.FINE)) { logger.fine("Building classpath for project: " + projname[n]); } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projname[n]); IJavaProject jproject = JavaCore.create(project); // Add output location IPath outputLocation = jproject.getOutputLocation(); IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation); String path = folder.getLocation().toString(); outputPaths.add(path); // Add other libraries to the classpath IClasspathEntry[] curclspath = jproject.getRawClasspath(); for (int i = 0; curclspath != null && i < curclspath.length; i++) { if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(curclspath[i].getPath()); if (file.exists()) { // Library is within the workspace classpathEntries.add(file.getLocation().toString()); } else { // Assume library is external to workspace classpathEntries.add(curclspath[i].getPath().toString()); } } else if (curclspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // Container's not currently handled - but // problem need to retrieve from project and // iterate over container entries } } } catch (Exception e) { // TODO: report error } } if (outputPaths.size() == 1) { classpathEntries.add(outputPaths.get(0)); } else if (outputPaths.size() > 0) { // Need to merge output folders into one location java.io.File dir = new java.io.File( System.getProperty("java.io.tmpdir") + java.io.File.separatorChar + "savara" + java.io.File.separatorChar + "simulation" + System.currentTimeMillis()); dir.deleteOnExit(); dir.mkdirs(); classpathEntries.add(dir.getAbsolutePath()); for (String path : outputPaths) { copy(new java.io.File(path), dir); } } } catch (Exception ex) { ex.printStackTrace(); } java.util.List<Bundle> bundles = getBundles(); for (Bundle b : bundles) { buildClassPath(b, classpathEntries); } ret = new String[classpathEntries.size()]; classpathEntries.copyInto(ret); if (logger.isLoggable(Level.FINEST)) { logger.finest("Scenario Simulation Classpath:"); for (int i = 0; i < ret.length; i++) { logger.finest(" [" + i + "] " + ret[i]); } } return (ret); }
From source file:org.seasar.diigu.eclipse.util.JavaProjectClassLoader.java
License:Apache License
protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) { already.add(project);//from www. j a v a2 s . c om try { IContainer workspaceroot = project.getProject().getParent(); IPath path = project.getOutputLocation(); addURL(toURL(workspaceroot.getFolder(path).getLocation())); IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IPath dist = entry.getOutputLocation(); if (dist != null) { addURL(toURL(workspaceroot.getFolder(dist).getLocation())); } break; case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: IPath p = entry.getPath(); if (p.toFile().exists()) { addURL(toURL(p)); } else { addURL(toURL(workspaceroot.getFile(p).getLocation())); } break; case IClasspathEntry.CPE_PROJECT: IJavaProject proj = ProjectUtils.getJavaProject(entry.getPath().segment(0)); if (proj != null && proj.exists() && already.contains(proj) == false && (atFirst || entry.isExported())) { addClasspathEntries(proj, already, false); } break; default: break; } } } catch (Exception e) { DiiguPlugin.log(e); } }
From source file:org.seasar.kijimuna.core.util.JavaProjectClassLoader.java
License:Apache License
protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) { already.add(project);/*w ww . j av a 2s.c o m*/ try { IContainer workspaceroot = project.getProject().getParent(); IPath path = project.getOutputLocation(); addURL(toURL(workspaceroot.getFolder(path).getLocation())); IClasspathEntry[] entries = project.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IPath dist = entry.getOutputLocation(); if (dist != null) { addURL(toURL(workspaceroot.getFolder(dist).getLocation())); } break; case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: IPath p = entry.getPath(); if (p.toFile().exists()) { addURL(toURL(p)); } else { addURL(toURL(workspaceroot.getFile(p).getLocation())); } break; case IClasspathEntry.CPE_PROJECT: IJavaProject proj = JavaCore.create(ProjectUtils.getProject(entry.getPath().segment(0))); if (proj != null && proj.exists() && already.contains(proj) == false && (atFirst || entry.isExported())) { addClasspathEntries(proj, already, false); } break; default: break; } } } catch (Exception e) { KijimunaCore.reportException(e); } }