List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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. jav a2 s . c om 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.//from w w w .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:byke.tests.workspaceutils.JavaProject.java
License:Open Source License
private boolean containsClasspathEntry(String absolutePath) throws JavaModelException { for (IClasspathEntry entry : _javaProject.getRawClasspath()) { if (IClasspathEntry.CPE_LIBRARY != entry.getEntryKind()) continue; if (entry.getPath().toFile().getAbsolutePath().equals(absolutePath)) return true; }/*from w w w . jav a2 s. c om*/ return false; }
From source file:bz.davide.dmeclipsesavehookplugin.builder.DMEclipseSaveHookPluginBuilder.java
License:Open Source License
static void findTransitiveDepProjects(IJavaProject current, ArrayList<IProject> projects, ArrayList<String> fullClasspath) throws CoreException { if (!projects.contains(current.getProject())) { projects.add(current.getProject()); }//from w ww.j av a 2 s . co m fullClasspath.add(ResourcesPlugin.getWorkspace().getRoot().findMember(current.getOutputLocation()) .getLocation().toOSString() + "/"); ArrayList<IClasspathEntry> classPaths = new ArrayList<IClasspathEntry>(); classPaths.addAll(Arrays.asList(current.getRawClasspath())); for (int x = 0; x < classPaths.size(); x++) { IClasspathEntry cp = classPaths.get(x); if (cp.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = cp.getPath().lastSegment(); IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName); if (prj.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(prj); findTransitiveDepProjects(javaProject, projects, fullClasspath); } continue; } if (cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String fullContainerName = cp.getPath().toString(); if (!fullContainerName.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER/")) { System.out.println("CP C: " + fullContainerName); IClasspathContainer container = JavaCore.getClasspathContainer(cp.getPath(), current); classPaths.addAll(Arrays.asList(container.getClasspathEntries())); } } if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = cp.getPath(); // Check first if this path is relative to workspace IResource workspaceMember = ResourcesPlugin.getWorkspace().getRoot().findMember(path); if (workspaceMember != null) { String fullPath = workspaceMember.getLocation().toOSString(); fullClasspath.add(fullPath); } else { fullClasspath.add(path.toOSString()); } } } }
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 w w w . j a v a 2 s.com 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:/*from ww w. j ava 2s . c o m*/ break; } } return srcFolders; }
From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.application.JavaWebApplicationDelegate.java
License:Open Source License
/** * Attempts to determine the framework based on the contents and nature of * the project. Returns null if no framework was determined. * @param project// w w w. ja va 2 s . c om * @return Framework type or null if framework was not determined. * @deprecated kept for reference as to how application type was being * determined from a Java project for legacy v1 CF servers. v2 Servers no * longer require a framework for an application, as frameworks have been * replaced with buildpacks. */ protected String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = DockerFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (DockerFoundryProjectUtil.hasNature(project, DockerFoundryConstants.GRAILS_NATURE)) { return DockerFoundryConstants.GRAILS; } // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() //$NON-NLS-1$ && project.getFile("application.properties").exists()) { //$NON-NLS-1$ return DockerFoundryConstants.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return DockerFoundryConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return DockerFoundryConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { // Log the error but don't throw it again as there may be // other ways to detect the framework DockerFoundryPlugin.log(new Status(IStatus.WARNING, DockerFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); //$NON-NLS-1$ } if (DockerFoundryProjectUtil.isSpringProject(project)) { return DockerFoundryConstants.SPRING; } if (foundSpringLibrary) { return DockerFoundryConstants.SPRING; } } } return null; }
From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.debug.DebugProvider.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *///www .j a v a2s . c om protected boolean containsDebugFiles(IJavaProject project) { try { IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (containsResource(folder, ".profile.d")) {//$NON-NLS-1$ return true; } } } } } catch (JavaModelException e) { DockerFoundryPlugin.logError(e); } catch (CoreException ce) { DockerFoundryPlugin.logError(ce); } return false; }
From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java
License:Apache License
public static boolean isContainerInClasspath(IJavaProject javaProject, IClasspathContainer container) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); // IClasspathEntry[] temps = container.getClasspathEntries(); boolean result = false; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(container.getPath())) { result = true;// www. j a v a 2 s . co m break; } } return result; }
From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java
License:Apache License
/** * Get all classpathentries for the given project. * //from ww w . j a v a2 s .co m * @param javaProject * project to get the classpath for. * @return classpathentries */ private static String[] getJavaClasspath(IJavaProject javaProject) throws CoreException { List<String> classPath = new ArrayList<String>(); String[] defaultClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject); classPath.addAll(Arrays.asList(defaultClassPath)); // add CPE_CONTAINER classpathes IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (classpathContainer != null) { IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries(); for (IClasspathEntry cEntry : classpathEntries) { classPath.add(cEntry.getPath().toOSString()); } } } } return classPath.toArray(new String[] {}); }