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:de.loskutov.eclipse.jdepend.views.TreeObject.java
License:Open Source License
protected String getPackageOutputPath(IJavaElement jElement) throws JavaModelException { String dir = ""; //$NON-NLS-1$ if (jElement == null) { return dir; }/*from w w w.j ava2 s .c o m*/ IJavaProject project = jElement.getJavaProject(); if (project == null) { return dir; } IPath path = project.getOutputLocation(); IResource resource = jElement.getUnderlyingResource(); if (resource == null) { return dir; } // resolve multiple output locations here if (project.exists() && project.getProject().isOpen()) { IClasspathEntry entries[] = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry classpathEntry = entries[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = classpathEntry.getOutputLocation(); if (outputPath != null) { // if this source folder contains specified java resource // then take bytecode location from himself if (classpathEntry.getPath().isPrefixOf(resource.getFullPath())) { path = outputPath; break; } } } } } if (path == null) { // check the default location if not already included IPath def = project.getOutputLocation(); if (def != null && def.isPrefixOf(resource.getFullPath())) { path = def; } } if (path == null) { return dir; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (!project.getPath().equals(path)) { IFolder outputFolder = workspace.getRoot().getFolder(path); if (outputFolder != null) { // linked resources will be resolved here! IPath rawPath = outputFolder.getRawLocation(); if (rawPath != null) { path = rawPath; } } } else { path = project.getProject().getLocation(); } if (path == null) { return dir; } // here we should resolve path variables, // probably existing at first place of path IPathVariableManager pathManager = workspace.getPathVariableManager(); path = pathManager.resolvePath(path); if (path == null) { return dir; } boolean packageRoot = false; try { packageRoot = isPackageRoot(project, resource); } catch (JavaModelException e) { // seems to be a bug in 3.3 } if (packageRoot) { dir = path.toOSString(); } else { String packPath = getPackageName().replace('.', '/'); dir = path.append(packPath).toOSString(); } return dir; }
From source file:de.tobject.findbugs.builder.ResourceUtils.java
License:Open Source License
public static IPath getOutputLocation(IClasspathEntry classpathEntry, IPath defaultOutputLocation) { IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null) { // this location is workspace relative and starts with project dir outputLocation = relativeToAbsolute(outputLocation); } else {// w ww . j av a 2s. c o m outputLocation = defaultOutputLocation; } return outputLocation; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java
License:Open Source License
private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) { IPath p = ent.getPath();//from w w w .j av a 2s . c om IPath op = ent.getOutputLocation(); IPath sp = ent.getSourceAttachmentPath(); IProject ip = jp.getProject(); String jdp = null; boolean opt = false; IClasspathAttribute[] atts = ent.getExtraAttributes(); for (IClasspathAttribute att : atts) { if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) jdp = att.getValue(); else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) { String v = att.getValue(); if (v.equals("true")) opt = true; } } if (p == null && op == null) return; File f1 = null; if (p != null) { f1 = BedrockUtil.getFileForPath(p, ip); if (!f1.exists()) { BedrockPlugin.logD("Path file " + p + " not found as " + f1); // f1 = null; } } File f2 = null; if (op != null) { f2 = BedrockUtil.getFileForPath(op, ip); if (!f2.exists()) { BedrockPlugin.logD("Path file " + op + " not found"); f2 = null; } } File f3 = null; if (sp != null) { f3 = BedrockUtil.getFileForPath(sp, ip); if (!f3.exists()) { BedrockPlugin.logD("Path file " + sp + " not found"); f3 = null; } } if (f1 == null && f2 == null) return; // references to nested projects are handled in addClassPaths if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT) return; xw.begin("PATH"); xw.field("ID", ent.hashCode()); if (nest) xw.field("NESTED", "TRUE"); switch (ent.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: xw.field("TYPE", "SOURCE"); f3 = f1; f1 = null; break; case IClasspathEntry.CPE_PROJECT: xw.field("TYPE", "BINARY"); break; case IClasspathEntry.CPE_LIBRARY: xw.field("TYPE", "LIBRARY"); break; } if (ent.isExported()) xw.field("EXPORTED", true); if (opt) xw.field("OPTIONAL", true); if (f1 != null) xw.textElement("BINARY", f1.getAbsolutePath()); if (f2 != null) xw.textElement("OUTPUT", f2.getAbsolutePath()); if (f3 != null) xw.textElement("SOURCE", f3.getAbsolutePath()); if (jdp != null) xw.textElement("JAVADOC", jdp); IAccessRule[] rls = ent.getAccessRules(); for (IAccessRule ar : rls) { xw.begin("ACCESS"); xw.field("KIND", ar.getKind()); xw.field("PATTERN", ar.getPattern().toString()); xw.field("IGNOREIFBETTER", ar.ignoreIfBetter()); xw.end("ACCESS"); } xw.end("PATH"); }
From source file:edu.rice.cs.drjava.plugins.eclipse.repl.EclipseInteractionsModel.java
License:BSD License
private void _addProjectToClasspath(IJavaProject jProj, IJavaModel jModel, IWorkspaceRoot root) throws CoreException { // Get the project's location on disk IProject proj = jProj.getProject();/*from ww w . j av a2 s.c o m*/ URI projRoot = proj.getDescription().getLocationURI(); // Note: getLocation returns null if the default location is used // (brilliant...) // Get the resolved classpath entries - this should filter out // all CPE_VARIABLE and CPE_CONTAINER entries. IClasspathEntry entries[] = jProj.getResolvedClasspath(true); // For each of the classpath entries... for (int j = 0; j < entries.length; j++) { IClasspathEntry entry = entries[j]; // Check what kind of entry it is... int kind = entry.getEntryKind(); // And get the appropriate path. IPath path; switch (kind) { case IClasspathEntry.CPE_LIBRARY: // The raw location of a JAR. path = entry.getPath(); //System.out.println("Adding library: " + path.toOSString()); addToClassPath(path.toOSString()); break; case IClasspathEntry.CPE_SOURCE: // The output location of source. // Need to append it to the user's workspace directory. path = entry.getOutputLocation(); if (path == null) { path = jProj.getOutputLocation(); //System.out.println(" output location from proj: " + path); } // At this point, the output location contains the project // name followed by the actual output folder name if (projRoot != null && (!projRoot.isAbsolute() || projRoot.getScheme().equals("file"))) { // We have a custom project location, so the project name // is not part of the *actual* output directory. We need // to remove the project name (first segment) and then // append the rest of the output location to projRoot. path = path.removeFirstSegments(1); path = new Path(projRoot.getPath()).append(path); } else { // A null projRoot means use the default location, which // *does* include the project name in the output directory. path = root.getLocation().append(path); } //System.out.println("Adding source: " + path.toOSString()); //addToClassPath(path.toOSString()); addBuildDirectoryClassPath(path.toOSString()); break; case IClasspathEntry.CPE_PROJECT: // In this case, just the project name is given. // We don't actually need to add anything to the classpath, // since the project is open and we will get its classpath // on another pass. break; default: // This should never happen. throw new RuntimeException("Unsupported classpath entry type."); } } }
From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java
License:Eclipse Public License
private void calculateDependencies(IClasspathEntry[] cpe, IProject project) throws DependenciesResolverException { try {/*from ww w . ja va 2s . c om*/ IWorkspace workspace = project.getWorkspace(); IPath workspacePath = workspace.getRoot().getLocation(); String nombreWorkspace = workspacePath.toString(); IJavaProject jp = JavaCore.create(project); if (!dependencies.contains(project.getLocation().toString())) { // Aadimos la carpeta bin classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile()); classpath.add(jp.getOutputLocation().toString()); } for (IClasspathEntry cpEntry : cpe) { String path = cpEntry.getPath().toString(); String dependency = nombreWorkspace.concat(path); if (!dependencies.contains(dependency)) { RESClientPlugin.log("Adding dependency: " + dependency); dependencies.add(dependency); if (cpEntry.getOutputLocation() != null) { RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString()); classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString()); classpathFiles.add(cpEntry.getOutputLocation().toFile()); } int tipo = cpEntry.getEntryKind(); //Si la dependencia es de una libreria( if (tipo == IClasspathEntry.CPE_LIBRARY) { String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString(); //mgarcia: Optsicom res Evolution if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) { classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString())); //Aadimos las dependencias a las properties RESClientPlugin.log("Adding library: " + dep); classpath.add(cpEntry.getPath().toString()); } else { throw new DependenciesResolverException(); } } else if (tipo == IClasspathEntry.CPE_PROJECT) { // File[] files = new File(dependency).listFiles(); // for (File f : files){ // lista.add(f); // String dep = f.getPath(); // RESClientPlugin.log("Adding dependency: " + dep); // dependencies.add(dep); // } IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment()); IJavaProject projectDependency = JavaCore.create(p); IClasspathEntry[] cp = projectDependency.getRawClasspath(); classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile()); classpath.add(projectDependency.getOutputLocation().toString()); RESClientPlugin.log("Populating files from: " + p.getName()); calculateDependencies(cp, p); } else if (tipo == IClasspathEntry.CPE_SOURCE) { File f = new File(dependency); classpathFiles.add(f); RESClientPlugin.log("Adding source: " + dependency); } else if (tipo == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry[] clpe = new IClasspathEntry[1]; clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry); if (clpe[0] != null) { RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString()); calculateDependencies(clpe, project); } } else if (tipo == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER") || cpEntry.getPath().toOSString().contains("requiredPlugins")) { continue; } IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp); IClasspathEntry[] entradas = cc.getClasspathEntries(); RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString()); calculateDependencies(entradas, project); } } } } catch (JavaModelException e) { RESClientPlugin.log(e); } for (String path : classpath) { RESClientPlugin.log("Classpath: " + path); } for (File file : classpathFiles) { RESClientPlugin.log("Classpath file: " + file.getAbsolutePath()); } }
From source file:fede.workspace.eclipse.composition.copy.exporter.JavaClassRefExporter.java
License:Apache License
protected Map<IPath, FolderExportedContent> findLocations(FolderExportedContent folderContent, String exporterType) throws JavaModelException, CoreException { IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem()); Map<IPath, FolderExportedContent> outputLocations = new HashMap<IPath, FolderExportedContent>(); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); if (exporterType.equals(JAVA_REF_EXPORTER_TYPE)) { for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getOutputLocation(); if (outputPath == null) outputPath = javaProject.getOutputLocation(); outputLocations.put(getRelativePath(outputPath), folderContent); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath outputPath = entry.getPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); }/*from www . j a va 2 s .c om*/ } } else { for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputPath = entry.getPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath outputPath = entry.getSourceAttachmentPath(); if (outputPath != null) outputLocations.put(getRelativePath(outputPath), folderContent); } } } return outputLocations; }
From source file:fede.workspace.eclipse.composition.java.JavaProjectExporter.java
License:Apache License
/** * Updates an existing packaged binary version of the content of the item in * this project./*from w w w. ja v a2s. c o m*/ * * Scans all output directories of the java project and updates all modified * classes in the packaged item version. * * If no resource delta is specified all the binary contents are copied to * the packaged version. * * @param monitor * the monitor * @param eclipseExportedContent * the eclipse exported content * @param projectDelta * the project delta * @param exporterType * the exporter type * * @throws CoreException * the core exception */ @Override protected void exportItem(EclipseExportedContent eclipseExportedContent, IResourceDelta projectDelta, IProgressMonitor monitor, String exporterType) throws CoreException { /* * skip empty notifications */ if ((projectDelta != null) && (projectDelta.getKind() == IResourceDelta.NO_CHANGE)) { return; } /* * Verify this item is actually hosted in a Java Project */ if (!JavaProjectManager.isJavaProject(MelusineProjectManager.getProject(getItem()))) { return; } IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem()); /* * TODO We scan all output directories, we should only scan the output * directory associated with the item. * * We need to handle mapping variants in which there are many composites * in a single java project, this is the case for example when a * composite has parts that are themselves java composites. */ Set<IPath> outputLocations = new HashSet<IPath>(); for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } IPath outputPath = entry.getOutputLocation(); if (outputPath == null) { outputPath = javaProject.getOutputLocation(); } outputLocations.add(getRelativePath(outputPath)); } Scanner scanner = new Scanner(eclipseExportedContent); for (IPath outputPath : outputLocations) { IFolder outputRoot = getFolder(outputPath); IResourceDelta outputDelta = (projectDelta != null) ? projectDelta.findMember(outputRoot.getProjectRelativePath()) : null; // If no modification of the output location just skip it if ((projectDelta != null) && (outputDelta == null)) { return; } scanner.scan(outputRoot, outputDelta, monitor); } }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Removes the java source folder.//from w w w. j a v a2 s . co m * * @param item * the item * @param sourceFolder * the source folder * @param monitor * the monitor * * @throws CoreException * the core exception */ public static void removeJavaSourceFolder(Item item, IFolder sourceFolder, IProgressMonitor monitor) throws CoreException { if (sourceFolder == null) { return; } IProject project = sourceFolder.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } IClasspathEntry ce = removeProjectClasspath(sourceFolder.getFullPath(), javaProject, monitor); if (ce != null) { IPath p = ce.getOutputLocation(); p = p.removeFirstSegments(1).makeRelative(); IFolder f = project.getFolder(p); if (f.exists()) { f.delete(true, monitor); } } if (!useDefaultClasses(javaProject)) { IFolder output = project .getFolder(DEFAULT_OUTPUT_FOLDER_NAME.compute(ContextVariableImpl.DEFAULT, item)); if (output.exists()) { output.delete(false, monitor); } } }
From source file:fede.workspace.eclipse.java.JavaProjectManager.java
License:Apache License
/** * Use default classes.//from ww w . j ava 2 s. c o m * * @param project * the project * * @return true, if successful * * @throws JavaModelException * the java model exception */ static boolean useDefaultClasses(IJavaProject project) throws JavaModelException { IClasspathEntry[] classpath = project.getRawClasspath(); int cpLength = classpath.length; for (int j = 0; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() == null) { return true; } } return false; }
From source file:fr.imag.adele.cadse.cadseg.menu.ExportBundlePagesAction.java
License:Apache License
@Override public void doFinish(UIPlatform uiPlatform, Object monitor) throws Exception { super.doFinish(uiPlatform, monitor); IProgressMonitor pmo = (IProgressMonitor) monitor; try {// w ww .j av a 2s. com EclipsePluginContentManger project = (EclipsePluginContentManger) cadsedef.getContentItem(); pmo.beginTask("export cadse " + cadsedef.getName(), 1); String qname = cadsedef.getQualifiedName(); String qname_version = ""; String version = ""; IJavaProject jp = project.getMainMappingContent(IJavaProject.class); IProject eclipseProject = project.getProject(); IPath eclipseProjectPath = eclipseProject.getFullPath(); // jp.getProject().build(kind, pmo) IPath defaultOutputLocation = jp.getOutputLocation(); IPath manifestPath = new Path(JarFile.MANIFEST_NAME); HashSet<IPath> excludePath = new HashSet<IPath>(); excludePath.add(eclipseProjectPath.append(manifestPath)); excludePath.add(eclipseProjectPath.append(".project")); excludePath.add(eclipseProjectPath.append(".classpath")); excludePath.add(eclipseProjectPath.append("run-cadse-" + cadsedef.getName() + ".launch")); excludePath.add(eclipseProjectPath.append(".melusine.ser")); excludePath.add(eclipseProjectPath.append(".melusine.xml")); Manifest mf = new Manifest(eclipseProject.getFile(manifestPath).getContents()); File pf = new File(file, qname + ".jar"); File sourceDir = new File(file, qname + ".Source"); if (tstamp) { Date d = new Date(System.currentTimeMillis()); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm"); String timeStamp = "v" + formatter.format(d); version = mf.getMainAttributes().getValue(OsgiManifest.BUNDLE_VERSION); String[] partVersion = version.split("\\."); if (partVersion.length == 4) { version = version + "-" + timeStamp; } else { version = version + "." + timeStamp; } mf.getMainAttributes().putValue(OsgiManifest.BUNDLE_VERSION, version); pf = new File(file, qname + "_" + version + ".jar"); qname_version = qname + "_" + version; sourceDir = new File(file, qname + ".Source_" + version); } JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(pf), mf); HashMap<IFile, IPath> files = new HashMap<IFile, IPath>(); IWorkspaceRoot eclipseRoot = eclipseProject.getWorkspace().getRoot(); IContainer classesFolder = (IContainer) eclipseRoot.findMember(defaultOutputLocation); addFolder(files, excludePath, classesFolder, Path.EMPTY); IClasspathEntry[] classpaths = jp.getRawClasspath(); for (IClasspathEntry entry : classpaths) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { classesFolder = (IContainer) eclipseRoot.findMember(entry.getOutputLocation()); addFolder(files, excludePath, classesFolder, Path.EMPTY); } IPath sourcePath = entry.getPath(); excludePath.add(sourcePath); continue; } if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { } } addFolder(files, excludePath, eclipseProject, Path.EMPTY); pmo.beginTask("export cadse " + cadsedef.getName(), files.size()); Set<IFile> keySet = new TreeSet<IFile>(new Comparator<IFile>() { public int compare(IFile o1, IFile o2) { return o1.getFullPath().toPortableString().compareTo(o2.getFullPath().toPortableString()); } }); keySet.addAll(files.keySet()); for (IFile f : keySet) { IPath entryPath = files.get(f); pmo.worked(1); try { ZipUtil.addEntryZip(outputStream, f.getContents(), entryPath.toPortableString(), f.getLocalTimeStamp()); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } } outputStream.close(); if (deleteOld) { File[] childrenFiles = file.listFiles(); if (childrenFiles != null) { for (File f : childrenFiles) { if (f.equals(pf)) { continue; } String fileName = f.getName(); if (!fileName.startsWith(qname)) { continue; } FileUtil.deleteDir(f); } } } if (exportSource && tstamp) { sourceDir.mkdir(); File srcDir = new File(sourceDir, "src"); srcDir.mkdir(); File mfDir = new File(sourceDir, "META-INF"); mfDir.mkdir(); File modelDir = new File(srcDir, qname_version); modelDir.mkdir(); FileUtil.setFile(new File(sourceDir, "plugin.xml"), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<?eclipse version=\"3.0\"?>\n" + "<plugin>\n" + "<extension point=\"org.eclipse.pde.core.source\">\n" + "<location path=\"src\"/>\n" + "</extension>\n" + "</plugin>\n"); String vendor_info = CadseDefinitionManager.getVendorNameAttribute(cadsedef); FileUtil.setFile(new File(mfDir, "MANIFEST.MF"), "Manifest-Version: 1.0\n" + "Bundle-ManifestVersion: 2\n" + "Bundle-SymbolicName: " + qname + ".Source;singleton:=true\n" + "Bundle-Version: " + version + "\n" + "Bundle-Localization: plugin\n" + "Bundle-Vendor: " + vendor_info + "\n" + "Bundle-Name: " + qname + "\n"); excludePath.clear(); files.clear(); classesFolder = (IContainer) eclipseRoot.findMember(defaultOutputLocation); excludePath.add(classesFolder.getFullPath()); for (IClasspathEntry entry : classpaths) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { classesFolder = (IContainer) eclipseRoot.findMember(entry.getOutputLocation()); addFolder(files, excludePath, classesFolder, Path.EMPTY); } IPath sourcePath = entry.getPath(); excludePath.add(sourcePath); ZipUtil.zipDirectory(eclipseRoot.findMember(sourcePath).getLocation().toFile(), new File(modelDir, "src.zip"), null); continue; } } addFolder(files, excludePath, eclipseProject, Path.EMPTY); keySet = files.keySet(); for (IFile f : keySet) { IPath entryPath = files.get(f); try { FileUtil.copy(f.getLocation().toFile(), new File(modelDir, entryPath.toOSString()), false); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } }