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.core.AspectJCorePreferences.java
License:Open Source License
private static void addAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {// ww w . jav a 2s .co m IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attr; switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static void removeAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {// www. ja va 2 s . com IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attr.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Remove all occurrences of an attribute * @param javaProject/*from w ww.j a v a 2s . co m*/ * @param attribute */ private static void removeAttribute(IJavaProject javaProject, IClasspathAttribute attribute) { try { IClasspathEntry[] cp = javaProject.getRawClasspath(); boolean changed = false; for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean found = false; for (int j = 0; !found && (j < attributes.length); j++) { if (attributes[j].getName().equals(attribute.getName())) { found = true; } } if (found) { changed = true; IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attribute.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } if (changed) { javaProject.setRawClasspath(cp, null); } } catch (JavaModelException e) { } }
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 {//ww w . ja va 2s . c o 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; }//ww w . j a v a 2s . c om return new Integer(entry).toString(); }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * returns a list of fully qualified names of entries on the classpath * that have been rebuilt since last build * @return/* w w w. j ava 2 s. co m*/ */ private List /*String*/ getChangedRequiredProjects(long lastBuildTimestamp) { try { // first find all the projects that have changed since last build IProject[] projectsOnClasspath = getRequiredProjects(getProject(), true); List /*IProject*/ changedProjects = new ArrayList(); for (int i = 0; i < projectsOnClasspath.length; i++) { IProject project = projectsOnClasspath[i]; // get timestamp of last build for this project long otherTimestamp = -1; if (AspectJPlugin.isAJProject(project)) { AjCompiler compiler = AspectJPlugin.getDefault().getCompilerFactory() .getCompilerForProject(project); otherTimestamp = getLastBuildTimeStamp(compiler); } else if (project.hasNature(JavaCore.NATURE_ID)) { Object s = JavaModelManager.getJavaModelManager().getLastBuiltState(project, null); if (s != null && s instanceof State) { State state = (State) s; // need to use reflection to get at the last build time otherTimestamp = getLastBuildTime(state); } } else { otherTimestamp = -1; } if (lastBuildTimestamp <= otherTimestamp) { changedProjects.add(project); } } List /*String*/ changedEntries = new ArrayList(); Set /*String*/ noDups = new HashSet(); // used to ensure there are no dups // now that we have all the projects, need to find out what they contribute to // this project's path. could be itself, a jar, or a class folder if (changedProjects.size() > 0) { IClasspathEntry[] thisClasspath = JavaCore.create(getProject()).getResolvedClasspath(true); for (Iterator projIter = changedProjects.iterator(); projIter.hasNext();) { IProject changedProject = (IProject) projIter.next(); for (int i = 0; i < thisClasspath.length; i++) { IClasspathEntry classpathEntry = thisClasspath[i]; switch (classpathEntry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: if (changedProject.getFullPath().equals(classpathEntry.getPath())) { // resolve project and add all entries List toAdd = listOfClassPathEntriesToListOfString(AspectJCorePreferences .resolveDependentProjectClasspath(classpathEntry, changedProject)); for (Iterator pathIter = toAdd.iterator(); pathIter.hasNext();) { String pathStr = (String) pathIter.next(); if (!noDups.contains(pathStr)) { changedEntries.add(pathStr); noDups.add(pathStr); } } } break; case IClasspathEntry.CPE_LIBRARY: if (changedProject.getFullPath().isPrefixOf(classpathEntry.getPath())) { // only add if this path exists IWorkspaceRoot root = getProject().getWorkspace().getRoot(); IFile onPath = root.getFile(classpathEntry.getPath()); if (onPath.exists() || root.getFolder(onPath.getFullPath()).exists()) { // may be a folder String pathStr = onPath.getLocation().toPortableString(); if (!noDups.contains(pathStr)) { changedEntries.add(pathStr); noDups.add(pathStr); } } } } } } } // if all else went well, also add the inpath to the list of changed projects. // Adding the inpath always is just a conservative estimate of what has changed. // // For Java projects, we only know the last structural build time. Usually this is // fine, but if the Java project is on the inpath, then we care about the last // build of any kind, which we can't be sure of. // (Actually, we need to know this for Aspect path projects, but aspectj can give us // precise time of the last build. // // So, as a conservative estimate, put all inpath entries onto the list. Set inPathFiles = CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()) .getInpath(); if (inPathFiles != null) { for (Iterator fileIter = inPathFiles.iterator(); fileIter.hasNext();) { File inpathFile = (File) fileIter.next(); Path path = new Path(inpathFile.getAbsolutePath()); String pathStr = path.toPortableString(); if (!noDups.contains(pathStr)) { changedEntries.add(pathStr); noDups.add(pathStr); } } } return changedEntries; } catch (Exception e) { // something went wrong. // return null to imply everything's changed AspectJPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, AspectJPlugin.PLUGIN_ID, "Error determining list of entries on classpath that have changed.", e)); return null; } }
From source file:org.eclipse.ajdt.core.builder.AJBuilder.java
License:Open Source License
/** * This is taken straight from the JavaBuilder - and is what is returned * from the build method/*from ww w . j a v a 2 s . c o m*/ */ private IProject[] getRequiredProjects(IProject project, boolean includeBinaryPrerequisites) { JavaProject javaProject = (JavaProject) JavaCore.create(project); IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); if (javaProject == null || workspaceRoot == null) return new IProject[0]; ArrayList<IProject> projects = new ArrayList<IProject>(); try { IClasspathEntry[] entries = javaProject.getExpandedClasspath(); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: // missing projects are considered too p = workspaceRoot.getProject(path.lastSegment()); break; case IClasspathEntry.CPE_LIBRARY: if (includeBinaryPrerequisites && path.segmentCount() > 1) { // some binary resources on the class path can come from // projects that are not included in the project // references IResource resource = workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) p = (IProject) resource; } } if (p != null && !projects.contains(p)) projects.add(p); } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.eclipse.ajdt.core.CoreUtils.java
License:Open Source License
/** * Get all projects within the workspace who have a dependency on the given * project - this can either be a class folder dependency or on a library * which the project exports./*from w w w . j ava 2 s . com*/ * * @param IProject * project * @return List of two IProject[] where the first is all the class folder * depending projects, and the second is all the exported library * dependent projects */ public static List<IProject[]> getDependingProjects(IProject project) { List<IProject[]> projects = new ArrayList<IProject[]>(); IProject[] projectsInWorkspace = AspectJPlugin.getWorkspace().getRoot().getProjects(); List<IPath> outputLocationPaths = getOutputLocationPaths(project); IClasspathEntry[] exportedEntries = getExportedEntries(project); List<IProject> classFolderDependingProjects = new ArrayList<IProject>(); List<IProject> exportedLibraryDependingProjects = new ArrayList<IProject>(); workThroughProjects: for (int i = 0; i < projectsInWorkspace.length; i++) { if (projectsInWorkspace[i].equals(project) || !(projectsInWorkspace[i].isOpen())) continue workThroughProjects; try { if (projectsInWorkspace[i].hasNature(JavaCore.NATURE_ID)) { JavaProject javaProject = (JavaProject) JavaCore.create(projectsInWorkspace[i]); if (javaProject == null) continue workThroughProjects; try { IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { for (Iterator<IPath> iter = outputLocationPaths.iterator(); iter.hasNext();) { IPath path = iter.next(); if (entry.getPath().equals(path)) { classFolderDependingProjects.add(projectsInWorkspace[i]); continue workThroughProjects; } } for (int k = 0; k < exportedEntries.length; k++) { if (entry.getPath().equals(exportedEntries[k].getPath())) { exportedLibraryDependingProjects.add(projectsInWorkspace[i]); } } } } } catch (JavaModelException e) { continue workThroughProjects; } } } catch (CoreException e) { } } projects.add(0, classFolderDependingProjects.toArray(new IProject[] {})); projects.add(1, exportedLibraryDependingProjects.toArray(new IProject[] {})); return projects; }
From source file:org.eclipse.ajdt.core.CoreUtils.java
License:Open Source License
private static IClasspathEntry[] getExportedEntries(IProject project) { List<IClasspathEntry> exportedEntries = new ArrayList<IClasspathEntry>(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return new IClasspathEntry[0]; }/*from w ww . j ava 2 s . c o 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) { IClasspathEntry nonExportedEntry = JavaCore.newLibraryEntry(entry.getPath(), null, null); exportedEntries.add(nonExportedEntry); } } } } catch (JavaModelException e) { } return (IClasspathEntry[]) exportedEntries.toArray(new IClasspathEntry[exportedEntries.size()]); }
From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest2.java
License:Open Source License
private boolean projectHasLibraryOnClasspath(IJavaProject proj, String libName) throws JavaModelException { IClasspathEntry[] entries = proj.getRawClasspath(); IPath libPath = proj.getProject().getLocation().append(libName); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (entry.getPath().equals(libPath) || entry.getPath().equals(libPath.makeAbsolute())) { return true; }/* www.ja va2 s . co m*/ } } return false; }