List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
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 w w w.j a v a 2 s . co m 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 2s. c o m*/ } } 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./* w ww . j a v a 2 s.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
/** * Use default classes.// w w w .j av a 2s . co 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 {//from ww w . ja v a 2s .c om 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 { } }
From source file:fr.inria.diverse.commons.eclipse.pde.wizards.pages.pde.ui.templates.AbstractTemplateSection.java
License:Open Source License
/** * Returns the folder with Java files in the target project. The default * implementation looks for source folders in the classpath of the target * folders and picks the first one encountered. Subclasses may override this * behaviour./* www .j a v a 2 s .c om*/ * * @param monitor * progress monitor to use * @return source folder that will be used to generate Java files or * <samp>null </samp> if none found. */ protected IFolder getSourceFolder(IProgressMonitor monitor) { IFolder sourceFolder = null; try { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath().removeFirstSegments(1); if (path.segmentCount() > 0) sourceFolder = project.getFolder(path); break; } } } catch (JavaModelException e) { PDEPlugin.logException(e); } return sourceFolder; }
From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java
License:Open Source License
/** * Launches the exploration of the given Java project. * //from w w w . j a v a 2s.c o m * @param project * The Java project to explore * @param monitor * The progress monitor * @return The Component representing the Java project. */ public Component doExplore(IProject project, IProgressMonitor monitor) { Component ariadneComponent = this.getOrCreateComponent(project); IJavaProject iJavaProject = JavaCore.create(project); try { IClasspathEntry[] rawClasspath = iJavaProject.getRawClasspath(); for (IClasspathEntry iClasspathEntry : rawClasspath) { // We have the source folders of the project. IPath inputFolderPath = iClasspathEntry.getPath(); IPath outputFolderPath = iClasspathEntry.getOutputLocation(); if (outputFolderPath == null) { outputFolderPath = iJavaProject.getOutputLocation(); } // Create the classpath entry ClasspathEntry classpathEntry = CodeFactory.eINSTANCE.createClasspathEntry(); classpathEntry.setInputFolder(inputFolderPath.toString()); classpathEntry.setOutputFolder(outputFolderPath.toString()); ariadneComponent.getClasspathEntries().add(classpathEntry); int entryKind = iClasspathEntry.getEntryKind(); if (IClasspathEntry.CPE_SOURCE == entryKind) { // Explore its content located in its input folder this.exploreClasspathEntry(iJavaProject, iClasspathEntry, classpathEntry, monitor); } } } catch (JavaModelException e) { e.printStackTrace(); } return ariadneComponent; }
From source file:gov.redhawk.ide.codegen.java.AbstractJavaCodeGenerator.java
License:Open Source License
@Override public IStatus cleanupSourceFolders(final IProject project, final IProgressMonitor monitor) { final IJavaProject jp = JavaCore.create(project); final HashSet<IClasspathEntry> paths = new HashSet<IClasspathEntry>(); try {/*from ww w . ja v a 2 s . c om*/ for (final IClasspathEntry path : jp.getRawClasspath()) { IPath p = path.getPath(); if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (p.segment(0).equals(project.getFullPath().segment(0))) { p = p.removeFirstSegments(1); if (project.getFolder(p).exists()) { paths.add(path); } } } else { paths.add(path); } } jp.setRawClasspath(paths.toArray(new IClasspathEntry[paths.size()]), monitor); } catch (final JavaModelException e) { return new Status(IStatus.WARNING, JavaGeneratorPlugin.PLUGIN_ID, "Unable to adjust the list of source code folders for the project"); } return new Status(IStatus.OK, JavaGeneratorPlugin.PLUGIN_ID, "Cleaned up source folders"); }
From source file:gov.redhawk.ide.codegen.java.JavaGeneratorUtils.java
License:Open Source License
public static void addSourceClassPaths(final IJavaProject jproject, final IPath srcPath, final IPath binPath, final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 1); final Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>( Arrays.asList(jproject.getRawClasspath())); // Add source code to the java project classpath for (final IClasspathEntry path : entries) { if ((path.getEntryKind() == IClasspathEntry.CPE_SOURCE) && path.getPath().equals(jproject.getProject().getFullPath())) { continue; }//from w ww . ja v a2 s .com entries.add(path); } final IClasspathEntry e = JavaCore.newSourceEntry(srcPath, new Path[0], binPath); entries.add(e); jproject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progress.newChild(1)); }
From source file:in.cypal.studio.gwt.core.common.Util.java
License:Apache License
/** * @param file//w ww. j a v a 2 s . c o m * @return */ private static String[] getSegmentsFromSourceFolder(IFile file) { int removeCount = 1;// by default, just remove the source folder; try { IJavaProject javaProject = JavaCore.create(file.getProject()); IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;// we are interested only in source folders IPath path = classpathEntries[i].getPath(); if (path.isPrefixOf(file.getFullPath())) { removeCount = path.segmentCount() - 1; } } } catch (Throwable e) { Activator.logException(new Exception(e)); } IPath filePath = file.getProjectRelativePath().removeFirstSegments(removeCount); return filePath.segments(); }