List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
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();// ww w. ja v a2 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;/* w w w .ja v a 2s. c o m*/ 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 library entries to the classpath * //from w ww . j a v a 2s .c o m * @param doc the document * @param path the path element * @param entries list of entries to be added */ private static void addLibraryEntries(Document doc, Element path, List<IClasspathEntry> entries) { for (IClasspathEntry entry : entries) { String rootedPath = entry.getPath().toOSString(); String relativePath = rootedPath.substring(1); addPathElement(doc, path, relativePath); } }
From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Sets bootclasspath for the build file * /*from w w w .j ava 2 s . com*/ * @param doc the document * @param root the root element of the XML document * @param entries list of classpath entries */ private static void setBootClasspath(Document doc, Element root, List<IClasspathEntry> entries) { Element path = doc.createElement(ANT_PATH); path.setAttribute(ANT_ID, BOOTCLASSPATH_NAME); for (IClasspathEntry entry : entries) { String rootedPath = entry.getPath().toOSString(); String relativePath = rootedPath.substring(1); addPathElement(doc, path, relativePath); } root.appendChild(path); }
From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Sets bootclasspath for the build file * /* ww w . j av a2 s . c om*/ * @param doc the document * @param root the root element of the XML document * @param entries list of classpath entries */ private static void addSourceEntries(Document doc, Element path, List<IClasspathEntry> entries) { for (IClasspathEntry entry : entries) { String rootedPath = entry.getPath().toOSString(); String relativePath = rootedPath.substring(1); 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//from w ww.jav 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.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Builds sourcepath with relative paths for an entry * @param currentEntry the source entry//from w w w .j a va2 s .co m * @param entries the source entries * @return comma-delimited source path */ private static String getModifiedSourcePath(IClasspathEntry currentEntry, List<IClasspathEntry> entries) { StringBuffer sb = new StringBuffer(""); for (int i = 0; i < entries.size(); i++) { IClasspathEntry entry = entries.get(i); if (currentEntry.equals(entry)) { continue; } String rootedPath = entry.getPath().toOSString(); String relativePath = rootedPath.substring(1); String str = i == 0 ? relativePath : "," + relativePath; sb.append(str); } return sb.toString(); }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a source entry in the classpath * @param entry the classpath entry/*from www . ja v a 2 s .c o m*/ * @param root the workspace root (necessary for getting the file specified by this entry) */ private void handleSource(IClasspathEntry entry, IWorkspaceRoot root) { // Each entry either has an associated Output Location or goes to the project's default output location // Associated output locations are also just absolute paths (e.g. /MalcolmsProject/bin) just like sources // We'll need to mkdir all of these output locations but that shouldn't be hard //System.out.println("Source absolute path: " + entry.getPath()); //System.out.println("Associated output location: " + entry.getOutputLocation()); sources.add(entry); IFile file = root.getFile(entry.getPath()); IProject project = file.getProject(); IPath projectPath = project.getLocation(); System.out.println("Source location: " + projectPath.toOSString()); // (1) Copy the files from here to plug-in area File src = new File(projectPath.toOSString()); File dst = new File(getRootProjectPluginLocation() + File.separator + project.getName()); System.out.println("Src path: " + src.getPath()); System.out.println("Dst path: " + dst.getPath()); try { FileUtils.copyDirectory(src, dst); } catch (IOException e) { // TODO Auto-generated catch block // TODO Handle this better! e.printStackTrace(); } filesToArchive.add(dst.getPath().toString()); // (2) Name the directory the Eclipse project name // (3) Add that path to filesToArchive //filesToArchive.add(projectPath.toOSString()); }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a library entry in the classpath * @param entry the classpath entry// w w w . j a v a 2 s . c om * @param root the workspace root * @throws IOException */ private void handleLibrary(IClasspathEntry entry, IWorkspaceRoot root) throws IOException { // 3 types of library entries: internal (this project), internal (another project), and external // (1) Rooted absolute path // (2) Rooted absolute path (but with different project directory) --> Need to copy this to swampbin // (3) Actual absolute path to somewhere else on the filesystem --> Need to copy this to swampbin System.out.println("\n\n\n\n"); System.out.println("Library absolute path: " + entry.getPath().makeAbsolute()); //System.out.println("First segment: " + entry.getPath().segment(0)); IFile file = root.getFile(entry.getPath()); System.out.println("File project: " + file.getProject().getName()); if (file.getProject().equals(this.project.getProject())) { System.out.println("Is inside project"); libs.add(entry); } else { System.out.println("Is outside project"); IFile libFile = root.getFile(entry.getPath()); IProject libProject = libFile.getProject(); String filename = getLibraryFileName(entry.getPath()); IPath destPath; if (libProject.exists()) { if (libProject.isOpen()) { try { System.out.println("Local project"); destPath = copyWorkspacePathIntoBinDir(libFile, filename, SWAMPBIN_PATH); } catch (Exception e) { System.out.println("Local project that failed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Local project that's closed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Not a project - just an absolute path"); destPath = copyAbsolutePathIntoBinDir(entry.getPath().toOSString(), filename, SWAMPBIN_PATH); } hasSwampbinDependencies = true; System.out.println("SWAMPBIN path: " + destPath); IClasspathEntry newEntry = JavaCore.newLibraryEntry(destPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); System.out.println("New entry path: " + newEntry.getPath()); libs.add(newEntry); if (entry.isExported()) { exportedEntries.add(newEntry); } } }