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:at.bestsolution.javafx.ide.jdt.internal.NewJavaProjectService.java
License:Open Source License
public static void flush(List<CPListElement> classPathEntries, IPath outputLocation, IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor) throws CoreException, OperationCanceledException { IProject project = javaProject.getProject(); IPath projPath = project.getFullPath(); IPath oldOutputLocation;/*from w w w. ja v a 2s. c om*/ try { oldOutputLocation = javaProject.getOutputLocation(); } catch (CoreException e) { oldOutputLocation = projPath.append( "bin"/*PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)*/); } if (oldOutputLocation.equals(projPath) && !outputLocation.equals(projPath)) { if (BuildPathsBlock.hasClassfiles(project)) { // if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(false, projPath)) { BuildPathsBlock.removeOldClassfiles(project); // } } } else if (!outputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { BuildPathsBlock.removeOldClassfiles(folder); } else { // if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(folder.isDerived(), oldOutputLocation)) { BuildPathsBlock.removeOldClassfiles(folder); // } } } } monitor.worked(1); IWorkspaceRoot fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); //create and set the output path first if (!fWorkspaceRoot.exists(outputLocation)) { IFolder folder = fWorkspaceRoot.getFolder(outputLocation); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } int nEntries = classPathEntries.size(); IClasspathEntry[] classpath = new IClasspathEntry[nEntries]; int i = 0; for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); classpath[i] = entry.getClasspathEntry(); i++; IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (!path.equals(entry.getOrginalPath())) { String eeID = JavaRuntime.getExecutionEnvironmentId(path); if (eeID != null) { BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance); newProjectCompliance = null; // don't set it again below } } if (newProjectCompliance != null) { Map<String, String> options = javaProject.getOptions(false); JavaModelUtil.setComplianceOptions(options, newProjectCompliance); JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options javaProject.setOptions(options); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, outputLocation, new SubProgressMonitor(monitor, 2)); }
From source file:at.component.newcomponentwizard.generator.NewProjectCreationOperation.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) private void addAllSourcePackages(IProject project, Set list) { try {/*w w w . j a v a 2 s.co m*/ 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) { IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(project.getFolder(path)); IJavaElement[] children = root.getChildren(); for (int j = 0; j < children.length; j++) { IPackageFragment frag = (IPackageFragment) children[j]; if (frag.getChildren().length > 0 || frag.getNonJavaResources().length > 0) list.add(children[j].getElementName()); } } } } } catch (JavaModelException e) { } }
From source file:at.spardat.xma.guidesign.presentation.XMAPropertyDescriptor.java
License:Open Source License
private String[] getSourceFolderStrings() { IProject project = editor.getResourceFile().getProject(); File workspaceLocation = project.getWorkspace().getRoot().getLocation().toFile(); IJavaProject jp = JavaCore.create(project); IClasspathEntry[] javacp;/*from w w w .j a v a 2 s. c o m*/ try { javacp = jp.getResolvedClasspath(true); } catch (JavaModelException e) { GUIDesignerPlugin.INSTANCE.log(e); return new String[] { project.getLocation().toString() + "/src" }; } ArrayList<String> result = new ArrayList<String>(); for (IClasspathEntry classpathEntry : javacp) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { File f = new File(workspaceLocation, classpathEntry.getPath().toString()); String s = f.getAbsolutePath(); result.add(s); } } return result.toArray(new String[result.size()]); }
From source file:bndtools.wizards.project.NewBndProjectWizardPageTwo.java
License:Open Source License
@Override public boolean isPageComplete() { boolean resultFromSuperClass = super.isPageComplete(); int nr = 0;/* www .j a va 2s .c o m*/ try { IClasspathEntry[] entries = getJavaProject().getResolvedClasspath(true); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { nr++; // here we could do more validation on the paths if we want to // for now we just count pages } } } catch (Exception e) { // if for some reason we cannot access the resolved classpath // we simply set an error message setErrorMessage("Could not access resolved classpaths: " + e); } // we're okay if we have exactly at most two valid source paths // most templates use 2 source sets (main + test) but some do not // have the test source set return resultFromSuperClass && (1 <= nr) && (nr <= 2); }
From source file:br.ufal.cideei.handlers.DoAnalysisOnClassPath.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { //#ifdef CACHEPURGE //@ br.Main.randomLong(); //#endif/*from ww w .jav a 2 s . c o m*/ // TODO: exteriorize this number as a configuration parameter. Abstract away the looping. try { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); Object firstElement = selection.getFirstElement(); if (!(firstElement instanceof IJavaProject)) { throw new UnsupportedOperationException("Selected resource is not a java project"); } IJavaProject javaProject = (IJavaProject) firstElement; IClasspathEntry[] classPathEntries = null; try { classPathEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { e.printStackTrace(); throw new ExecutionException("No source classpath identified"); } /* * To build the path string variable that will represent Soot's classpath we will first iterate * through all libs (.jars) files, then through all source classpaths. * * FIXME: WARNING: A bug was found on Soot, in which the FileSourceTag would contain incorrect * information regarding the absolute location of the source file. In this workaround, the classpath * must be injected into the FeatureModelInstrumentorTransformer class (done through its * constructor). * * As a consequence, we CANNOT build an string with all classpaths that contains source code for the * project and thus one only source code classpath can be analysed at a given time. * * This seriously restricts the range of projects that can be analysed with this tool. */ List<IClasspathEntry> sourceClasspathEntries = new ArrayList<IClasspathEntry>(); StringBuilder libsPaths = new StringBuilder(); for (IClasspathEntry entry : classPathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = entry.getPath().makeAbsolute().toFile(); if (file.isAbsolute()) { libsPaths.append(file.getAbsolutePath() + File.pathSeparator); } else { libsPaths.append(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocation().toOSString() + File.pathSeparator); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceClasspathEntries.add(entry); } } if (sourceClasspathEntries.size() != 1) { throw new UnsupportedOperationException("project must have exactly one source classpath entry"); } IClasspathEntry entry = sourceClasspathEntries.get(0); final int times = 10; for (int i = 0; i < times; i++) { // #ifdef METRICS String sinkFile = System.getProperty("user.home") + File.separator + javaProject.getElementName().trim().toLowerCase().replace(' ', '-') + "-fs"; // #ifdef LAZY sinkFile += "-lazy"; // #endif // #ifdef FEATUREMODEL //@ sinkFile += "-fm"; // #endif sink = new MetricsSink(new MetricsTable(new File(sinkFile + ".xls"))); // #endif this.addPacks(javaProject, entry, libsPaths.toString()); SootManager.reset(); // #ifdef METRICS sink.terminate(); // #endif System.out.println("=============" + (i + 1) + "/" + times + "============="); } sink.createSummaryFile(); } catch (Throwable e) { e.printStackTrace(); } finally { SootManager.reset(); // #ifdef METRICS if (sink != null && !sink.terminated()) { sink.terminate(); } // #endif } return null; }
From source file:br.ufal.cideei.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try {//from w w w .j a v a 2 s . c o m IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); Object firstElement = selection.getFirstElement(); if (!(firstElement instanceof IJavaProject)) { throw new UnsupportedOperationException("selected resource is not a java project"); } IJavaProject javaProject = (IJavaProject) firstElement; IClasspathEntry[] classPathEntries = null; try { classPathEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { e.printStackTrace(); throw new ExecutionException("No source classpath identified"); } /* * To build the path string variable that will represent Soot's classpath we will first iterate * through all libs (.jars) files, then through all source classpaths. * * FIXME: WARNING: A bug was found on Soot, in which the FileSourceTag would contain incorrect * information regarding the absolute location of the source file. In this workaround, the classpath * must be injected into the FeatureModelInstrumentorTransformer class (done though its * constructor). * * As a consequence, we CANNOT build an string with all classpaths that contains source code for the * project and thus only one source code classpath can be analysed at a given time. * * This seriously restricts the range of projects that can be analysed with this tool. */ List<IClasspathEntry> sourceClasspathEntries = new ArrayList<IClasspathEntry>(); StringBuilder libsPaths = new StringBuilder(); for (IClasspathEntry entry : classPathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = entry.getPath().makeAbsolute().toFile(); if (file.isAbsolute()) { libsPaths.append(file.getAbsolutePath() + File.pathSeparator); } else { libsPaths.append(ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocation().toOSString() + File.pathSeparator); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceClasspathEntries.add(entry); } } if (sourceClasspathEntries.size() != 1) { throw new UnsupportedOperationException("project must have exactly one source classpath entry"); } IClasspathEntry entry = sourceClasspathEntries.get(0); final int times = 10; for (int i = 0; i < times; i++) { // #ifdef METRICS String sinkFile = System.getProperty("user.home") + File.separator + javaProject.getElementName().trim().toLowerCase().replace(' ', '-') + "-fo"; // #ifdef LAZY sinkFile += "-lazy"; // #endif // #ifdef FEATUREMODEL //@ sinkFile += "-fm"; // #endif sink = new MetricsSink(new MetricsTable(new File(sinkFile + ".xls"))); // #endif this.addPacks(javaProject, entry, libsPaths.toString()); SootManager.reset(); // #ifdef METRICS sink.terminate(); // #endif System.out.println("=============" + (i + 1) + "/" + times + "============="); } sink.createFeatureObliviousSummaryFile(); } catch (Throwable e) { e.printStackTrace(); } finally { SootManager.reset(); // #ifdef METRICS if (sink != null && !sink.terminated()) { sink.terminate(); } // #endif } return null; }
From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java
License:Open Source License
/** * Gets the correspondent classpath.//w ww. j a v a 2 s. c o m * * @param file * the file * @return the correspondent classpath * @throws ExecutionException * the execution exception */ public static String getCorrespondentClasspath(IFile file) throws ExecutionException { /* * used to find out what the classpath entry related to the IFile of the * text selection. this is necessary for some algorithms that might use * the Soot framework */ IProject project = file.getProject(); IJavaProject javaProject = null; try { if (file.getProject().isNatureEnabled("org.eclipse.jdt.core.javanature")) { javaProject = JavaCore.create(project); } } catch (CoreException e) { e.printStackTrace(); throw new ExecutionException("Not a Java Project"); } /* * When using the Soot framework, we need the path to the package root * in which the file is located. There may be other ways to acomplish * this. */ String pathToSourceClasspathEntry = null; IClasspathEntry[] classPathEntries = null; try { classPathEntries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { e.printStackTrace(); throw new ExecutionException("No source classpath identified"); } for (IClasspathEntry entry : classPathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { pathToSourceClasspathEntry = ResourcesPlugin.getWorkspace().getRoot().getFile(entry.getPath()) .getLocation().toOSString(); break; } } return pathToSourceClasspathEntry; }
From source file:ca.mcgill.cs.swevo.ppa.ui.PPAJavaProjectHelper.java
License:Open Source License
private List getDefaultClassPath(IJavaProject jproj) { List list = new ArrayList(); IResource srcFolder;/*from www . j a va 2s . c o m*/ IPreferenceStore store = PreferenceConstants.getPreferenceStore(); String sourceFolderName = store.getString(PreferenceConstants.SRCBIN_SRCNAME); if (store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ) && sourceFolderName.length() > 0) { srcFolder = jproj.getProject().getFolder(sourceFolderName); } else { srcFolder = jproj.getProject(); } list.add(new CPListElement(jproj, IClasspathEntry.CPE_SOURCE, srcFolder.getFullPath(), srcFolder)); IClasspathEntry[] jreEntries = PreferenceConstants.getDefaultJRELibrary(); list.addAll(getExistingEntries(jreEntries)); return list; }
From source file:ca.mcgill.sable.soot.examples.NewSootExampleWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean performFinish = super.performFinish(); if (performFinish) { IJavaProject newProject = (IJavaProject) getCreatedElement(); try {/*from ww w . ja v a 2 s. c o m*/ IClasspathEntry[] originalCP = newProject.getRawClasspath(); IClasspathEntry ajrtLIB = JavaCore.newVariableEntry( new Path(SootClasspathVariableInitializer.VARIABLE_NAME_CLASSES), new Path(SootClasspathVariableInitializer.VARIABLE_NAME_SOURCE), null); // Update the raw classpath with the new entry int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = ajrtLIB; newProject.setRawClasspath(newCP, new NullProgressMonitor()); } catch (JavaModelException e) { } String templateFilePath = fromFile; InputStream is = null; FileOutputStream fos = null; try { is = SootPlugin.getDefault().getBundle().getResource(templateFilePath).openStream(); if (is == null) { new RuntimeException("Resource " + templateFilePath + " not found!").printStackTrace(); } else { IClasspathEntry[] resolvedClasspath = newProject.getResolvedClasspath(true); IClasspathEntry firstSourceEntry = null; for (IClasspathEntry classpathEntry : resolvedClasspath) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { firstSourceEntry = classpathEntry; break; } } if (firstSourceEntry != null) { IPath path = SootPlugin.getWorkspace().getRoot().getFile(firstSourceEntry.getPath()) .getLocation(); String srcPath = path.toString(); String newfileName = toFile; final IPath newFilePath = firstSourceEntry.getPath().append(newfileName); fos = new FileOutputStream(srcPath + File.separator + newfileName); int temp = is.read(); while (temp > -1) { fos.write(temp); temp = is.read(); } fos.close(); //refresh project newProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); final IWorkbenchPage activePage = JavaPlugin.getActivePage(); if (activePage != null) { final Display display = getShell().getDisplay(); if (display != null) { display.asyncExec(new Runnable() { public void run() { try { IResource newResource = SootPlugin.getWorkspace().getRoot() .findMember(newFilePath); IDE.openEditor(activePage, (IFile) newResource, true); } catch (PartInitException e) { JavaPlugin.log(e); } } }); } } } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); if (fos != null) fos.close(); } catch (IOException e) { } } } return performFinish; }
From source file:ccw.builder.ClojureBuilder.java
License:Open Source License
private static Map<IFolder, IFolder> getSrcFolders(IProject project) throws CoreException { Map<IFolder, IFolder> srcFolders = new HashMap<IFolder, IFolder>(); IJavaProject jProject = JavaCore.create(project); IClasspathEntry[] entries = jProject.getResolvedClasspath(true); IPath defaultOutputFolder = jProject.getOutputLocation(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IFolder folder = project.getWorkspace().getRoot().getFolder(entry.getPath()); IFolder outputFolder = project.getWorkspace().getRoot().getFolder( (entry.getOutputLocation() == null) ? defaultOutputFolder : entry.getOutputLocation()); if (folder.exists()) srcFolders.put(folder, outputFolder); break; case IClasspathEntry.CPE_LIBRARY: break; case IClasspathEntry.CPE_PROJECT: // TODO should compile here ? break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: // Impossible cases, since entries are resolved default:// w ww. j a v a2 s. c om break; } } return srcFolders; }