List of usage examples for org.eclipse.jdt.core IClasspathEntry getOutputLocation
IPath getOutputLocation();
.class
files generated for this source entry (entry kind #CPE_SOURCE ). From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java
License:Open Source License
private Map<IContainer, IContainer> generateSourceToOut(IJavaProject project) throws JavaModelException { IProject p = project.getProject();// www.java2 s .c o m IWorkspaceRoot root = (IWorkspaceRoot) p.getParent(); IClasspathEntry[] cp = project.getRawClasspath(); // determine default out folder IPath defaultOutPath = project.getOutputLocation(); IContainer defaultOutContainer; if (defaultOutPath.segmentCount() > 1) { defaultOutContainer = root.getFolder(defaultOutPath); } else { defaultOutContainer = p; } Map<IContainer, IContainer> sourceToOut = new TreeMap<IContainer, IContainer>(comparator); for (IClasspathEntry cpe : cp) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // determine source folder IContainer sourceContainer; IPath sourcePath = cpe.getPath(); if (sourcePath.segmentCount() > 1) { sourceContainer = root.getFolder(sourcePath); } else { sourceContainer = p; } // determine out folder IPath outPath = cpe.getOutputLocation(); IContainer outContainer; if (outPath == null) { outContainer = defaultOutContainer; } else if (outPath.segmentCount() > 1) { outContainer = root.getFolder(outPath); } else { outContainer = p; } // if the two containers are equal, that means no copying should be done // do not add to map if (!sourceContainer.equals(outContainer)) { sourceToOut.put(sourceContainer, outContainer); } } } return sourceToOut; }
From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java
License:Apache License
private void getClassPathEntries(IJavaProject prj, ArrayList data, List selectedPaths, ArrayList visitedProjects) { IClasspathEntry[] entries = null;/*from w w w . j av a 2s .com*/ IPath outputPath = null; try { outputPath = prj.getOutputLocation(); if (selectedPaths.contains(outputPath.toFile().toString().replace('\\', '/'))) { add(data, prj.getProject().getWorkspace().getRoot().findMember(outputPath)); } entries = prj.getRawClasspath(); } catch (JavaModelException e) { DbfLauncherPlugin.log(e); } if (entries == null) return; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { path = entry.getOutputLocation(); if (path == null) continue; } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = entry.getPath().lastSegment(); if (!visitedProjects.contains(prjName)) { visitedProjects.add(prjName); getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths, visitedProjects); } continue; } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/'))) continue; IClasspathEntry[] tmpEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { try { tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries(); } catch (JavaModelException e1) { DbfLauncherPlugin.log(e1); continue; } } else { tmpEntry = new IClasspathEntry[1]; tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry); } for (int j = 0; j < tmpEntry.length; j++) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath()); if (res != null) add(data, res); else add(data, tmpEntry[j].getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcPath = entry.getOutputLocation(); if (srcPath != null && !srcPath.equals(outputPath)) { add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath)); } } else { add(data, tmpEntry[j].getPath()); } } } }
From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Adds source output entries to the classpath * /* www . jav a2 s . c o m*/ * @param doc the document * @param path the path element that the entries are being added under * @param srcEntries list of source entries to be added */ private static void addSourceOutputEntries(Document doc, Element path, List<IClasspathEntry> srcEntries) { if (srcEntries != null) { Set<String> dirs = new HashSet<>(); for (IClasspathEntry entry : srcEntries) { IPath outputPath = entry.getOutputLocation(); if (outputPath != null) { String relativePath = outputPath.toOSString().substring(1); if (!dirs.contains(relativePath)) { dirs.add(relativePath); addPathElement(doc, path, relativePath); } } } } }
From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Returns an image descriptor for the image file at the given * plug-in relative path/*www .j a v a 2s .co m*/ * * @param doc the document * @param root the root element * @param prjOutputDirectory the output directory * @param list the list of projects that the calling project * depends on * @param projectName the name of the calling project * @param isRoot is this project the root * @return the image descriptor */ private static void setBuildTarget(Document doc, Element root, String outputDirectory, List<ImprovedClasspathHandler> dependentProjects, List<IClasspathEntry> srcEntries, String projectName, Set<String> filePaths, String prjEncoding) { String prjOutputDirectory = outputDirectory.substring(1); // unroot it System.out.println("Relative output directory: " + prjOutputDirectory); Element target = doc.createElement(ANT_TARGET); target.setAttribute(ANT_NAME, ANT_BUILD); //if (isRoot) { Element init = setInitTarget(doc, root, prjOutputDirectory); target.setAttribute(ANT_DEPENDS, ANT_INIT); //} root.appendChild(target); for (ImprovedClasspathHandler ich : dependentProjects) { BuildfileGenerator.generateBuildFile(ich, filePaths); String buildFilePath = ich.getProjectName() + BUILDFILE_EXT; // this will be in the same directory Element ant = doc.createElement(ANT_ANT); ant.setAttribute(ANT_ANTFILE, buildFilePath); ant.setAttribute(ANT_TARGET, ANT_BUILD); target.appendChild(ant); } // includesfile and excludesfile attributes - http://ant.apache.org/manual/Tasks/javac.html for (IClasspathEntry entry : srcEntries) { IPath[] inclusionPatterns = entry.getInclusionPatterns(); IPath[] exclusionPatterns = entry.getExclusionPatterns(); Element javac = doc.createElement(ANT_JAVAC); javac.setAttribute(ANT_INCLUDE_ANT_RUNTIME, ANT_FALSE); javac.setAttribute(ANT_CLASSPATHREF, CLASSPATH_NAME); javac.setAttribute(ANT_BOOTCLASSPATHREF, BOOTCLASSPATH_NAME); if (inclusionPatterns.length == 0 && exclusionPatterns.length == 0) { javac.setAttribute(ANT_SOURCEPATHREF, SOURCEPATH_NAME); } else { javac.setAttribute(ANT_SOURCEPATH, getModifiedSourcePath(entry, srcEntries)); } String srcEncoding = getEncodingAttribute(entry); if (!("").equals(srcEncoding)) { javac.setAttribute(ANT_ENCODING, srcEncoding); } else if (!("".equals(prjEncoding)) && prjEncoding != null) { System.out.println("Project encoding: " + prjEncoding); javac.setAttribute(ANT_ENCODING, prjEncoding); } // Source entries may have a specific output location associated with them, otherwise, we use the project's default location IPath destPath = entry.getOutputLocation(); String destDir; if (destPath != null) { String strPath = destPath.toOSString(); destDir = strPath.substring(1); } else { destDir = prjOutputDirectory; } Element mkdir = doc.createElement(ANT_MKDIR); mkdir.setAttribute(ANT_DIR, destDir); // TODO Become smarter about when we actually need this init.appendChild(mkdir); javac.setAttribute(ANT_DESTDIR, destDir); javac.setAttribute(ANT_SOURCE, "${source}"); javac.setAttribute(ANT_TARGET, "${target}"); Element src = doc.createElement(ANT_SRC); addInclusionExclusionPatterns(doc, javac, ANT_INCLUDE, entry.getInclusionPatterns()); addInclusionExclusionPatterns(doc, javac, ANT_EXCLUDE, entry.getExclusionPatterns()); String absPath = entry.getPath().toOSString(); String strRelPath = absPath.substring(1); System.out.println("Relative path: " + strRelPath); src.setAttribute(ANT_PATH, strRelPath); javac.appendChild(src); target.appendChild(javac); } }
From source file:org.drools.eclipse.util.ProjectClassLoader.java
License:Apache License
public static List<URL> getProjectClassPathURLs(IJavaProject project, List<String> alreadyLoadedProjects) { List<URL> pathElements = new ArrayList<URL>(); try {/*www .ja v a2s . co m*/ IClasspathEntry[] paths = project.getResolvedClasspath(true); Set<IPath> outputPaths = new HashSet<IPath>(); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = getRawLocationURL(path.getPath()); pathElements.add(url); } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = path.getOutputLocation(); if (path.getOutputLocation() != null) { outputPaths.add(output); } } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); for (IPath path : outputPaths) { outputPath = location.append(path.removeFirstSegments(1)); pathElements.add(0, outputPath.toFile().toURI().toURL()); } // also add classpath of required projects for (String projectName : project.getRequiredProjectNames()) { if (!alreadyLoadedProjects.contains(projectName)) { alreadyLoadedProjects.add(projectName); IProject reqProject = project.getProject().getWorkspace().getRoot().getProject(projectName); if (reqProject != null) { IJavaProject reqJavaProject = JavaCore.create(reqProject); pathElements.addAll(getProjectClassPathURLs(reqJavaProject, alreadyLoadedProjects)); } } } } catch (JavaModelException e) { DroolsEclipsePlugin.log(e); } catch (MalformedURLException e) { DroolsEclipsePlugin.log(e); } catch (Throwable t) { DroolsEclipsePlugin.log(t); } return pathElements; }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
private static void resolveClasspathToURLs(final IJavaProject javaProject, final Set<URL> resolvedEntries, final Set<String> visited) throws JavaModelException, IOException { if (javaProject == null || !javaProject.exists()) return;//from w ww. j av a 2 s.c o m final String projectName = javaProject.getProject().getName(); if (visited.contains(projectName)) return; visited.add(projectName); for (final IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { resolveClasspathToURLs(JavaCore.create(WorkspaceUtil.getProject(entry.getPath())), resolvedEntries, visited); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { resolvedEntries.add(WorkspaceUtil.getLocation(entry.getPath()).toFile().toURI().toURL()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); if (location.toString().startsWith(WorkspaceUtil.PATH_SEPERATOR + projectName)) { //it happens that the path is not absolute location = javaProject.getProject().getFolder(location.removeFirstSegments(1)).getLocation(); } resolvedEntries.add(location.toFile().toURI().toURL()); } } }
From source file:org.ebayopensource.turmeric.repositorysystem.imp.impl.TurmericProjectConfigurer.java
License:Open Source License
private void mavenizeAndCleanUp(final IProject project, final ProjectMavenizationRequest request, final IProgressMonitor monitor) throws CoreException, MavenEclipseApiException, IOException, InterruptedException, TemplateException { if (SOALogger.DEBUG) logger.entering(project, request); final IMavenEclipseApi api = MavenCoreUtils.mavenEclipseAPI(); try {/*w w w.j a v a2 s. com*/ // It seems that the pom.xml is not updated in the Eclipse Workspace by the mavenize project operation // Util.refresh( project.getFile( "pom.xml" ) ); // Project Mavenization doesn't seem to care that the output directory is set here and set in the pom.xml // it will use the maven default of target-eclipse no matter what. IJavaProject javaProject = null; try { api.mavenizeProject(request, monitor); logger.info("Mavenization finished->" + project); ProgressUtil.progressOneStep(monitor); javaProject = JavaCore.create(project); //javaProject.setOutputLocation( project.getFolder( SOAProjectConstants.FOLDER_OUTPUT_DIR).getFullPath(), null ); FileUtils.deleteDirectory(project.getFolder("target-eclipse").getLocation().toFile()); //Util.delete( project.getFolder( "target-eclipse" ), null ); final Map<?, ?> options = javaProject.getOptions(false); options.clear(); javaProject.setOptions(options); } catch (NullPointerException e) { throw new CoreException(EclipseMessageUtils.createErrorStatus( "NPE occured during projects mavenization.\n\n" + "The possible cause is that the M2Eclipse Maven indexes in your current workspace might be corrupted. " + "Please remove folder {workspace}/.metadata/.plugins/org.maven.ide.eclipse/, and then restart your IDE.", e)); } // The Mavenization also seemed to take the META-SRC src directory and add an exclusion pattern along with // setting its output location to itself. Maybe they wanted to do a class library folder? Either way its // no good for us. Secondly, we are setting the Maven classpath container to have its entries exported by default. // Finally, we are adding the classpath entry attribute 'org.eclipse.jst.component.dependency' in case the project // is a WTP web project so that WTP will use the maven classpath container when deploying to its runtime servers. boolean changed = false; final List<IClasspathEntry> newEntries = ListUtil.list(); final IPath containerPath = new Path(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); for (final IClasspathEntry cpEntry : JDTUtil.rawClasspath(javaProject, true)) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().equals(containerPath)) { newEntries.add(JavaCore.newContainerEntry(containerPath, true)); changed |= true; } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (!ArrayUtils.isEmpty(cpEntry.getExclusionPatterns()) || cpEntry.getOutputLocation() != null) { newEntries.add(JavaCore.newSourceEntry(cpEntry.getPath())); changed |= true; } else { newEntries.add(cpEntry); } } else { newEntries.add(cpEntry); } } ProgressUtil.progressOneStep(monitor, 15); if (changed) { javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); ProgressUtil.progressOneStep(monitor); //This is a hot fix for the Maven classpath container issue, //should be removed as soon as the M2Eclipse guys fix it int count = 0; //we only go to sleep 5 times. while (MavenCoreUtils.getMaven2ClasspathContainer(javaProject).getClasspathEntries().length == 0 && count < 5) { logger.warning("Maven Classpath is empty->", SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID, ", going to sleep..."); Thread.sleep(1000); ProgressUtil.progressOneStep(monitor, 10); count++; } } } finally { if (SOALogger.DEBUG) logger.exiting(); } }
From source file:org.eclim.plugin.jdt.util.ClasspathUtils.java
License:Open Source License
/** * Recursively collects classpath entries from the current and dependent * projects./*from www . j a v a 2s . com*/ */ private static void collect(IJavaProject javaProject, List<String> paths, Set<IJavaProject> visited, boolean isFirstProject) throws Exception { if (visited.contains(javaProject)) { return; } visited.add(javaProject); try { IPath out = javaProject.getOutputLocation(); paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } catch (JavaModelException ignore) { // ignore... just signals that no output dir was configured. } IProject project = javaProject.getProject(); String name = project.getName(); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException jme) { // this may or may not be a problem. logger.warn("Unable to retrieve resolved classpath for project: " + name, jme); return; } final List<IJavaProject> nextProjects = new ArrayList<IJavaProject>(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: String path = entry.getPath().toOSString().replace('\\', '/'); if (path.startsWith("/" + name + "/")) { path = ProjectUtils.getFilePath(project, path); } paths.add(path); break; case IClasspathEntry.CPE_PROJECT: if (isFirstProject || entry.isExported()) { javaProject = JavaUtils.getJavaProject(entry.getPath().segment(0)); if (javaProject != null) { // breadth first, not depth first, to preserve dependency ordering nextProjects.add(javaProject); } } break; case IClasspathEntry.CPE_SOURCE: IPath out = entry.getOutputLocation(); if (out != null) { paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } break; } } // depth second for (final IJavaProject nextProject : nextProjects) { collect(nextProject, paths, visited, false); } }
From source file:org.eclipse.acceleo.common.internal.utils.workspace.AcceleoWorkspaceUtil.java
License:Open Source License
/** * This will return the set of output folders name for the given (java) project. * <p>//from w ww . jav a 2 s . co m * For example, if a project has a source folder "src" with its output folder set as "bin" and a source * folder "src-gen" with its output folder set as "bin-gen", this will return a LinkedHashSet containing * both "bin" and "bin-gen". * </p> * * @param project * The project we seek the output folders of. * @return The set of output folders name for the given (java) project. */ private static Set<String> getOutputFolders(IProject project) { final Set<String> classpathEntries = new CompactLinkedHashSet<String>(); final IJavaProject javaProject = JavaCore.create(project); try { for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IPath output = entry.getOutputLocation(); if (output != null) { classpathEntries.add(output.removeFirstSegments(1).toString()); } } } /* * Add the default output location to the classpath anyway since source folders are not required * to have their own */ final IPath output = javaProject.getOutputLocation(); classpathEntries.add(output.removeFirstSegments(1).toString()); } catch (JavaModelException e) { AcceleoCommonPlugin.log(e, false); } return classpathEntries; }
From source file:org.eclipse.acceleo.internal.ide.ui.builders.AcceleoBuilder.java
License:Open Source License
/** * Computes the classpath for the given java project. * /* ww w . j a v a 2 s .c om*/ * @param javaProject * The Java project * @return The classpath entries */ private Set<AcceleoProjectClasspathEntry> computeProjectClassPath(IJavaProject javaProject) { Set<AcceleoProjectClasspathEntry> classpathEntries = new LinkedHashSet<AcceleoProjectClasspathEntry>(); // Compute the classpath of the acceleo project IClasspathEntry[] rawClasspath; try { rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry iClasspathEntry : rawClasspath) { int entryKind = iClasspathEntry.getEntryKind(); if (IClasspathEntry.CPE_SOURCE == entryKind) { // We have the source folders of the project. IPath inputFolderPath = iClasspathEntry.getPath(); IPath outputFolderPath = iClasspathEntry.getOutputLocation(); if (outputFolderPath == null) { outputFolderPath = javaProject.getOutputLocation(); } IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(inputFolderPath.lastSegment()); if (!(project != null && project.exists() && project.equals(javaProject.getProject()))) { IContainer inputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(inputFolderPath); IContainer outputContainer = ResourcesPlugin.getWorkspace().getRoot() .getFolder(outputFolderPath); if (inputContainer != null && outputContainer != null) { File inputDirectory = inputContainer.getLocation().toFile(); File outputDirectory = outputContainer.getLocation().toFile(); AcceleoProjectClasspathEntry entry = new AcceleoProjectClasspathEntry(inputDirectory, outputDirectory); classpathEntries.add(entry); this.outputFolders.add(outputDirectory); } } } } } catch (JavaModelException e) { AcceleoUIActivator.log(e, true); } return classpathEntries; }