List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:org.eclipse.emf.codegen.ecore.gwt.GWTBuilder.java
License:Open Source License
@SuppressWarnings("rawtypes") @Override/* w ww . ja v a 2 s .c om*/ 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.quickfix.XcoreClasspathUpdater.java
License:Open Source License
protected boolean addJarToClasspath(IJavaProject javaProject, IPath location, IProgressMonitor monitor) throws JavaModelException { IClasspathEntry newClasspthEntry = JavaCore.newLibraryEntry(location, null, null); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1]; for (int i = 0; i < rawClasspath.length; ++i) { IClasspathEntry entry = rawClasspath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(location)) { return false; }//from w ww . j a v a 2 s .co m newRawClasspath[i + 1] = entry; } newRawClasspath[0] = newClasspthEntry; javaProject.setRawClasspath(newRawClasspath, monitor); return true; }
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 {// w ww . j a v a 2 s . c o 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.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 w w w .ja v a 2 s. co 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(); } }
From source file:org.eclipse.emf.mwe.internal.ui.debug.sourcelookup.SourceFolderSourceContainer.java
License:Open Source License
/** * create a FolderSourceContainer for each declared source folder of the java project *///from ww w .j a va 2s .c o m @Override protected ISourceContainer[] createSourceContainers() throws CoreException { if (fSourceFolders == null) { List<ISourceContainer> containers = new ArrayList<ISourceContainer>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (fProject.getProject().isOpen()) { IClasspathEntry[] entries = fProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IPath path = entry.getPath(); IResource resource = root.findMember(path); if (resource instanceof IContainer) { containers.add(new FolderSourceContainer((IContainer) resource, false)); } break; } } } fSourceFolders = containers.toArray(new ISourceContainer[containers.size()]); } return fSourceFolders; }
From source file:org.eclipse.fx.ide.ui.preview.LivePreviewSynchronizer.java
License:Open Source License
private void resolveDataProject(IJavaProject project, Set<IPath> outputPath, Set<IPath> listRefLibraries) { // System.err.println("START RESOLVE: " + project.getElementName()); try {/*from w w w . j av a 2 s. c om*/ IClasspathEntry[] entries = project.getRawClasspath(); outputPath.add(project.getOutputLocation()); for (IClasspathEntry e : entries) { // System.err.println(e + " ====> " + e.getEntryKind()); 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) { // System.err.println("CPE_LIBRARY PUSHING: " + e.getPath()); 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) { // System.err.println("requiredPlugins & CPE_LIBRARY PUSHING: " + e.getPath()); listRefLibraries.add(cpEntry.getPath()); } } } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (!e.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER") && !e.getPath().toString().startsWith("org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER")) { // System.err.println("====> A container"); IClasspathContainer cp = JavaCore.getClasspathContainer(e.getPath(), project); for (IClasspathEntry ce : cp.getClasspathEntries()) { // System.err.println(ce.getEntryKind() + "=> " + ce); if (ce.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(ce.getPath()); } else if (ce.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot() .getProject(ce.getPath().lastSegment()); if (p.exists()) { resolveDataProject(JavaCore.create(p), outputPath, listRefLibraries); } } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.err.println("END RESOLVE"); }
From source file:org.eclipse.imp.asl.compiler.ASLCompiler.java
License:Open Source License
private IPath findSrcFolderRelativePath(IFile file, IJavaProject javaProject) throws JavaModelException { final IPath folderPath = file.getFullPath().removeLastSegments(1); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IPath entryPath = entry.getPath(); if (entryPath.isPrefixOf(folderPath)) { int segCount = entryPath.matchingFirstSegments(folderPath); return folderPath.removeFirstSegments(segCount); }//from ww w . ja v a 2 s . co m } } return null; }
From source file:org.eclipse.imp.java.hosted.BuildPathUtils.java
License:Open Source License
/** * // w ww . j ava 2s .co m * @param filePath * @param project * @return a String representing the filePath relative to the source directory that contains it, and without a file extension. * @throws JavaModelException */ public static String getBareName(IPath filePath, IJavaProject project) throws JavaModelException { for (final IClasspathEntry cpEntry : project.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpEntry.getPath().isPrefixOf(filePath) && !BuildPathUtils.isExcluded(filePath, cpEntry)) { return filePath.makeRelativeTo(cpEntry.getPath()).removeFileExtension().toOSString(); } } return null; }
From source file:org.eclipse.imp.java.hosted.BuildPathUtils.java
License:Open Source License
/** * @param filePath/*from w w w .j a va 2 s . co m*/ * @param project * @return true if the given file is excluded from the source path of the given project */ public static boolean isExcluded(IPath filePath, final IJavaProject project) { try { // --- Determine the classpath source entry that corresponds to file. if (project == null) { return true; // --- If there is no java project associated with this file, then the file must be // excluded. } // --- If filePath is not relative to the workspace, make it so. IPath workspace = project.getProject().getLocation().removeLastSegments(1); if (workspace.isPrefixOf(filePath)) { filePath = filePath.makeRelativeTo(workspace); } for (final IClasspathEntry cpEntry : project.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpEntry.getPath().isPrefixOf(filePath) && !isExcluded(filePath, cpEntry)) { return false; } } } catch (JavaModelException e) { return true; } return true; }