List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
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) {/*from w w w . j a v a2 s. c o 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 void insert(CPListElement element, List<CPListElement> cpList) { int length = cpList.size(); CPListElement[] elements = cpList.toArray(new CPListElement[length]); int i = 0;//from w w w. j av a2 s . c o m while (i < length && elements[i].getEntryKind() != element.getEntryKind()) { i++; } if (i < length) { i++; while (i < length && elements[i].getEntryKind() == element.getEntryKind()) { i++; } cpList.add(i, element); return; } switch (element.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: cpList.add(0, element); break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_PROJECT: case IClasspathEntry.CPE_VARIABLE: default: cpList.add(element); break; } }
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// w w w . j a v a2s. co 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 ww w .j a v a 2s .co 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: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 . j av a2 s .com*/ 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()); }/* w w w .j a va 2s.c o 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: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 w ww . ja v a 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/*from ww w . j ava 2 s. c o m*/ * @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:com.android.ide.eclipse.adt.build.BaseBuilder.java
License:Open Source License
/** * Returns an array of external jar files used by the project. * @return an array of OS-specific absolute file paths *//*from w w w.j av a 2 s . c om*/ protected final String[] getExternalJars() { // get the current project IProject project = getProject(); // get a java project from it IJavaProject javaProject = JavaCore.create(project); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); ArrayList<String> oslibraryList = new ArrayList<String>(); IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // if this is a classpath variable reference, we resolve it. if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { e = JavaCore.getResolvedClasspathEntry(e); } // get the IPath IPath path = e.getPath(); // check the name ends with .jar if (AndroidConstants.EXT_JAR.equalsIgnoreCase(path.getFileExtension())) { boolean local = false; IResource resource = wsRoot.findMember(path); if (resource != null && resource.exists() && resource.getType() == IResource.FILE) { local = true; oslibraryList.add(resource.getLocation().toOSString()); } if (local == false) { // if the jar path doesn't match a workspace resource, // then we get an OSString and check if this links to a valid file. String osFullPath = path.toOSString(); File f = new File(osFullPath); if (f.exists()) { oslibraryList.add(osFullPath); } else { String message = String.format(Messages.Couldnt_Locate_s_Error, path); AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, message); // Also put a warning marker on the project markProject(AdtConstants.MARKER_ADT, message, IMarker.SEVERITY_WARNING); } } } } } } return oslibraryList.toArray(new String[oslibraryList.size()]); }
From source file:com.android.ide.eclipse.adt.internal.build.BuildHelper.java
License:Open Source License
private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, ResourceMarker resMarker) {/*from w w w. jav a2 s .c om*/ // if this is a classpath variable reference, we resolve it. if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject refProject = wsRoot.getProject(entry.getPath().lastSegment()); try { // ignore if it's an Android project, or if it's not a Java Project if (refProject.hasNature(JavaCore.NATURE_ID) && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) { IJavaProject refJavaProject = JavaCore.create(refProject); // get the output folder IPath path = refJavaProject.getOutputLocation(); IResource outputResource = wsRoot.findMember(path); if (outputResource != null && outputResource.getType() == IResource.FOLDER) { mCompiledCodePaths.add(outputResource.getLocation().toOSString()); } } } catch (CoreException exception) { // can't query the project nature? ignore } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { handleClasspathLibrary(entry, wsRoot, resMarker); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); // ignore the system and default_system types as they represent // libraries that are part of the runtime. if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) { IClasspathEntry[] entries = container.getClasspathEntries(); for (IClasspathEntry cpe : entries) { handleCPE(cpe, javaProject, wsRoot, resMarker); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }