List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:apet.utils.ClasspathUtils.java
License:Open Source License
/** * Returns the Eclipse Project class loader using project build path * @param javaProject Eclipse Java Project * @return A class loader using project build path * @throws Exception If the project is no valid *///from w ww .j a v a2 s. com public static ClassLoader getProjectClassLoader(IJavaProject javaProject) throws Exception { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); String wsPath = javaProject.getProject().getLocation().toPortableString(); String firstEntryLocation = javaProject.getPath().toPortableString(); int idx = wsPath.indexOf(firstEntryLocation); URL[] urls = null; int i = 0; //System.out.println("ClassLoader " + wsPath); //System.out.println("ClassLoader " + firstEntryLocation); String output = javaProject.getOutputLocation().toPortableString(); urls = new URL[entries.length + 1]; if (idx != -1) { wsPath = wsPath.substring(0, idx); } else { output = output.substring(firstEntryLocation.length()); } urls[i++] = new File(wsPath + output).toURL(); //System.out.println("ClassLoader " + output); String fullPath = null; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); String projectPath = JavaCore.create(project.getProject()).getOutputLocation().toPortableString(); fullPath = wsPath + projectPath; } else { Object resource = JavaModel.getTarget(entry.getPath(), true); if (resource instanceof IResource) { IResource iFile = (IResource) resource; fullPath = iFile.getLocation().toPortableString(); } else if (resource instanceof File) { File file = (File) resource; fullPath = file.getAbsolutePath(); } } urls[i++] = new File(fullPath).toURL(); //System.out.println(fullPath); } URLClassLoader classLoader = new URLClassLoader(urls, String.class.getClassLoader()); /*for (int j = 0; j < urls.length; j ++) { System.out.println(urls[j]); }*/ return classLoader; }
From source file:apet.utils.ClasspathUtils.java
License:Open Source License
/** * Returns a String with all libraries defined in build path * @param javaProject Eclipse Java Project * @return a String with all libraries defined in build path * @throws Exception If the project is no valid */// w w w .j a v a 2 s .c o m public static String getStringClasspath(IJavaProject javaProject) throws Exception { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); String wsPath = javaProject.getProject().getLocation().toPortableString(); String firstEntryLocation = javaProject.getPath().toPortableString(); int idx = wsPath.indexOf(firstEntryLocation); String[] urls = new String[entries.length + 1]; String fullPath = null; int i = 0; String output = javaProject.getOutputLocation().toPortableString(); if (idx != -1) { wsPath = wsPath.substring(0, idx); } else { output = output.substring(firstEntryLocation.length()); } urls[i++] = wsPath + output; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); String projectPath = JavaCore.create(project.getProject()).getOutputLocation().toPortableString(); fullPath = wsPath + projectPath; } else { Object resource = JavaModel.getTarget(entry.getPath(), true); if (resource instanceof IResource) { IResource iFile = (IResource) resource; fullPath = iFile.getLocation().toPortableString(); } else if (resource instanceof File) { File file = (File) resource; fullPath = file.getAbsolutePath(); } } urls[i++] = fullPath; } StringBuffer buffer = new StringBuffer(); for (String url : urls) { buffer.append(url); buffer.append(":"); } return buffer.toString().substring(0, buffer.length() - 1); }
From source file:ar.com.fluxit.jqa.JQAEclipseRunner.java
License:Open Source License
private Collection<File> getClassFiles(IJavaProject javaProject) throws JavaModelException { Collection<File> result = new ArrayList<File>(); File buildDir = Utils.getAbsolutePath(javaProject.getOutputLocation()); result.addAll(FileUtils.listFiles(buildDir, new SuffixFileFilter(RulesContextChecker.CLASS_SUFFIX), TrueFileFilter.INSTANCE));// w w w .j a v a2 s . co m return result; }
From source file:at.bestsolution.efxclipse.tooling.ui.preview.LivePreviewSynchronizer.java
License:Open Source License
private void resolveDataProject(IJavaProject project, Set<IPath> outputPath, Set<IPath> listRefLibraries) { try {/* ww w . j a v a 2s . co m*/ IClasspathEntry[] entries = project.getRawClasspath(); outputPath.add(project.getOutputLocation()); for (IClasspathEntry e : entries) { if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(e.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(e.getPath()); } else if ("org.eclipse.pde.core.requiredPlugins".equals(e.getPath().toString())) { IClasspathContainer cpContainer = JavaCore.getClasspathContainer(e.getPath(), project); for (IClasspathEntry cpEntry : cpContainer.getClasspathEntries()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot() .getProject(cpEntry.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(cpEntry.getPath()); } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.bestsolution.javafx.ide.jdt.internal.NewJavaProjectService.java
License:Open Source License
public static void flush(List<CPListElement> classPathEntries, IPath outputLocation, IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor) throws CoreException, OperationCanceledException { IProject project = javaProject.getProject(); IPath projPath = project.getFullPath(); IPath oldOutputLocation;/*from www .j a v a 2s . c om*/ try { oldOutputLocation = javaProject.getOutputLocation(); } catch (CoreException e) { oldOutputLocation = projPath.append( "bin"/*PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)*/); } if (oldOutputLocation.equals(projPath) && !outputLocation.equals(projPath)) { if (BuildPathsBlock.hasClassfiles(project)) { // if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(false, projPath)) { BuildPathsBlock.removeOldClassfiles(project); // } } } else if (!outputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { BuildPathsBlock.removeOldClassfiles(folder); } else { // if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(folder.isDerived(), oldOutputLocation)) { BuildPathsBlock.removeOldClassfiles(folder); // } } } } monitor.worked(1); IWorkspaceRoot fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); //create and set the output path first if (!fWorkspaceRoot.exists(outputLocation)) { IFolder folder = fWorkspaceRoot.getFolder(outputLocation); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } int nEntries = classPathEntries.size(); IClasspathEntry[] classpath = new IClasspathEntry[nEntries]; int i = 0; for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); classpath[i] = entry.getClasspathEntry(); i++; IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (!path.equals(entry.getOrginalPath())) { String eeID = JavaRuntime.getExecutionEnvironmentId(path); if (eeID != null) { BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance); newProjectCompliance = null; // don't set it again below } } if (newProjectCompliance != null) { Map<String, String> options = javaProject.getOptions(false); JavaModelUtil.setComplianceOptions(options, newProjectCompliance); JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options javaProject.setOptions(options); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, outputLocation, new SubProgressMonitor(monitor, 2)); }
From source file:bz.davide.dmeclipsesavehookplugin.builder.DMEclipseSaveHookPluginBuilder.java
License:Open Source License
static void findTransitiveDepProjects(IJavaProject current, ArrayList<IProject> projects, ArrayList<String> fullClasspath) throws CoreException { if (!projects.contains(current.getProject())) { projects.add(current.getProject()); }/*from ww w .ja v a 2 s . c om*/ fullClasspath.add(ResourcesPlugin.getWorkspace().getRoot().findMember(current.getOutputLocation()) .getLocation().toOSString() + "/"); ArrayList<IClasspathEntry> classPaths = new ArrayList<IClasspathEntry>(); classPaths.addAll(Arrays.asList(current.getRawClasspath())); for (int x = 0; x < classPaths.size(); x++) { IClasspathEntry cp = classPaths.get(x); if (cp.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = cp.getPath().lastSegment(); IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName); if (prj.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(prj); findTransitiveDepProjects(javaProject, projects, fullClasspath); } continue; } if (cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String fullContainerName = cp.getPath().toString(); if (!fullContainerName.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER/")) { System.out.println("CP C: " + fullContainerName); IClasspathContainer container = JavaCore.getClasspathContainer(cp.getPath(), current); classPaths.addAll(Arrays.asList(container.getClasspathEntries())); } } if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = cp.getPath(); // Check first if this path is relative to workspace IResource workspaceMember = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if (workspaceMember != null) { String fullPath = workspaceMember.getLocation().toOSString(); fullClasspath.add(fullPath); } else { fullClasspath.add(path.toOSString()); } } } }
From source file:ca.mcgill.sable.soot.launching.SootClasspath.java
License:Open Source License
public static URL[] projectClassPath(IJavaProject javaProject) { IWorkspace workspace = SootPlugin.getWorkspace(); IClasspathEntry[] cp;//from w w w. j a v a 2 s . com try { cp = javaProject.getResolvedClasspath(true); List<URL> urls = new ArrayList<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:ccw.builder.ClojureBuilder.java
License:Open Source License
private static Map<IFolder, IFolder> getSrcFolders(IProject project) throws CoreException { Map<IFolder, IFolder> srcFolders = new HashMap<IFolder, IFolder>(); IJavaProject jProject = JavaCore.create(project); IClasspathEntry[] entries = jProject.getResolvedClasspath(true); IPath defaultOutputFolder = jProject.getOutputLocation(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IFolder folder = project.getWorkspace().getRoot().getFolder(entry.getPath()); IFolder outputFolder = project.getWorkspace().getRoot().getFolder( (entry.getOutputLocation() == null) ? defaultOutputFolder : entry.getOutputLocation()); if (folder.exists()) srcFolders.put(folder, outputFolder); break; case IClasspathEntry.CPE_LIBRARY: break; case IClasspathEntry.CPE_PROJECT: // TODO should compile here ? break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: // Impossible cases, since entries are resolved default://from ww w.j a va 2s . co m break; } } return srcFolders; }
From source file:cfgrecognition.loader.SootClasspath.java
License:Open Source License
public static URL[] projectClassPath(IJavaProject javaProject) { IWorkspace workspace = Activator.getWorkspaceRoot().getWorkspace(); IClasspathEntry[] cp;//from ww w. j ava 2 s .co 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:cfgrecognition.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. * //from w ww. java2 s .c o 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 = Activator.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]; } }