List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE
int CPE_VARIABLE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE.
Click Source Link
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static void addEntryToJavaBuildPath(IJavaProject jp, IClasspathAttribute attribute, String path, int eKind) { IClasspathAttribute[] attributes = new IClasspathAttribute[] { attribute }; try {//from w w w . j a v a 2 s . co m IClasspathEntry[] originalCP = jp.getRawClasspath(); IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; IClasspathEntry cp = null; if (eKind == IClasspathEntry.CPE_LIBRARY) { cp = JavaCore.newLibraryEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_VARIABLE) { cp = JavaCore.newVariableEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_CONTAINER) { cp = JavaCore.newContainerEntry(new Path(path), null, attributes, false); } else if (eKind == IClasspathEntry.CPE_PROJECT) { cp = JavaCore.newProjectEntry(new Path(path), null, true, attributes, false); } // Update the raw classpath with the new entry. if (cp != null) { System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); newCP[originalCP.length] = cp; jp.setRawClasspath(newCP, new NullProgressMonitor()); } } catch (JavaModelException e) { } catch (NumberFormatException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static String toEntryKind(String entryStr) { int entry = 0; if (entryStr.equals("SOURCE")) { //$NON-NLS-1$ entry = IClasspathEntry.CPE_SOURCE; } else if (entryStr.equals("LIBRARY")) { //$NON-NLS-1$ entry = IClasspathEntry.CPE_LIBRARY; } else if (entryStr.equals("PROJECT")) { //$NON-NLS-1$ entry = IClasspathEntry.CPE_PROJECT; } else if (entryStr.equals("VARIABLE")) { //$NON-NLS-1$ entry = IClasspathEntry.CPE_VARIABLE; } else if (entryStr.equals("CONTAINER")) { //$NON-NLS-1$ entry = IClasspathEntry.CPE_CONTAINER; }/*from www.j a v a 2 s . c o m*/ return new Integer(entry).toString(); }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
private void migrateToRTContainerIfNecessary(IJavaProject javaProject) { if (!AspectJRTInitializer.hasBeenUsed) { // if the old ASPECTJRT_LIB var hasn't been initialized // then there definitely won't be anything to migrate return;/* w w w. j a va 2 s. c om*/ } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) { String var = entries[i].getPath().segment(0); if (var.equals("ASPECTJRT_LIB")) { //$NON-NLS-1$ // replace with AspectJRT container entries[i] = JavaCore.newContainerEntry(new Path(AspectJPlugin.ASPECTJRT_CONTAINER), false); javaProject.setRawClasspath(entries, new NullProgressMonitor()); return; } } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.internal.core.ajde.CoreCompilerConfiguration.java
License:Open Source License
public String expandVariables(String path, String eKinds) { StringBuffer resultBuffer = new StringBuffer(); StringTokenizer strTok = new StringTokenizer(path, File.pathSeparator); StringTokenizer strTok2 = new StringTokenizer(eKinds, File.pathSeparator); while (strTok.hasMoreTokens()) { String current = strTok.nextToken(); int entryKind = Integer.parseInt(strTok2.nextToken()); if (entryKind == IClasspathEntry.CPE_VARIABLE) { int slashPos = current.indexOf(AspectJPlugin.NON_OS_SPECIFIC_SEPARATOR, 0); if (slashPos != -1) { String exp = JavaCore.getClasspathVariable(current.substring(0, slashPos)).toOSString(); resultBuffer.append(exp); resultBuffer.append(current.substring(slashPos)); } else { String exp = JavaCore.getClasspathVariable(current).toOSString(); resultBuffer.append(exp); }/*from w ww .j a va2 s.c o m*/ } else { resultBuffer.append(current); } resultBuffer.append(File.pathSeparator); } return resultBuffer.toString(); }
From source file:org.eclipse.ajdt.internal.core.ajde.CoreOutputLocationManager.java
License:Open Source License
private void handleClassPathEntry(IJavaProject jp, IClasspathEntry cpe) throws JavaModelException { switch (cpe.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jp); if (container != null && container.getKind() != IClasspathContainer.K_DEFAULT_SYSTEM) { IClasspathEntry[] cpes = container.getClasspathEntries(); for (int i = 0; i < cpes.length; i++) { handleClassPathEntry(jp, cpes[i]); }//from w ww . j av a 2 s. co m } break; case IClasspathEntry.CPE_LIBRARY: File libFile = pathToFile(cpe.getPath()); if (libFile.isDirectory()) { // ignore jar files if (libFile != null && !binFolderToProject.containsKey(libFile)) { binFolderToProject.put(libFile, jp.getProject()); } } break; case IClasspathEntry.CPE_PROJECT: IJavaProject jpClasspath = pathToProject(cpe.getPath()); if (jpClasspath != null) { mapProject(jpClasspath); } break; case IClasspathEntry.CPE_SOURCE: File outFile = pathToFile( cpe.getOutputLocation() == null ? jp.getOutputLocation() : cpe.getOutputLocation()); if (outFile != null && !binFolderToProject.containsKey(outFile)) { binFolderToProject.put(outFile, jp.getProject()); } break; case IClasspathEntry.CPE_VARIABLE: IClasspathEntry cpeResolved = JavaCore.getResolvedClasspathEntry(cpe); if (cpeResolved != null) { handleClassPathEntry(jp, cpeResolved); } break; } }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
/** * Checks for duplicate entries on the inpath compared to the Java build * path//from w w w . j av a2s .c om * * This checks to make sure that duplicate entries are not being referred * to. For example, it is possible for the JUnit jar to be referred to * through a classpath variable as well as a classpath container. This * method checks for such duplicates * * 1. if an inpath entry is on the build path, then remove it from checking * 2. resolve the remaining inpath entries 3. resolve the build path 4. * there should be no overlap */ private IJavaModelStatus checkForDuplicates(IJavaProject currJProject, IClasspathEntry[] entries) { try { Map<String, IClasspathEntry> allEntries = new HashMap<String, IClasspathEntry>(entries.length, 1.0f); for (int i = 0; i < entries.length; i++) { // ignore entries that are inside of a container if (getClasspathContainer(entries[i]) == null) { allEntries.put(entries[i].getPath().toPortableString(), entries[i]); } } IClasspathEntry[] rawProjectClasspath = currJProject.getRawClasspath(); for (int i = 0; i < rawProjectClasspath.length; i++) { allEntries.remove(rawProjectClasspath[i].getPath().toPortableString()); } IClasspathEntry[] resolvedProjectClasspath = currJProject.getResolvedClasspath(true); Map<String, IClasspathEntry> resolvedEntries = new HashMap<String, IClasspathEntry>(); Iterator<IClasspathEntry> allEntriesIter = allEntries.values().iterator(); while (allEntriesIter.hasNext()) { ClasspathEntry rawEntry = (ClasspathEntry) allEntriesIter.next(); switch (rawEntry.entryKind) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(rawEntry); resolvedEntries.put(resolvedEntry.getPath().toPortableString(), resolvedEntry); break; case IClasspathEntry.CPE_CONTAINER: List containerEntries = AspectJCorePreferences.resolveClasspathContainer(rawEntry, currJProject.getProject()); for (Iterator containerIter = containerEntries.iterator(); containerIter.hasNext();) { IClasspathEntry containerEntry = (IClasspathEntry) containerIter.next(); resolvedEntries.put(containerEntry.getPath().toPortableString(), containerEntry); } break; case IClasspathEntry.CPE_PROJECT: IProject thisProject = currJProject.getProject(); IProject requiredProj = thisProject.getWorkspace().getRoot() .getProject(rawEntry.getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(thisProject.getName()) && requiredProj.exists()) { List containerEntries2 = AspectJCorePreferences.resolveDependentProjectClasspath(rawEntry, requiredProj); for (Iterator containerIter = containerEntries2.iterator(); containerIter.hasNext();) { IClasspathEntry containerEntry = (IClasspathEntry) containerIter.next(); resolvedEntries.put(containerEntry.getPath().toPortableString(), containerEntry); } } break; } } for (int i = 0; i < resolvedProjectClasspath.length; i++) { if (resolvedEntries.containsKey(resolvedProjectClasspath[i].getPath().toPortableString())) { // duplicate found. return new JavaModelStatus(IStatus.WARNING, IStatus.WARNING, currJProject, currJProject.getPath(), UIMessages.InPathBlock_DuplicateBuildEntry + resolvedProjectClasspath[i].getPath()); } } return JavaModelStatus.VERIFIED_OK; } catch (JavaModelException e) { return new JavaModelStatus(e); } }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
private CPListElement[] openVariableSelectionDialog() { List existingElements = fPathList.getElements(); ArrayList<IPath> existingPaths = new ArrayList<IPath>(existingElements.size()); for (int i = 0; i < existingElements.size(); i++) { CPListElement elem = (CPListElement) existingElements.get(i); if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { existingPaths.add(elem.getPath()); }/* w ww . j av a2 s . c o m*/ } IPath[] existingPathsArray = existingPaths.toArray(new IPath[existingPaths.size()]); IPath[] paths = BuildPathDialogAccess.chooseVariableEntries(getShell(), existingPathsArray); if (paths != null) { ArrayList<CPListElement> result = new ArrayList<CPListElement>(); for (int i = 0; i < paths.length; i++) { CPListElement elem = new CPListElement(fCurrJProject, IClasspathEntry.CPE_VARIABLE, paths[i], null); IPath resolvedPath = JavaCore.getResolvedVariablePath(paths[i]); elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists()); if (!existingElements.contains(elem)) { result.add(elem); } } return result.toArray(new CPListElement[result.size()]); } return null; }
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 w w w . ja v a2s .co 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 . j a v a 2 s . 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.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 v a 2s . 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()); } } }