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:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasClassFolderDependency(IProject project, IProject projectDependedOn) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IJavaProject depProject = JavaCore.create(projectDependedOn); if (javaProject == null || depProject == null) return false; // first get the output location for projectDependedOn IPath outputLocation = null;/*from w w w . j ava 2 s. co m*/ IClasspathEntry[] cp = depProject.getRawClasspath(); for (int j = 0; j < cp.length; j++) { IClasspathEntry entry = cp[j]; int contentKind = entry.getContentKind(); if (contentKind == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } if (entry.getEntryKind() == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } } if (outputLocation == null) { outputLocation = depProject.getOutputLocation(); } // now check the classpath entries of project for the output // location just calculated IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int entryKind = entry.getEntryKind(); IPath entryPath = entry.getPath(); if (entryKind == IClasspathEntry.CPE_LIBRARY && entryPath.equals(outputLocation)) { return true; } } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasAnExportedClasspathEntry(IProject project) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return false; }/* www .j ava 2 s . co m*/ try { IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.isExported()) { // we don't want to export it in the new classpath. if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return true; } } } } catch (JavaModelException e) { AspectJTestPlugin.log(e); } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasJarOnClasspath(IProject projectToHaveJar, IProject projectWhichExportedJar) throws JavaModelException { IJavaProject javaProject1 = JavaCore.create(projectToHaveJar); IJavaProject javaProject2 = JavaCore.create(projectWhichExportedJar); if (javaProject1 == null || javaProject2 == null) { return false; }// ww w. ja v a 2s . c om IClasspathEntry[] cpEntry2 = javaProject2.getRawClasspath(); for (int j = 0; j < cpEntry2.length; j++) { IClasspathEntry entry = cpEntry2[j]; if (entry.isExported()) { // we don't want to export it in the new classpath. if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry[] cpEntry1 = javaProject1.getRawClasspath(); for (int i = 0; i < cpEntry1.length; i++) { IClasspathEntry entry1 = cpEntry1[i]; if (entry1.getEntryKind() == entry.getEntryKind() && entry1.getPath().equals(entry.getPath())) { if (entry1.isExported()) { // don't want it to be exported return false; } return true; } } return false; } } } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasOutJarOnClasspath(IProject projectToHaveJar, IProject projectWhichHasOutJar, String outJar) throws JavaModelException { IJavaProject javaProject1 = JavaCore.create(projectToHaveJar); if (javaProject1 == null) { return false; }//ww w . j a va 2 s . c om System.out.println("TEST: outjar = " + outJar); //$NON-NLS-1$ StringBuffer sb = new StringBuffer(outJar); int indexOfProject = sb.lastIndexOf(projectWhichHasOutJar.getName()); IPath newPath; if (indexOfProject < 0) { newPath = new Path(outJar); } else { newPath = new Path(sb.substring(indexOfProject)); } IClasspathEntry[] cpEntry = javaProject1.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (entry.getPath().equals(new Path(outJar)) || entry.getPath().equals(newPath.makeAbsolute())) { return true; } } } return false; }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static int numberOfTimesOutJarOnClasspath(IProject projectToHaveJar, IProject projectWhichHasOutJar, String outJar) throws JavaModelException { IJavaProject javaProject1 = JavaCore.create(projectToHaveJar); if (javaProject1 == null) { return -1; }/* w ww.j a v a 2 s. com*/ int counter = 0; System.out.println("TEST: outjar = " + outJar); //$NON-NLS-1$ StringBuffer sb = new StringBuffer(outJar); int indexOfProject = sb.lastIndexOf(projectWhichHasOutJar.getName()); String jar = sb.substring(indexOfProject); IPath newPath = new Path(jar); IClasspathEntry[] cpEntry = javaProject1.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (entry.getPath().equals(new Path(outJar)) || entry.getPath().equals(newPath.makeAbsolute())) { counter++; } } } return counter; }
From source file:org.eclipse.andmore.internal.build.BuildHelper.java
License:Open Source License
private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, ResourceMarker resMarker) {/*from ww w .ja v a 2 s . c o m*/ // 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(AndmoreAndroidConstants.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. AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }
From source file:org.eclipse.andmore.internal.lint.EclipseLintClient.java
License:Open Source License
@Override @NonNull// ww w .ja v a2s . c om protected ClassPathInfo getClassPath(@NonNull Project project) { ClassPathInfo info; if (mProjectInfo == null) { mProjectInfo = Maps.newHashMap(); info = null; } else { info = mProjectInfo.get(project); } if (info == null) { List<File> sources = null; List<File> classes = null; List<File> libraries = null; IProject p = getProject(project); if (p != null) { try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(p); // Output path File file = workspacePathToFile(javaProject.getOutputLocation()); classes = Collections.singletonList(file); // Source path IClasspathEntry[] entries = javaProject.getRawClasspath(); sources = new ArrayList<File>(entries.length); libraries = new ArrayList<File>(entries.length); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); if (entry == null) { // It's possible that the variable is no longer valid; ignore continue; } kind = entry.getEntryKind(); } if (kind == IClasspathEntry.CPE_SOURCE) { sources.add(workspacePathToFile(entry.getPath())); } else if (kind == IClasspathEntry.CPE_LIBRARY) { libraries.add(entry.getPath().toFile()); } // Note that we ignore IClasspathEntry.CPE_CONTAINER: // Normal Android Eclipse projects supply both // AdtConstants.CONTAINER_FRAMEWORK // and // AdtConstants.CONTAINER_LIBRARIES // here. We ignore the framework classes for obvious reasons, // but we also ignore the library container because lint will // process the libraries differently. When Eclipse builds a // project, it gets the .jar output of the library projects // from this container, which means it doesn't have to process // the library sources. Lint on the other hand wants to process // the source code, so instead it actually looks at the // project.properties file to find the libraries, and then it // iterates over all the library projects in turn and analyzes // those separately (but passing the main project for context, // such that the including project's manifest declarations // are used for data like minSdkVersion level). // // Note that this container will also contain *other* // libraries (Java libraries, not library projects) that we // *should* include. However, we can't distinguish these // class path entries from the library project jars, // so instead of looking at these, we simply listFiles() in // the libs/ folder after processing the classpath info } // Add in libraries File libs = new File(project.getDir(), FD_NATIVE_LIBS); if (libs.isDirectory()) { File[] jars = libs.listFiles(); if (jars != null) { for (File jar : jars) { if (SdkUtils.endsWith(jar.getPath(), DOT_JAR)) { libraries.add(jar); } } } } } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } } if (sources == null) { sources = super.getClassPath(project).getSourceFolders(); } if (classes == null) { classes = super.getClassPath(project).getClassFolders(); } if (libraries == null) { libraries = super.getClassPath(project).getLibraries(); } info = new ClassPathInfo(sources, classes, libraries, null); mProjectInfo.put(project, info); } return info; }
From source file:org.eclipse.andmore.internal.project.AndroidClasspathContainerInitializer.java
License:Open Source License
@Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { AndmoreAndroidPlugin plugin = AndmoreAndroidPlugin.getDefault(); synchronized (Sdk.getLock()) { boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED; // check if the project has a valid target. IAndroidTarget target = null;//from ww w. ja v a2s . co m if (sdkIsLoaded) { target = Sdk.getCurrent().getTarget(project.getProject()); } if (sdkIsLoaded && target != null) { String[] paths = getTargetPaths(target); IPath android_lib = new Path(paths[CACHE_INDEX_JAR]); IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = entry.getPath(); if (entryPath != null) { if (entryPath.equals(android_lib)) { IPath entrySrcPath = entry.getSourceAttachmentPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (entrySrcPath != null) { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), entrySrcPath.toString()); } else { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), null); } IClasspathAttribute[] extraAttributtes = entry.getExtraAttributes(); if (extraAttributtes.length == 0) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, NULL_API_URL); } for (int j = 0; j < extraAttributtes.length; j++) { IClasspathAttribute extraAttribute = extraAttributtes[j]; String value = extraAttribute.getValue(); if ((value == null || value.trim().length() == 0) && IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { value = NULL_API_URL; } if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME .equals(extraAttribute.getName())) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, value); } } } } } } rebindClasspathEntries(project.getJavaModel(), containerPath); } } }
From source file:org.eclipse.andmore.internal.project.LibraryClasspathContainerInitializer.java
License:Open Source License
/** * Processes a {@link IClasspathEntry} and add it to one of the list if applicable. * @param entry the entry to process/* w w w .j a va 2 s. c o m*/ * @param javaProject the {@link IJavaProject} from which this entry came. * @param wsRoot the {@link IWorkspaceRoot} * @param projects the project list to add to * @param jarFiles the jar list to add to * @param includeJarFiles whether to include jar files or just projects. This is useful when * calling on an Android project (value should be <code>false</code>) */ private static void processCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot, Set<IProject> projects, Set<File> jarFiles, boolean includeJarFiles) { // 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(AndmoreAndroidConstants.NATURE_DEFAULT) == false) { // add this project to the list projects.add(refProject); // also get the dependency from this project. getDependencyListFromClasspath(refProject, projects, jarFiles, true /*includeJarFiles*/); } } catch (CoreException exception) { // can't query the project nature? ignore } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (includeJarFiles) { handleClasspathLibrary(entry, wsRoot, jarFiles); } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container and its content 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) { processCPE(cpe, javaProject, wsRoot, projects, jarFiles, includeJarFiles); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath()); } } }
From source file:org.eclipse.andmore.internal.resources.manager.ProjectClassLoader.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 ava 2 s . co m private final URL[] getExternalJars() { // get a java project from it IJavaProject javaProject = JavaCore.create(mJavaProject.getProject()); ArrayList<URL> oslibraryList = new ArrayList<URL>(); 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); } handleClassPathEntry(e, oslibraryList); } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // get the container. try { IClasspathContainer container = JavaCore.getClasspathContainer(e.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 entry : entries) { // TODO: Xav -- is this necessary? if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { entry = JavaCore.getResolvedClasspathEntry(entry); } handleClassPathEntry(entry, oslibraryList); } } } catch (JavaModelException jme) { // can't resolve the container? ignore it. AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", e.getPath()); } } } } return oslibraryList.toArray(new URL[oslibraryList.size()]); }