List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static List<IBuildpathEntry> fetchBuildEntryFromJavaProject(IJavaProject javaProject) { // Project entry List<IBuildpathEntry> vEntries = new ArrayList<IBuildpathEntry>(); List<String> duplicateChecker = new ArrayList<String>(); IClasspathEntry[] entries2;/* w ww . java 2 s. co m*/ try { entries2 = javaProject.getRawClasspath(); } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java prjoect classpath: " + javaProject.getElementName(), e, IStatus.WARNING); return Collections.emptyList(); } for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); String sPath = path.toString(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToVJETEntry(entry, vEntries, duplicateChecker); case IClasspathEntry.CPE_PROJECT: IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource != null && subResource.getType() == IResource.PROJECT) { addProjectEntry(entry.getPath(), vEntries, duplicateChecker); } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.segment(0))) { IClasspathContainer container; try { container = JavaCore.getClasspathContainer(path, javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToVJETEntry(entries[i], vEntries, duplicateChecker); } } } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java classpath container: " + sPath, e, IStatus.WARNING); } } break; default: break; } } return vEntries; }
From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java
License:Open Source License
/** * Creates a new project./*from w w w. j a va2 s . c o m*/ * * @param project The project. * @param depends Comma separated project names this project depends on. */ protected void create(IProject project, String depends) throws Exception { // with scala-ide installed, apparently this needs to be explicitly done IProjectDescription desc = project.getDescription(); if (!desc.hasNature(PluginResources.NATURE)) { String[] natures = desc.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = PluginResources.NATURE; desc.setNatureIds(newNatures); project.setDescription(desc, new NullProgressMonitor()); } IJavaProject javaProject = JavaCore.create(project); ((JavaProject) javaProject).configure(); if (!project.getFile(CLASSPATH).exists()) { ArrayList<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>(); boolean source = false; boolean container = false; ClassPathDetector detector = new ClassPathDetector(project, null); for (IClasspathEntry entry : detector.getClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { source = true; } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { container = true; } classpath.add(entry); } // default source folder if (!source) { IResource src; IPreferenceStore store = PreferenceConstants.getPreferenceStore(); String name = store.getString(PreferenceConstants.SRCBIN_SRCNAME); boolean srcBinFolders = store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ); if (srcBinFolders && name.length() > 0) { src = javaProject.getProject().getFolder(name); } else { src = javaProject.getProject(); } classpath.add(new CPListElement(javaProject, IClasspathEntry.CPE_SOURCE, src.getFullPath(), src) .getClasspathEntry()); File srcPath = new File(ProjectUtils.getFilePath(project, src.getFullPath().toString())); if (!srcPath.exists()) { srcPath.mkdirs(); } } // default containers if (!container) { for (IClasspathEntry entry : PreferenceConstants.getDefaultJRELibrary()) { classpath.add(entry); } } // dependencies on other projects for (IClasspathEntry entry : createOrUpdateDependencies(javaProject, depends)) { classpath.add(entry); } javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), null); // output location IPath output = detector.getOutputLocation(); if (output == null) { output = BuildPathsBlock.getDefaultOutputLocation(javaProject); } javaProject.setOutputLocation(output, null); } javaProject.makeConsistent(null); javaProject.save(null, false); }
From source file:org.eclim.plugin.jdt.util.ClasspathUtils.java
License:Open Source License
/** * Recursively collects classpath entries from the current and dependent * projects./*from www. j a v a 2 s .c o m*/ */ private static void collect(IJavaProject javaProject, List<String> paths, Set<IJavaProject> visited, boolean isFirstProject) throws Exception { if (visited.contains(javaProject)) { return; } visited.add(javaProject); try { IPath out = javaProject.getOutputLocation(); paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } catch (JavaModelException ignore) { // ignore... just signals that no output dir was configured. } IProject project = javaProject.getProject(); String name = project.getName(); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException jme) { // this may or may not be a problem. logger.warn("Unable to retrieve resolved classpath for project: " + name, jme); return; } final List<IJavaProject> nextProjects = new ArrayList<IJavaProject>(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: String path = entry.getPath().toOSString().replace('\\', '/'); if (path.startsWith("/" + name + "/")) { path = ProjectUtils.getFilePath(project, path); } paths.add(path); break; case IClasspathEntry.CPE_PROJECT: if (isFirstProject || entry.isExported()) { javaProject = JavaUtils.getJavaProject(entry.getPath().segment(0)); if (javaProject != null) { // breadth first, not depth first, to preserve dependency ordering nextProjects.add(javaProject); } } break; case IClasspathEntry.CPE_SOURCE: IPath out = entry.getOutputLocation(); if (out != null) { paths.add(ProjectUtils.getFilePath(javaProject.getProject(), out.addTrailingSeparator().toOSString())); } break; } } // depth second for (final IJavaProject nextProject : nextProjects) { collect(nextProject, paths, visited, false); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the aspect path *//* w ww .java2 s . co m*/ public static boolean isOnAspectpath(IProject project, String path) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(path)) { if (isOnAspectpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static List<IClasspathEntry> resolveClasspathContainer(IClasspathEntry classpathContainerEntry, IProject thisProject) throws JavaModelException { IJavaProject thisJavaProject = JavaCore.create(thisProject); IClasspathContainer container = JavaCore.getClasspathContainer(classpathContainerEntry.getPath(), thisJavaProject);// w w w . ja va2s . c o m if (container != null) { List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int i = 0; i < containerEntries.length; i++) { // projects must be resolved specially since the AspectJ doesn't understand the // concept of project switch (containerEntries[i].getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IProject requiredProj = thisProject.getWorkspace().getRoot() .getProject(containerEntries[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(thisProject.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(containerEntries[i], requiredProj)); } break; case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore .getResolvedClasspathEntry(containerEntries[i]); if (resolvedClasspathEntry != null) { actualEntries.add(resolvedClasspathEntry); } break; case IClasspathEntry.CPE_CONTAINER: // not sure if we can have this, but try anyway actualEntries.addAll(resolveClasspathContainer(containerEntries[i], thisProject)); break; case IClasspathEntry.CPE_LIBRARY: actualEntries.add(containerEntries[i]); break; default: // do nothing } } return actualEntries; } else { return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Resolves a single classpath entry/*from ww w. ja v a 2 s.co m*/ * @param entry the classpath entry to resolve * @param thisProject the java project that has this entry * @return the resolved list of classpath entries * @throws JavaModelException */ public static List<IClasspathEntry> resolveClasspath(IClasspathEntry entry, IProject thisProject) throws JavaModelException { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: return resolveClasspathContainer(entry, thisProject); case IClasspathEntry.CPE_LIBRARY: return Collections.singletonList(entry); case IClasspathEntry.CPE_PROJECT: IProject containedProj = thisProject.getWorkspace().getRoot() .getProject(entry.getPath().makeRelative().toPortableString()); if (!containedProj.getName().equals(thisProject.getName()) && containedProj.exists()) { return resolveDependentProjectClasspath(entry, containedProj); } else { return Collections.emptyList(); } case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(entry); if (resolvedClasspathEntry != null) { return Collections.singletonList(resolvedClasspathEntry); } else { return Collections.emptyList(); } default: return Collections.emptyList(); } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Checks to see if an entry is already on the Inpath *//*from ww w . java2 s . c o m*/ public static boolean isOnInpath(IProject project, String jarPath) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if ((cp[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) || (cp[i].getEntryKind() == IClasspathEntry.CPE_VARIABLE) || (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) || (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT)) { IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolvedClasspathEntry != null) { String entry = resolvedClasspathEntry.getPath().toPortableString(); if (entry.equals(jarPath)) { if (isOnInpath(cp[i])) { return true; } } } } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project/* ww w . j a v a 2 s . c o m*/ * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static String[] internalGetProjectPath(IProject project, IClasspathAttribute attribute, boolean useResolvedPath) { if (isAspectPathAttribute(attribute)) { if (shouldCheckOldStylePath(project, ASPECTPATH)) { String[] old = getOldProjectPath(project, true); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectAspectPath(project, old[0], old[1], old[2]); }/*from www . j a va 2 s .c o m*/ markOldStylePathAsRead(project, ASPECTPATH); } } else { // INPATH_ATTRIBUTE if (shouldCheckOldStylePath(project, INPATH)) { String[] old = getOldProjectPath(project, false); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectInPath(project, old[0], old[1], old[2]); } markOldStylePathAsRead(project, INPATH); } } String pathString = ""; //$NON-NLS-1$ String contentString = ""; //$NON-NLS-1$ String entryString = ""; //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean attributeFound = false; for (int j = 0; j < attributes.length; j++) { if (attributes[j].getName().equals(attribute.getName())) { attributeFound = true; List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); if (useResolvedPath) { // this entry is on the path. must resolve it if (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); // Bug 273770 - look for the XXXPATH_RESTRICTION_ATTRIBUTE_NAME classpath attribute Set<String> extraPathElements = findContainerRestrictions(cp[i], isAspectPathAttribute(attribute)); if (extraPathElements != null && extraPathElements.size() > 0) { // must filter for (Iterator<IClasspathEntry> cpIter = containerEntries.iterator(); cpIter .hasNext();) { IClasspathEntry containerEntry = cpIter.next(); if (!containsAsPathFragment(extraPathElements, containerEntry)) { cpIter.remove(); } } } actualEntries.addAll(containerEntries); } else if (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProj = project.getWorkspace().getRoot() .getProject(cp[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(project.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(cp[i], requiredProj)); } } else { // resolve the classpath variable IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolved != null) { if (resolved.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // must resolve the project actualEntries.addAll( resolveDependentProjectClasspath(resolved, project.getWorkspace() .getRoot().getProject(resolved.getPath().toString()))); } else { actualEntries.add(resolved); } } } // cp[i].getEntryKind() } else { actualEntries.add(cp[i]); } // useResolvedEntry for (IClasspathEntry actualEntry : actualEntries) { // we can get null for actualEntry if the raw entry corresponds to // an unbound classpath variable if (actualEntry != null) { pathString += actualEntry.getPath().toPortableString() + File.pathSeparator; contentString += actualEntry.getContentKind() + File.pathSeparator; entryString += actualEntry.getEntryKind() + File.pathSeparator; } } } // attributes[j].equals(attribute) } // for (int j = 0; j < attributes.length; j++) // there is a special case that we must look inside the classpath container for entries with // attributes if we are returning the resolved path and the container itself isn't already // on the path. if (!attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); for (IClasspathEntry containerEntry : containerEntries) { if (isOnPath(containerEntry, isAspectPathAttribute(attribute))) { pathString += containerEntry.getPath().toPortableString() + File.pathSeparator; contentString += containerEntry.getContentKind() + File.pathSeparator; entryString += containerEntry.getEntryKind() + File.pathSeparator; } } // for (Iterator cpIter = containerEntries.iterator(); cpIter.hasNext(); ) } // !attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER } // for (int i = 0; i < cp.length; i++) } catch (JavaModelException e) { } return new String[] { pathString, contentString, entryString }; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static Set<String> findContainerRestrictions(IClasspathEntry containerEntry, boolean isAspectPathAttribute) { if (containerEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { return Collections.emptySet(); }// ww w .j a v a 2 s .co m Set<String> restrictionPaths = new HashSet<String>(); String restrictions = getRestriction(containerEntry, isAspectPathAttribute ? ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME : INPATH_RESTRICTION_ATTRIBUTE_NAME); if (restrictions != null) { String[] restrictionsArr = restrictions.split(","); for (int j = 0; j < restrictionsArr.length; j++) { restrictionPaths.add(restrictionsArr[j].trim()); } return restrictionPaths; } else { return null; } }