List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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 w w . 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 *//*from w ww . j av a2 s. co 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:at.bestsolution.efxclipse.robovm.RobovmSetupHandler.java
License:Open Source License
private void resolveDataProject(IJavaProject project, Set<IPath> listProjectSourceDirs, Set<IPath> listRefProjectSourceDirs, Set<IPath> listRefLibraries) { try {/*from w w w.j a v a2 s.c o m*/ IClasspathEntry[] entries = project.getRawClasspath(); 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), listRefProjectSourceDirs, listRefProjectSourceDirs, listRefLibraries); } } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(e.getPath()); } else if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { listProjectSourceDirs.add(e.getPath()); } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String start = e.getPath().segment(0); // TODO remove hard coded strings if (!"org.eclipse.jdt.launching.JRE_CONTAINER".equals(start) && !"org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER".equals(start)) { IClasspathContainer cpe = JavaCore.getClasspathContainer(e.getPath(), project); IClasspathEntry[] cpEntries = cpe.getClasspathEntries(); for (IClasspathEntry tmp : cpEntries) { if (tmp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(tmp.getPath()); } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.bestsolution.efxclipse.tooling.css.cssext.ui.CssExtManager.java
License:Open Source License
public void searchClasspath(URI uri) { IJavaProject project = getJavaprojectFromPlatformURI(uri); try {//from w w w .ja va2 s .co m for (IClasspathEntry entry : project.getRawClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.handler.AbstractAntHandler.java
License:Open Source License
private void resolveDataProject(IJavaProject project, Set<IPath> listProjectSourceDirs, Set<IPath> listRefProjectSourceDirs, Set<IPath> listRefLibraries) { try {/*from w ww .j ava 2 s . c o m*/ IClasspathEntry[] entries = project.getRawClasspath(); 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), listRefProjectSourceDirs, listRefProjectSourceDirs, listRefLibraries); } } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(e.getPath()); } else if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { listProjectSourceDirs.add(e.getPath()); } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String start = e.getPath().segment(0); // TODO remove hard coded strings if (!"org.eclipse.jdt.launching.JRE_CONTAINER".equals(start) && !"at.bestsolution.efxclipse.tooling.jdt.core.JAVAFX_CONTAINER".equals(start)) { IClasspathContainer cpe = JavaCore.getClasspathContainer(e.getPath(), project); IClasspathEntry[] cpEntries = cpe.getClasspathEntries(); for (IClasspathEntry tmp : cpEntries) { if (tmp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { listRefLibraries.add(tmp.getPath()); } } } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
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 {/* w w 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.fxide.jdt.corext.javadoc.JavaDocLocations.java
License:Open Source License
public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException { if (element.getElementType() == IJavaElement.JAVA_PROJECT) { return getProjectJavadocLocation((IJavaProject) element); }//from ww w .j av a 2 s . c o m IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element); if (root == null) { return null; } if (root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry entry = root.getResolvedClasspathEntry(); URL javadocLocation = getLibraryJavadocLocation(entry); if (javadocLocation != null) { return getLibraryJavadocLocation(entry); } entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return getLibraryJavadocLocation(entry); default: return null; } } else { return getProjectJavadocLocation(root.getJavaProject()); } }
From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocLocations.java
License:Open Source License
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ }/*from www. j a v a2 s .c o m*/ int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return parseURL(attrib.getValue()); } } return null; }
From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java
License:Open Source License
/** * Returns the classpath entry of the given package fragment root. This is the raw entry, except * if the root is a referenced library, in which case it's the resolved entry. * * @param root a package fragment root// w w w . ja v a2 s.co m * @return the corresponding classpath entry * @throws JavaModelException if accessing the entry failed * @since 3.6 */ public static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry rawEntry = root.getRawClasspathEntry(); int rawEntryKind = rawEntry.getEntryKind(); switch (rawEntryKind) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry(); if (resolvedEntry.getReferencingEntry() != null) return resolvedEntry; else return rawEntry; } } return rawEntry; }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException { String encoding = ResourcesPlugin.getEncoding(); IClasspathEntry entry = root.getRawClasspathEntry(); if (entry != null) { int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) { IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); }/* ww w .j a v a2 s.c om*/ } } } return encoding; }