List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.e4.xwt.ui.utils.ClassLoaderHelper.java
License:Open Source License
public static byte[] getClassContent(IJavaProject javaProject, String className) { if (javaProject == null || !javaProject.exists()) return null; String resourceName = className.replace('.', '/') + ".class"; try {//from w w w . jav a 2 s .co m IPath outPath = javaProject.getProject().getLocation().removeLastSegments(1) .append(javaProject.getOutputLocation()); outPath = outPath.addTrailingSeparator(); { URL url = toURL(outPath.append(resourceName)); if (url != null) { InputStream inputStream = url.openStream(); byte[] content = new byte[inputStream.available()]; inputStream.read(content); return content; } for (IProject project : javaProject.getProject().getReferencedProjects()) { if (!project.isOpen()) { continue; } IJavaProject javaReferencedProject = JavaCore.create(project); if (javaReferencedProject.exists()) { byte[] content = getClassContent(javaReferencedProject, className); if (content != null) { return content; } } } } IType type = javaProject.findType(className); if (type != null && type.exists()) { if (type.isBinary()) { return type.getClassFile().getBytes(); } else { IJavaProject typeProject = type.getJavaProject(); if (!javaProject.equals(typeProject)) { return getClassContent(typeProject, className); } } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.eclipse.edt.debug.internal.core.java.SMAPBuilder.java
License:Open Source License
private void buildAll() throws CoreException { // Performance: only visit the bin directories. IJavaProject project = JavaCore.create(getProject()); IClasspathEntry[] cp = project.getResolvedClasspath(true); Set<IPath> binDirectories = new HashSet<IPath>(cp.length); for (IClasspathEntry entry : cp) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null) { binDirectories.add(outputLocation); }/*from w w w . j a v a 2 s.com*/ } } IPath outputLocation = project.getOutputLocation(); if (outputLocation != null) { binDirectories.add(outputLocation); } ResourceVisitor visitor = new ResourceVisitor(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IPath path : binDirectories) { IResource resource = root.findMember(path); if (resource != null) { resource.accept(visitor); } } }
From source file:org.eclipse.edt.ide.deployment.services.generators.ServiceUriMappingGenerator.java
License:Open Source License
private static String createClasspath(IJavaProject javaProject) throws JavaModelException, MalformedURLException, URISyntaxException { StringBuffer classpath = new StringBuffer(); String path;//ww w. ja va 2s . c om IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true); for (int i = 0; i < resolvedClasspath.length; i++) { IClasspathEntry entry = resolvedClasspath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { path = entry.getPath().toPortableString(); } else { if (entry.getOutputLocation() != null) { path = javaProject.getProject().getLocation().removeLastSegments(1) .append(entry.getOutputLocation()).toPortableString(); } else { path = javaProject.getProject().getLocation().removeLastSegments(1) .append(javaProject.getOutputLocation()).toPortableString(); } } classpath.append(path); classpath.append(";"); } return classpath.toString(); }
From source file:org.eclipse.edt.ide.ui.internal.eglarpackager.EglarUtility.java
License:Open Source License
public static Set<IPath> getOutputLocation(IProject project) { Set<IPath> paths = new HashSet<IPath>(); try {/*ww w. j a v a2 s .c o m*/ IJavaProject javaProject = null; if (JavaEEProjectUtilities.isDynamicWebProject(project) || project.hasNature("org.eclipse.jdt.core.javanature")) { javaProject = JavaCore.create(project); paths.add(javaProject.getOutputLocation()); } if (javaProject != null) { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getOutputLocation() != null) { paths.add(entries[i].getOutputLocation()); } } } } catch (Exception ex) { ex.printStackTrace(); } return paths; }
From source file:org.eclipse.edt.ide.ui.internal.externaltype.wizards.javatype.ExternalTypeFromJavaPage.java
License:Open Source License
private ClassLoader getURLClassLoader() { if (urlClassLoader == null) { List<URL> classPathURLs = new ArrayList<URL>(); try {//Add Java class path. IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot pRoot : roots) { IJavaProject refProject = pRoot.getParent().getJavaProject(); IPath proRoot = refProject.getProject().getLocation(); if (pRoot.isArchive() && pRoot.isExternal()) { classPathURLs.add(pRoot.getResolvedClasspathEntry().getPath().toFile().toURI().toURL()); } else if (pRoot.isArchive() && pRoot.getResource() != null) { classPathURLs.add(proRoot.append(pRoot.getResource().getProjectRelativePath()).toFile() .toURI().toURL()); } else { //source folder IPath outputRelPath = refProject.getOutputLocation().removeFirstSegments(1); classPathURLs.add(proRoot.append(outputRelPath).toFile().toURI().toURL()); }/*from www. j a v a2s . c o m*/ } } catch (Throwable ee) { ee.printStackTrace(); } ClassLoader parent = Thread.currentThread().getContextClassLoader(); URL[] urlPaths = new URL[classPathURLs.size()]; urlClassLoader = new URLClassLoader(classPathURLs.toArray(urlPaths), parent); } return urlClassLoader; }
From source file:org.eclipse.emf.codegen.ecore.gwt.GWTBuilder.java
License:Open Source License
@SuppressWarnings("rawtypes") @Override// w w w . ja va 2s.c o m protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { Set<IProject> result = new HashSet<IProject>(); final IProject project = getProject(); if (project.exists()) { IWorkspaceRoot root = project.getWorkspace().getRoot(); IJavaProject javaProject = JavaCore.create(project); IClasspathContainer gaeClasspathContainer = JavaCore.getClasspathContainer( new Path("com.google.appengine.eclipse.core.GAE_CONTAINER"), javaProject); if (gaeClasspathContainer != null) { for (IClasspathEntry classpathEntry : gaeClasspathContainer.getClasspathEntries()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) { IPath path = classpathEntry.getPath(); int segmentCount = path.segmentCount(); if (segmentCount >= 4) { if (path.segment(segmentCount - 2).equals("user") || path.segment(segmentCount - 3).equals("user")) { copy(URI.createFileURI(path.toOSString()), URI.createPlatformResourceURI( project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true)); } } } } } IClasspathContainer gwtClasspathContainer = JavaCore .getClasspathContainer(new Path("com.google.gwt.eclipse.core.GWT_CONTAINER"), javaProject); if (gwtClasspathContainer != null) { for (IClasspathEntry classpathEntry : gwtClasspathContainer.getClasspathEntries()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) { IPath path = classpathEntry.getPath(); int segmentCount = path.segmentCount(); if (segmentCount >= 2) { path = path.removeLastSegments(1).append("gwt-servlet.jar"); URI fileURI = URI.createFileURI(path.toOSString()); if (URIConverter.INSTANCE.exists(fileURI, null)) { copy(fileURI, URI.createPlatformResourceURI( project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true)); } } } } } IClasspathContainer pdeClasspathContainer = JavaCore .getClasspathContainer(new Path("org.eclipse.pde.core.requiredPlugins"), javaProject); if (pdeClasspathContainer != null) { for (IClasspathEntry classpathEntry : pdeClasspathContainer.getClasspathEntries()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProject = root.getProject(classpathEntry.getPath().segment(0)); IJavaProject requiredJavaProject = JavaCore.create(requiredProject); IPath outputLocation = requiredJavaProject.getOutputLocation(); final int depth = outputLocation.segmentCount(); IFolder folder = root.getFolder(outputLocation); folder.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource.getType() == IResource.FILE) { IPath fullPath = resource.getFullPath(); copy(URI.createPlatformResourceURI(fullPath.toString(), true), URI.createPlatformResourceURI(project.getName() + "/war/WEB-INF/classes/" + fullPath.removeFirstSegments(depth), true)); } return true; } }, IResource.DEPTH_INFINITE, 0); result.add(requiredProject); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) { IPath path = classpathEntry.getPath(); copy(URI.createFileURI(path.toOSString()), URI.createPlatformResourceURI( project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true)); } } } } return result.toArray(new IProject[result.size()]); }
From source file:org.eclipse.emf.ecore.xcore.ui.XcoreJavaProjectProvider.java
License:Open Source License
public ClassLoader getClassLoader(ResourceSet resourceSet) { IJavaProject project = getJavaProject(resourceSet); if (project != null) { IProject iProject = project.getProject(); IWorkspaceRoot workspaceRoot = iProject.getWorkspace().getRoot(); List<URL> libraryURLs = new UniqueEList<URL>(); try {//from w w w .j a va 2 s . co m getAllReferencedProjects(libraryURLs, new IProject[] { iProject }); IClasspathEntry[] classpath = project.getResolvedClasspath(true); if (classpath != null) { String projectName = iProject.getName(); for (int i = 0; i < classpath.length; ++i) { IClasspathEntry classpathEntry = classpath[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: { IPath path = classpathEntry.getPath(); if (path.segment(0).equals(projectName)) { path = iProject.getLocation().append(path.removeFirstSegments(1)); } libraryURLs.add(new URL(URI.createFileURI(path.toString()).toString())); break; } case IClasspathEntry.CPE_PROJECT: { IPath path = classpathEntry.getPath(); IProject referencedProject = workspaceRoot.getProject(path.segment(0)); IJavaProject referencedJavaProject = JavaCore.create(referencedProject); IContainer container = workspaceRoot .getFolder(referencedJavaProject.getOutputLocation()); libraryURLs.add(new URL( URI.createFileURI(container.getLocation().toString() + "/").toString())); IProjectDescription description = referencedProject.getDescription(); getAllReferencedProjects(libraryURLs, description.getReferencedProjects()); getAllReferencedProjects(libraryURLs, description.getDynamicReferences()); break; } case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_VARIABLE: default: { break; } } } } return new URLClassLoader(libraryURLs.toArray(new URL[libraryURLs.size()]), getClass().getClassLoader()); } catch (MalformedURLException exception) { exception.printStackTrace(); } catch (JavaModelException exception) { exception.printStackTrace(); } catch (CoreException exception) { exception.printStackTrace(); } } for (Resource resource : resourceSet.getResources()) { URI uri = resource.getURI(); if (uri.isPlatformPlugin()) { final Bundle bundle = Platform.getBundle(uri.segments()[1]); return new ClassLoader() { @Override public Enumeration<URL> findResources(String name) throws IOException { return bundle.getResources(name); } @Override public URL findResource(String name) { return bundle.getResource(name); } @Override public URL getResource(String name) { return findResource(name); } @Override public Class<?> findClass(String name) throws ClassNotFoundException { return bundle.loadClass(name); } @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> clazz = findClass(name); if (resolve) { resolveClass(clazz); } return clazz; } }; } } return null; }
From source file:org.eclipse.emf.ecore.xcore.ui.XcoreJavaProjectProvider.java
License:Open Source License
protected void getAllReferencedProjects(Collection<URL> libraryURLs, IProject[] projects) throws CoreException, MalformedURLException { for (int i = 0; i < projects.length; ++i) { IProject project = projects[i];// www. j a v a2 s . co m if (project.exists() && project.isOpen()) { IJavaProject referencedJavaProject = JavaCore.create(project); IContainer container = project.getWorkspace().getRoot() .getFolder(referencedJavaProject.getOutputLocation()); if (libraryURLs .add(new URL(URI.createFileURI(container.getLocation().toString() + "/").toString()))) { IProjectDescription description = project.getDescription(); getAllReferencedProjects(libraryURLs, description.getReferencedProjects()); getAllReferencedProjects(libraryURLs, description.getDynamicReferences()); } } } }
From source file:org.eclipse.emf.importer.java.builder.JavaEcoreBuilder.java
License:Open Source License
/** * Walks the container recursively./*from w ww. j av a2 s .c om*/ */ public void getAllGenModelFiles(Collection<IFile> result, IFile file) throws CoreException { if (file.getName().endsWith(".genmodel")) { IProject project = file.getProject(); IJavaProject javaProject = JavaCore.create(project); try { IPath outputLocation = javaProject.getOutputLocation(); if (project == project.getWorkspace().getRoot().findMember(javaProject.getOutputLocation()) || !outputLocation.isPrefixOf(file.getFullPath())) { result.add(file); } } catch (JavaModelException exception) { JavaImporterPlugin.INSTANCE.log(exception); } } }
From source file:org.eclipse.emf.java.presentation.JavaEditor.java
License:Open Source License
public void setupClassLoader(IProject project) { JavaPackageResourceImpl javaPackageResource = (JavaPackageResourceImpl) editingDomain .loadResource(JavaUtil.JAVA_PACKAGE_RESOURCE); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); List<URL> libraryURLs = new UniqueEList<URL>(); List<String> sourceURIs = new ArrayList<String>(); try {/*from ww w.j a v a2 s .c o m*/ IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); if (classpath != null) { for (int i = 0; i < classpath.length; ++i) { IClasspathEntry classpathEntry = classpath[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: { libraryURLs.add(new URL(URI.createFileURI(classpathEntry.getPath().toString()).toString())); break; } case IClasspathEntry.CPE_SOURCE: { sourceURIs.add( URI.createPlatformResourceURI(classpathEntry.getPath().toString(), true) + "/"); break; } case IClasspathEntry.CPE_PROJECT: { IProject referencedProject = workspaceRoot.getProject(classpathEntry.getPath().segment(0)); IJavaProject referencedJavaProject = JavaCore.create(referencedProject); IContainer container = workspaceRoot.getFolder(referencedJavaProject.getOutputLocation()); libraryURLs.add( new URL(URI.createFileURI(container.getLocation().toString() + "/").toString())); getAllReferencedProjects(libraryURLs, referencedProject.getDescription().getReferencedProjects()); getAllReferencedProjects(libraryURLs, referencedProject.getDescription().getDynamicReferences()); break; } case IClasspathEntry.CPE_VARIABLE: default: { break; } } } } javaPackageResource.setClassLoader(new URLClassLoader(libraryURLs.toArray(new URL[libraryURLs.size()]), new URLClassLoader(new URL[0], null))); javaPackageResource.getSourceURIs().addAll(sourceURIs); } catch (MalformedURLException exception) { exception.printStackTrace(); } catch (JavaModelException exception) { exception.printStackTrace(); } catch (CoreException exception) { exception.printStackTrace(); } }