List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
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 *//*w w w . ja va 2 s .co m*/ 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 ww w. j ava 2s.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 {//w w w .j a va 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) && !"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.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 w w . j a v a2s . co 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.jdt.ui.internal.handler.AbstractBuildHandler.java
License:Open Source License
private ILaunchConfiguration getLaunchConfig(File buildFile, BuildConfiguration cfgData, IFile buildCfgFile) throws CoreException { ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = mgr//from w w w. ja va 2s.c o m .getLaunchConfigurationType("org.eclipse.ant.AntLaunchConfigurationType"); if (type != null) { String name = (String) cfgData.builderName; if (name == null) { name = "JFX Build - " + cfgData.projectName; } File fBuildFile = new File(cfgData.buildDirectory + "/build.xml"); for (ILaunchConfiguration cfg : mgr.getLaunchConfigurations(type)) { if (cfg.getName().equals(name)) { String s = cfg.getAttribute(IExternalToolConstants.ATTR_LOCATION, IExternalToolConstants.EMPTY_STRING); if (!s.equals("") && new File(s).equals(fBuildFile)) { return cfg; } else { cfg.delete(); } } } ILaunchConfigurationWorkingCopy cfg = type.newInstance(null, name); cfg.setAttribute(IExternalToolConstants.ATTR_LOCATION, buildFile.getAbsolutePath()); cfg.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, buildFile.getParentFile().getAbsolutePath()); cfg.setAttribute("org.eclipse.debug.core.ATTR_REFRESH_SCOPE", "${project}"); cfg.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false); cfg.setAttribute("org.eclipse.jdt.launching.MAIN_TYPE", "org.eclipse.ant.internal.launching.remote.InternalAntRunner"); cfg.setAttribute("process_factory_id", "org.eclipse.ant.ui.remoteAntProcessFactory"); IVMInstall install = null; for (IClasspathEntry e : project.getRawClasspath()) { String start = e.getPath().segment(0); if (start.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) { install = JavaRuntime.getVMInstall(e.getPath()); cfg.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, e.getPath().toString()); } } if (!isJDK(install)) { if (MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Not a JDK", "The project is attached to a JRE only so ant would be started with a JRE which does not have a compiler. Would you like to proceed and select a JDK?")) { JDKSelectionDialog d = new JDKSelectionDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); if (d.open() == Window.OK) { cfg.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(d.install).toString()); } } else { return null; } } cfg.doSave(); return cfg; } return null; }
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 {//from www .j a v a2 s . 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.util.JavaModelUtil.java
License:Open Source License
/** * Finds an entry in a container. <code>null</code> is returned if the entry can not be found * @param container The container/*from www. j a v a2 s. c o m*/ * @param libPath The path of the library to be found * @return IClasspathEntry A classpath entry from the container of * <code>null</code> if the container can not be modified. */ public static IClasspathEntry findEntryInContainer(IClasspathContainer container, IPath libPath) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { IClasspathEntry curr = entries[i]; IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(curr); if (resolved != null && libPath.equals(resolved.getPath())) { return curr; // return the real entry } } return null; // attachment not possible }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {//from www . j a v a 2 s . c om IClasspathEntry rawEntry = root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry = JavaModelUtil.getClasspathEntry(root); if (entry.getReferencingEntry() != null) { return false; // not the variable entry itself, but a referenced entry } IPath path = rawEntry.getPath().makeRelative(); if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); if (segements > 1) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } } else { fBuffer.append(path.toString()); } } else { fBuffer.append(path.toString()); } int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); if (root.isExternal()) fBuffer.append(root.getPath().toOSString()); else fBuffer.append(root.getPath().makeRelative().toString()); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;//from www. ja v a 2 s . c om IClasspathEntry classpathEntry = null; try { classpathEntry = JavaModelUtil.getClasspathEntry(root); IPath rawPath = classpathEntry.getPath(); if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) path = rawPath; else path = root.getPath(); } catch (JavaModelException e) { path = root.getPath(); } if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); int offset = fBuffer.length(); if (segements > 1 || path.getDevice() != null) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuffer.append( Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } else { fBuffer.append(path.toOSString()); } } else { fBuffer.append(path.toOSString()); } }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) { IResource resource = root.getResource(); boolean rootQualified = getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else {//from ww w .j a va 2s. c o m fBuffer.append(root.getElementName()); int offset = fBuffer.length(); boolean referencedPostQualified = getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED); if (referencedPostQualified && isReferenced(root)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(resource.getParent().getFullPath().makeRelative().toString()); } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(root.getParent().getPath().makeRelative().toString()); } if (referencedPostQualified) { try { IClasspathEntry referencingEntry = JavaModelUtil.getClasspathEntry(root).getReferencingEntry(); if (referencingEntry != null) { fBuffer.append( Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } catch (JavaModelException e) { // ignore } } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } }