List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:de.devboost.eclipse.jdtutilities.JDTUtility.java
License:Open Source License
/** * Checks whether the given EMF platform URI is located in an output folder * of the given, containing Java project. *//*from w w w . j ava 2 s .com*/ public boolean isInOutputFolder(IProject project, String platformURI) { IJavaProject javaProject = getJavaProject(project); if (javaProject == null) { return false; } // FIXME Handle projects that have multiple output locations. try { IPath outputLocation = javaProject.getOutputLocation(); String outputPath = outputLocation.toString(); // We add a slash to the end of the path to make sure that the // output directory (e.g., 'bin') is not only a prefix of the // corresponding fragments in the URI (e.g., 'bind-src'), but really // refers to the same directory. if (!outputPath.endsWith("/")) { outputPath = outputPath + "/"; } if (platformURI.startsWith(outputPath)) { return true; } } catch (JavaModelException e) { logWarning("Can't determine output location for project " + javaProject.getElementName(), e); } return false; }
From source file:de.loskutov.bco.ui.JdtUtils.java
License:Open Source License
/** * @param javaElement//from w w w .j a va 2s. c o m * @return absolute path of generated bytecode package for given element * @throws JavaModelException */ private static String getPackageOutputPath(IJavaElement javaElement) throws JavaModelException { String dir = ""; //$NON-NLS-1$ if (javaElement == null) { return dir; } IJavaProject project = javaElement.getJavaProject(); if (project == null) { return dir; } // default bytecode location IPath path = project.getOutputLocation(); IResource resource = javaElement.getUnderlyingResource(); if (resource == null) { return dir; } // resolve multiple output locations here if (project.exists() && project.getProject().isOpen()) { IClasspathEntry entries[] = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry classpathEntry = entries[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = classpathEntry.getOutputLocation(); if (outputPath != null && classpathEntry.getPath().isPrefixOf(resource.getFullPath())) { path = outputPath; break; } } } } if (path == null) { // check the default location if not already included IPath def = project.getOutputLocation(); if (def != null && def.isPrefixOf(resource.getFullPath())) { path = def; } } if (path == null) { return dir; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (!project.getPath().equals(path)) { IFolder outputFolder = workspace.getRoot().getFolder(path); if (outputFolder != null) { // linked resources will be resolved here! IPath rawPath = outputFolder.getRawLocation(); if (rawPath != null) { path = rawPath; } } } else { path = project.getProject().getLocation(); } // here we should resolve path variables, // probably existing at first place of path IPathVariableManager pathManager = workspace.getPathVariableManager(); path = pathManager.resolvePath(path); if (path == null) { return dir; } if (isPackageRoot(project, resource)) { dir = path.toOSString(); } else { String packPath = EclipseUtils.getJavaPackageName(javaElement).replace(Signature.C_DOT, PACKAGE_SEPARATOR); dir = path.append(packPath).toOSString(); } return dir; }
From source file:de.loskutov.bco.ui.JdtUtils.java
License:Open Source License
private static void getClassURLs(IJavaProject javaProject, List<URL> urls) { IProject project = javaProject.getProject(); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); IClasspathEntry[] paths = null;//from w w w . j a v a 2 s . c o m IPath defaultOutputLocation = null; try { paths = javaProject.getResolvedClasspath(true); defaultOutputLocation = javaProject.getOutputLocation(); } catch (JavaModelException e) { // don't show message to user neither log it // BytecodeOutlinePlugin.log(e, IStatus.ERROR); } if (paths != null) { IPath projectPath = javaProject.getProject().getLocation(); for (int i = 0; i < paths.length; ++i) { IClasspathEntry cpEntry = paths[i]; IPath p = null; if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // filter out source container - there are unused for class // search - add bytecode output location instead p = cpEntry.getOutputLocation(); if (p == null) { // default output used: p = defaultOutputLocation; } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String projName = cpEntry.getPath().toPortableString().substring(1); IProject proj = workspaceRoot.getProject(projName); IJavaProject projj = JavaCore.create(proj); getClassURLs(projj, urls); continue; } else { p = cpEntry.getPath(); } if (p == null) { continue; } if (!p.toFile().exists()) { // removeFirstSegments: remove project from relative path p = projectPath.append(p.removeFirstSegments(1)); if (!p.toFile().exists()) { continue; } } try { urls.add(p.toFile().toURI().toURL()); } catch (MalformedURLException e) { // don't show message to user BytecodeOutlinePlugin.log(e, IStatus.ERROR); } } } }
From source file:de.loskutov.eclipse.jdepend.views.TreeObject.java
License:Open Source License
protected String getPackageOutputPath(IJavaElement jElement) throws JavaModelException { String dir = ""; //$NON-NLS-1$ if (jElement == null) { return dir; }/*from w w w .j ava 2 s .co m*/ IJavaProject project = jElement.getJavaProject(); if (project == null) { return dir; } IPath path = project.getOutputLocation(); IResource resource = jElement.getUnderlyingResource(); if (resource == null) { return dir; } // resolve multiple output locations here if (project.exists() && project.getProject().isOpen()) { IClasspathEntry entries[] = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry classpathEntry = entries[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = classpathEntry.getOutputLocation(); if (outputPath != null) { // if this source folder contains specified java resource // then take bytecode location from himself if (classpathEntry.getPath().isPrefixOf(resource.getFullPath())) { path = outputPath; break; } } } } } if (path == null) { // check the default location if not already included IPath def = project.getOutputLocation(); if (def != null && def.isPrefixOf(resource.getFullPath())) { path = def; } } if (path == null) { return dir; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (!project.getPath().equals(path)) { IFolder outputFolder = workspace.getRoot().getFolder(path); if (outputFolder != null) { // linked resources will be resolved here! IPath rawPath = outputFolder.getRawLocation(); if (rawPath != null) { path = rawPath; } } } else { path = project.getProject().getLocation(); } if (path == null) { return dir; } // here we should resolve path variables, // probably existing at first place of path IPathVariableManager pathManager = workspace.getPathVariableManager(); path = pathManager.resolvePath(path); if (path == null) { return dir; } boolean packageRoot = false; try { packageRoot = isPackageRoot(project, resource); } catch (JavaModelException e) { // seems to be a bug in 3.3 } if (packageRoot) { dir = path.toOSString(); } else { String packPath = getPackageName().replace('.', '/'); dir = path.append(packPath).toOSString(); } return dir; }
From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java
License:Open Source License
/** * Return output location for a project. *///from ww w. j a va 2s. c om public IPath getOutputLocation(IPath projectPath) { try { IJavaProject javaProject = JavaCore.create(getProject(projectPath)); return javaProject.getOutputLocation(); } catch (CoreException e) { // ignore } return null; }
From source file:de.tobject.findbugs.builder.PDEClassPathGenerator.java
License:Open Source License
private static Collection<String> createPluginClassPath(IJavaProject javaProject, Set<IProject> projectOnCp) throws CoreException { Set<String> javaClassPath = createJavaClasspath(javaProject, projectOnCp); IPluginModelBase model = PluginRegistry.findModel(javaProject.getProject()); if (model == null || model.getPluginBase().getId() == null) { return javaClassPath; }//from w w w . jav a 2s .c o m ArrayList<String> pdeClassPath = new ArrayList<>(); pdeClassPath.addAll(javaClassPath); BundleDescription target = model.getBundleDescription(); Set<BundleDescription> bundles = new HashSet<BundleDescription>(); // target is null if plugin uses non OSGI format if (target != null) { addDependentBundles(target, bundles); } // convert default location (relative to wsp) to absolute path IPath defaultOutputLocation = ResourceUtils.relativeToAbsolute(javaProject.getOutputLocation()); for (BundleDescription bd : bundles) { appendBundleToClasspath(bd, pdeClassPath, defaultOutputLocation); } if (defaultOutputLocation != null) { String defaultOutput = defaultOutputLocation.toOSString(); if (pdeClassPath.indexOf(defaultOutput) > 0) { pdeClassPath.remove(defaultOutput); pdeClassPath.add(0, defaultOutput); } } return pdeClassPath; }
From source file:distributed.plugin.ui.actions.ProcessActions.java
License:Open Source License
private ClassLoader getClassLoader() { ClassLoader loader = null;/* ww w. j av a 2 s . c o m*/ IJavaProject javaProject = this.getClientProject(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); List<URL> urls = new ArrayList<URL>(entries.length); for (int i = 0; i < entries.length; i++) { IPath classpathEntryPath = entries[i].getPath(); File classpathEntryFile = null; switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath out = root.getProject(classpathEntryPath.lastSegment()).getLocation(); if (out != null) classpathEntryFile = out.toFile(); else classpathEntryFile = root.getFolder(javaProject.getOutputLocation()).getLocation().toFile(); try { URI uri = classpathEntryFile.toURI(); urls.add(uri.toURL()); } catch (MalformedURLException e) { e.printStackTrace(); } break; case IClasspathEntry.CPE_CONTAINER: break; // FIXME Must handle 2 more cases to handle the location of // client source code } } // set default output (replay) file location w.r.t user bin location this.engine.setOutputLocation((URL) urls.get(0)); // create class loader loader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]), ProcessActions.class.getClassLoader()); } catch (JavaModelException e) { e.printStackTrace(); } return loader; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java
License:Open Source License
private void addClassPaths(IJavaProject jp, IvyXmlWriter xw, Set<IProject> done, boolean nest) { if (done == null) done = new HashSet<IProject>(); done.add(jp.getProject());//from w w w .j av a 2 s. c om BedrockPlugin.logD("Getting class path for " + jp.getProject().getName()); try { IClasspathEntry[] ents = jp.getResolvedClasspath(true); for (IClasspathEntry ent : ents) { addPath(xw, jp, ent, nest); } IPath op = jp.getOutputLocation(); if (op != null) { xw.begin("PATH"); xw.field("TYPE", "BINARY"); File f = BedrockUtil.getFileForPath(op, jp.getProject()); if (f.exists()) xw.textElement("BINARY", f.getAbsolutePath()); xw.end("PATH"); } for (IProject rp : jp.getProject().getReferencedProjects()) { if (done.contains(rp)) continue; IJavaProject jrp = JavaCore.create(rp); addClassPaths(jrp, xw, done, true); } } catch (CoreException e) { BedrockPlugin.logE("Problem resolving classpath: " + e); } }
From source file:edu.clarkson.serl.critic.loader.SootClasspath.java
License:Open Source License
public static URL[] projectClassPath(IJavaProject javaProject) { IWorkspace workspace = CriticPlugin.getWorkspaceRoot().getWorkspace(); IClasspathEntry[] cp;/*from w ww . j a v a 2 s.c o m*/ try { cp = javaProject.getResolvedClasspath(true); Set<URL> urls = new HashSet<URL>(); String uriString = workspace.getRoot().getFile(javaProject.getOutputLocation()).getLocationURI() .toString() + "/"; urls.add(new URI(uriString).toURL()); for (IClasspathEntry entry : cp) { File file = entry.getPath().toFile(); URL url = file.toURI().toURL(); urls.add(url); } URL[] array = new URL[urls.size()]; urls.toArray(array); return array; } catch (JavaModelException e) { e.printStackTrace(); return new URL[0]; } catch (MalformedURLException e) { e.printStackTrace(); return new URL[0]; } catch (URISyntaxException e) { e.printStackTrace(); return new URL[0]; } }
From source file:edu.clarkson.serl.critic.loader.SootClasspath.java
License:Open Source License
/** * This is an addition to the original SootClasspath class where * bug due to '\\' in the path string has been resolved. * (Added By: Ryan Edgar)//from w w w . j a va2s. co m * * @param javaProject The JavaProject to be analyzed. * @return An array of {@link URL}s corresponding to the classpath of the supplied project. */ public static URL[] projectClassPath2(IJavaProject javaProject) { IWorkspace workspace = CriticPlugin.getWorkspaceRoot().getWorkspace(); IClasspathEntry[] cp; try { cp = javaProject.getResolvedClasspath(true); Set<URL> urls = new HashSet<URL>(); String uriString = workspace.getRoot().getFile(javaProject.getOutputLocation()).getLocationURI() .toString() + "/"; urls.add(new URI(uriString).toURL()); for (IClasspathEntry entry : cp) { File file = entry.getPath().toFile(); if (file.getPath().startsWith("\\")) { file = workspace.getRoot().getLocation().append(file.getPath()).toFile(); } URL url = file.toURI().toURL(); urls.add(url); } URL[] array = new URL[urls.size()]; urls.toArray(array); return array; } catch (JavaModelException e) { e.printStackTrace(); return new URL[0]; } catch (MalformedURLException e) { e.printStackTrace(); return new URL[0]; } catch (URISyntaxException e) { e.printStackTrace(); return new URL[0]; } }