List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.google.test.metric.eclipse.internal.core.TestabilityLauncher.java
License:Apache License
public String[] getClassPaths(IJavaProject javaProject, String projectLocation) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); String[] classPaths = new String[classPathEntries.length + 1]; for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classPathEntry = classPathEntries[i]; String classPathString = null; IPath outputPath = classPathEntry.getOutputLocation(); if (outputPath != null) { classPathString = projectLocation + outputPath.toOSString(); } else {/*from w w w. jav a 2 s.c o m*/ IPath classPath = classPathEntry.getPath(); classPathString = classPath.toOSString(); if (!classPathString.startsWith(System.getProperty("file.separator"))) { classPathString = System.getProperty("file.separator") + classPathString; } classPathString = projectLocation + classPathString; } classPathString = classPathString.replace("\\", "/"); classPaths[i] = classPathString; } String defaultOutputPath = javaProject.getOutputLocation().toOSString(); defaultOutputPath = defaultOutputPath.replace("\\", "/"); classPaths[classPathEntries.length] = projectLocation + defaultOutputPath; return classPaths; }
From source file:com.ibm.research.tours.content.url.delegates.ClassFileTextRegionURLTourElementDelegate.java
License:Open Source License
private void init() { IPackageFragmentRoot root = null;/*from ww w . j a va 2s. c o m*/ root = JavaModelUtil.getPackageFragmentRoot(fFile); IClasspathEntry entry = null; try { entry = root.getRawClasspathEntry(); } catch (JavaModelException e) { e.printStackTrace(); } if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IPath path = entry.getPath().makeRelative(); } }
From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java
License:Open Source License
@Override protected void resolveClasspathEntry(IJavaProject project, IClasspathEntry entry, ILoader loader, boolean includeSource, boolean cpeFromMainProject) { entry = JavaCore.getResolvedClasspathEntry(entry); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { resolveSourcePathEntry(includeSource ? JavaSourceLoader.SOURCE : Loader.APPLICATION, includeSource, cpeFromMainProject, entry.getPath(), entry.getOutputLocation(), entry.getExclusionPatterns(), "java"); break;/*from www .j a va 2 s.co m*/ } case IClasspathEntry.CPE_LIBRARY: { resolveLibraryPathEntry(loader, entry.getPath()); break; } case IClasspathEntry.CPE_PROJECT: { resolveProjectPathEntry(loader, includeSource, entry.getPath()); break; } case IClasspathEntry.CPE_CONTAINER: { try { IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project); IClasspathEntry[] entries = cont.getClasspathEntries(); resolveClasspathEntries(project, Arrays.asList(entries), cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL, includeSource, false); } catch (CoreException e) { System.err.println(e); Assertions.UNREACHABLE(); } } } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
static ISourceContainer getProjectSourceContainer(IJavaProject javaProject) { List<ISourceContainer> containers = new ArrayList<ISourceContainer>(); boolean hasSources = false; try {/* w w w.j a va 2 s . c om*/ for (IClasspathEntry cpe : javaProject.getRawClasspath()) { switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: hasSources = true; break; case IClasspathEntry.CPE_LIBRARY: IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource lib = workspaceRoot.findMember(cpe.getPath()); IPackageFragmentRoot fragmentRoot; if (lib != null) { fragmentRoot = javaProject.getPackageFragmentRoot(lib); } else { fragmentRoot = javaProject.getPackageFragmentRoot(cpe.getPath().toOSString()); } containers.add(new PackageFragmentRootSourceContainer(fragmentRoot)); break; } } } catch (JavaModelException e) { // ignore... maybe log } if (hasSources) { containers.add(0, new JavaProjectSourceContainer(javaProject)); } if (containers.isEmpty()) { return null; } if (containers.size() == 1) { return containers.get(0); } return new CompositeSourceContainer(containers); }
From source file:com.iw.plugins.spindle.core.builder.TapestryBuilder.java
License:Mozilla Public License
public static IProject[] getBuildInterestingProjects(IJavaProject jproject, IWorkspaceRoot root) { if (jproject == null || root == null) return new IProject[0]; ArrayList projects = new ArrayList(); try {//from w w w.j a va 2 s .com IClasspathEntry[] entries = ((JavaProject) jproject).getExpandedClasspath(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(entries[i]); if (entry != null) { IPath path = entry.getPath(); IProject p = null; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject workspaceProject = root.getProject(path.lastSegment()); if (workspaceProject.hasNature(JavaCore.NATURE_ID)) p = workspaceProject; } if (p != null && !projects.contains(p)) projects.add(p); } } } catch (CoreException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java
License:Mozilla Public License
/** * @param entries/*from w w w. j a v a 2 s .co m*/ * @return */ private IClasspathEntry[] checkEntries(IClasspathEntry[] entries) throws CoreException { if (entries == null) { createSrcFolder(); return new IClasspathEntry[] { createSrcClasspathEntry(), TapestryProjectInstallData.TAPESTRY_FRAMEWORK, JavaRuntime.getDefaultJREContainerEntry() }; } boolean hasSrcEntry = false; boolean hasTapestryEntry = false; boolean hasDefaultJREEntry = false; List allEntries = Arrays.asList(entries); for (Iterator iter = allEntries.iterator(); iter.hasNext();) { IClasspathEntry element = (IClasspathEntry) iter.next(); if (!hasSrcEntry && element.getEntryKind() == IClasspathEntry.CPE_SOURCE) { hasSrcEntry = true; } else if (element.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (!hasTapestryEntry) hasTapestryEntry = element.getPath().segment(0).equals(TapestryCore.CORE_CONTAINER); if (!hasDefaultJREEntry) hasDefaultJREEntry = element.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER); } } if (!hasSrcEntry) { createSrcFolder(); allEntries.add(createSrcClasspathEntry()); } if (!hasTapestryEntry) allEntries.add(TapestryProjectInstallData.TAPESTRY_FRAMEWORK); if (!hasDefaultJREEntry) allEntries.add(JavaRuntime.getDefaultJREContainerEntry()); return (IClasspathEntry[]) allEntries.toArray(new IClasspathEntry[allEntries.size()]); }
From source file:com.iw.plugins.spindle.wizards.project.ContainerDialogField.java
License:Mozilla Public License
public void setClasspathEntry(IClasspathEntry root, boolean canBeModified) { currentRoot = root;// w w w . j a v a 2 s. co m String str = (root == null) ? "" : root.getPath().toString(); setTextValue(str); setEnabled(canBeModified); }
From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java
License:Open Source License
/** * Get all the resolved classpath entries for a specific project. The entries * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved * or included in the result. At also add the source and output folder provided with the * project//from ww w .ja v a 2s . c o m * * @param project the project where the file to compile is contained, must be not null * @return a not null list of string that contains the classpath to include in the compilation project */ private List<String> getClasspaths(IProject project) { IJavaProject jprj = JavaCore.create(project); List<String> classpath = new ArrayList<String>(); IWorkspaceRoot wsRoot = project.getWorkspace().getRoot(); if (jprj != null) { try { IClasspathEntry[] entries = jprj.getRawClasspath(); //Add the default output folder if any IPath defaultLocationPath = jprj.getOutputLocation(); if (defaultLocationPath != null) { IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } for (IClasspathEntry en : entries) { if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String containerPath = en.getPath().toString(); //Don't add the eclipse runtime and the classpath extension defined in the exclusion list if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER) && !classpathExclusionSet.contains(containerPath)) { addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath, jprj); } } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) { classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator); } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) { //check if is a source folder and if it has a custom output folder to add them also to the classpath IPath entryOutputLocation = en.getOutputLocation(); if (entryOutputLocation != null) { IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation); classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator); } } else { //It is a jar check if it is internal to the workspace of external IPath location = wsRoot.getFile(en.getPath()).getLocation(); if (location == null) { //The location could not be resolved from the root of the workspace, it is external classpath.add(en.getPath().toOSString()); } else { //The location has been resolved from the root of the workspace, it is internal classpath.add(location.toOSString()); } } } } catch (Exception ex) { ex.printStackTrace(); } } return classpath; }
From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java
License:Open Source License
/** * Add an array of classpath entry to the result set. If an entry is a classpath container * then it is resolved and the resulting entries are added recursively * //from w w w . j a va 2 s. com * @param entries the entries to add * @param classpath the current result * @param jprj the current java project */ private void addEntries(IClasspathEntry[] entries, List<String> classpath, IJavaProject jprj) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); for (IClasspathEntry en : entries) { if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { try { addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath, jprj); } catch (Exception ex) { ex.printStackTrace(); } } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT || en.getEntryKind() == IClasspathEntry.CPE_SOURCE) { classpath.add(workspace.getRoot().findMember(en.getPath()).getLocation().toOSString() + File.separator + "*"); //$NON-NLS-1$ } else { classpath.add(en.getPath().toOSString()); } } }
From source file:com.javadude.antxr.eclipse.core.AntxrNature.java
License:Open Source License
public void configure() throws CoreException { if (AntxrNature.DEBUG) { System.out.println("configuring ANTXR nature"); }// www . j a va 2s.c o m IProject project = getProject(); IProjectDescription projectDescription = project.getDescription(); List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(projectDescription.getBuildSpec())); ICommand antxrBuilderCommand = projectDescription.newCommand(); antxrBuilderCommand.setBuilderName(AntxrBuilder.BUILDER_ID); ICommand warningCleanerBuilderCommand = projectDescription.newCommand(); warningCleanerBuilderCommand.setBuilderName(WarningCleanerBuilder.BUILDER_ID); ICommand smapBuilderCommand = projectDescription.newCommand(); smapBuilderCommand.setBuilderName(SMapInstallerBuilder.BUILDER_ID); if (!commands.contains(antxrBuilderCommand)) { commands.add(0, antxrBuilderCommand); // add at start } if (!commands.contains(warningCleanerBuilderCommand)) { commands.add(warningCleanerBuilderCommand); // add at end } if (!commands.contains(smapBuilderCommand)) { commands.add(smapBuilderCommand); // add at end } // Commit the spec change into the project projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()])); getProject().setDescription(projectDescription, null); // // add the antxr.jar file to a lib dir // IFolder folder = getProject().getFolder("lib"); // if (!folder.exists()) { // folder.create(true, true, null); // } // IPath rawLocation = folder.getRawLocation(); // URL antxrJarUrl = AntxrCorePlugin.getDefault().getBundle().getEntry("lib/antxr.jar"); // // BufferedOutputStream bout = null; // BufferedInputStream bin = null; // int b; // try { // try { // bout = new BufferedOutputStream(new FileOutputStream(new File(rawLocation.toFile(), "antxr.jar"))); // bin = new BufferedInputStream(antxrJarUrl.openStream()); // while ((b = bin.read()) != -1) { // bout.write(b); // } // } finally { // if (bout != null) { // bout.close(); // } // if (bin != null) { // bin.close(); // } // } // } catch (IOException e) { // e.printStackTrace(); // } // // folder.refreshLocal(IResource.DEPTH_ONE, null); // // // add the jar to the classpath if not present // String jarPath = "/" + getProject().getName() + "/lib/antxr.jar"; IFolder antxr3GeneratedFolder = getProject().getFolder("antxr-generated"); if (!antxr3GeneratedFolder.exists()) { antxr3GeneratedFolder.create(true, true, null); } String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated"; final IJavaProject javaProject = JavaCore.create(getProject()); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean generatedSourceDirFound = false; for (IClasspathEntry classpathEntry : rawClasspath) { // if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // if (classpathEntry.getPath().toString().equals(jarPath)) { // found = true; // } // } if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (classpathEntry.getPath().toString().equals(generatedSourcePath)) { generatedSourceDirFound = true; } } } int toAdd = 0; if (!generatedSourceDirFound) { toAdd++; } if (!generatedSourceDirFound) { final IClasspathEntry newEntries[] = new IClasspathEntry[rawClasspath.length + toAdd]; System.arraycopy(rawClasspath, 0, newEntries, 0, rawClasspath.length); // newEntries[rawClasspath.length] = JavaCore.newLibraryEntry(new Path(jarPath), Path.EMPTY, Path.ROOT); if (!generatedSourceDirFound) { newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(new Path(generatedSourcePath)); } JavaCore.run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { javaProject.setRawClasspath(newEntries, null); } }, null); } }