List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java
License:Open Source License
public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement, IJavaProject project) {// w ww . j a v a 2 s . co m IPath path = curr.getPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // get the resource IResource res = null; boolean isMissing = false; IPath linkTarget = null; switch (curr.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: try { isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null); } catch (JavaModelException e) { isMissing = true; } break; case IClasspathEntry.CPE_VARIABLE: IPath resolvedPath = JavaCore.getResolvedVariablePath(path); isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists(); break; case IClasspathEntry.CPE_LIBRARY: res = root.findMember(path); if (res == null) { if (!ArchiveFileFilter.isArchivePath(path, true)) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK() && root.getProject(path.segment(0)).exists()) { res = root.getFolder(path); } } IPath rawPath = path; if (project != null) { IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr); if (roots.length == 1) rawPath = roots[0].getPath(); } isMissing = !rawPath.toFile().exists(); // look for external JARs and folders } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_SOURCE: path = path.removeTrailingSeparator(); res = root.findMember(path); if (res == null) { if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { res = root.getFolder(path); } isMissing = true; } else if (res.isLinked()) { linkTarget = res.getLocation(); } break; case IClasspathEntry.CPE_PROJECT: res = root.findMember(path); isMissing = (res == null); break; } CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res, linkTarget); elem.setExported(curr.isExported()); elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath()); elem.setAttribute(OUTPUT, curr.getOutputLocation()); elem.setAttribute(EXCLUSION, curr.getExclusionPatterns()); elem.setAttribute(INCLUSION, curr.getInclusionPatterns()); elem.setAttribute(ACCESSRULES, curr.getAccessRules()); elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules())); IClasspathAttribute[] extraAttributes = curr.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName()); if (attribElem == null) { elem.createAttributeElement(attrib.getName(), attrib.getValue(), false); } else { attribElem.setValue(attrib.getValue()); } } elem.setIsMissing(isMissing); return elem; }
From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java
License:Open Source License
public static boolean isProjectSourceFolder(CPListElement[] existing, IJavaProject project) { IPath projPath = project.getProject().getFullPath(); for (int i = 0; i < existing.length; i++) { IClasspathEntry curr = existing[i].getClasspathEntry(); if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (projPath.equals(curr.getPath())) { return true; }// ww w .ja v a2 s . c o m } } return false; }
From source file:at.component.newcomponentwizard.generator.NewProjectCreationOperation.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) private void addAllSourcePackages(IProject project, Set list) { try {/*from w w w. ja va 2 s . c o 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 2s . 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.builder.BndProjectNature.java
License:Open Source License
private void installBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndContainerInitializer.PATH_ID.equals(entry.getPath())) return; // already installed }//from w w w . j a va2 s . c o m IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newEntries, 0, classpath.length); newEntries[classpath.length] = JavaCore.newContainerEntry(BndContainerInitializer.PATH_ID); javaProject.setRawClasspath(newEntries, null); }
From source file:bndtools.builder.BndProjectNature.java
License:Open Source License
private void removeBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length); boolean changed = false; for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndContainerInitializer.PATH_ID.equals(entry.getPath())) { changed = true;//from w w w . j ava 2 s . com } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null); }
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/*www.j a va2 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.DoAnalysisOnClassPath.java
License:Open Source License
/** * Configures the classpath, sets up the transformers, load (jimplify) classes and run the packs. * /*from www. j a v a 2 s . c om*/ * @param javaProject * @param entry * @param libs */ private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /* * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); System.out.println(classPath); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }
From source file:br.ufal.cideei.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try {/* w ww . j a v a2 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.handlers.DoFeatureObliviousAnalysisOnClassPath.java
License:Open Source License
private void addPacks(IJavaProject javaProject, IClasspathEntry entry, String libs) { /*//from ww w . j a va 2 s .co m * if the classpath entry is "", then JDT will complain about it. */ String classPath; if (entry.getPath().toOSString().equals(File.separator + javaProject.getElementName())) { classPath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); } else { classPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath()).getLocation() .toOSString(); } SootManager.configure(classPath + File.pathSeparator + libs); IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().getExtracter(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { IJavaElement[] children = null; try { children = packageFragmentRoot.getChildren(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (IJavaElement child : children) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] compilationUnits = null; try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ICompilationUnit compilationUnit : compilationUnits) { String fragmentName = packageFragment.getElementName(); String compilationName = compilationUnit.getElementName(); StringBuilder qualifiedNameStrBuilder = new StringBuilder(fragmentName); // If it's the default package: if (qualifiedNameStrBuilder.length() == 0) { // Remove ".java" suffix qualifiedNameStrBuilder.append(compilationName.substring(0, compilationName.length() - 5)); } else { // Remove ".java" suffix qualifiedNameStrBuilder.append(".") .append(compilationName.substring(0, compilationName.length() - 5)); } // This goes into Soot loadAndSupport SootManager.loadAndSupport(qualifiedNameStrBuilder.toString()); } } } Scene.v().loadNecessaryClasses(); AlloyConfigurationCheck alloyConfigurationCheck = null; // #ifdef FEATUREMODEL //@ try { //@ String absolutePath = javaProject.getResource().getLocation().toFile().getAbsolutePath(); //@ alloyConfigurationCheck = new AlloyConfigurationCheck(absolutePath + File.separator + "fm.als"); //@ } catch (CannotReadAlloyFileException e) { //@ e.printStackTrace(); //@ return; //@ } // #endif addPacks(classPath, extracter, alloyConfigurationCheck); SootManager.runPacks(extracter); }