List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.eclipse.ajdt.internal.ui.AspectJProjectPropertiesPage.java
License:Open Source License
private IClasspathEntry[] getInitialPathValue(IProject project, IClasspathAttribute attribute) throws CoreException { List newPath = new ArrayList(); IJavaProject jProject = JavaCore.create(project); boolean isAspectPath = AspectJCorePreferences.isAspectPathAttribute(attribute); try {//from ww w. j a v a2 s . c o m IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (AspectJCorePreferences.isOnPath(entries[i], isAspectPath)) { newPath.add(entries[i]); } } } catch (JavaModelException e) { } // Bug 243356 // also get entries that are contained in containers // where the containers *don't* have the path attribute // but the element does. // this requires looking inside the containers. newPath.addAll(getEntriesInContainers(project, attribute)); if (newPath.size() > 0) { return (IClasspathEntry[]) newPath.toArray(new IClasspathEntry[0]); } else { return null; } }
From source file:org.eclipse.ajdt.internal.ui.AspectJProjectPropertiesPage.java
License:Open Source License
protected List /*CPListElement*/ getEntriesInContainers(IProject project, IClasspathAttribute attribute) { try {/*from w w w .j a va2 s . com*/ IJavaProject jProject = JavaCore.create(project); // get the raw classpath of the project IClasspathEntry[] allEntries = jProject.getRawClasspath(); List entriesWithAttribute = new ArrayList(); for (int i = 0; i < allEntries.length; i++) { // for each container element, peek inside it if (allEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(allEntries[i].getPath(), jProject); if (container != null && !(container instanceof JREContainer)) { IClasspathEntry[] containerEntries = container.getClasspathEntries(); // bug 273770 // Set /*String*/ extraPathElements = AspectJCorePreferences.findExtraPathElements(allEntries[i], // AspectJCorePreferences.isAspectPathAttribute(attribute)); for (int j = 0; j < containerEntries.length; j++) { // iterate through each element and add // to the path those that have the appropriate attribute if (hasClasspathAttribute(containerEntries[j], attribute) /*|| AspectJCorePreferences.containsAsPathFragment(extraPathElements, containerEntries[j])*/) { addContainerToAttribute(containerEntries[j], attribute, container); entriesWithAttribute.add(containerEntries[j]); } } } } } return entriesWithAttribute; } catch (JavaModelException e) { } return Collections.EMPTY_LIST; }
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 ww w .j a v a2 s . co m * * 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.utils.AJDTUtils.java
License:Open Source License
/** * Bug 98911: Delete any .aj files from the output folder, if the output * folder and the source folder are not the same. *//*from w w w . j ava 2s . c o m*/ private static void checkOutputFoldersForAJFiles(IProject project) throws CoreException { IJavaProject jp = JavaCore.create(project); if (jp == null) { return; } IPath defaultOutputLocation = jp.getOutputLocation(); if (defaultOutputLocation.equals(project.getFullPath())) { return; } boolean defaultOutputLocationIsSrcFolder = false; List<IPath> extraOutputLocations = new ArrayList<IPath>(); List<IClasspathEntry> srcFolders = new ArrayList<IClasspathEntry>(); IClasspathEntry[] cpe = jp.getRawClasspath(); for (int i = 0; i < cpe.length; i++) { if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcFolders.add(cpe[i]); IPath output = cpe[i].getOutputLocation(); if (output != null) { extraOutputLocations.add(output); } } } for (IClasspathEntry entry : srcFolders) { IPath path = entry.getPath(); if (path.equals(defaultOutputLocation)) { defaultOutputLocationIsSrcFolder = true; } for (Iterator<IPath> iterator = extraOutputLocations.iterator(); iterator.hasNext();) { IPath outputPath = iterator.next(); if (outputPath.equals(path)) { iterator.remove(); } } } boolean ajFilesFound = false; if (!defaultOutputLocationIsSrcFolder) { IFolder folder = project.getWorkspace().getRoot().getFolder(defaultOutputLocation); ajFilesFound = containsAJFiles(folder); } if (!ajFilesFound && extraOutputLocations.size() > 0) { for (IPath outputPath : extraOutputLocations) { IFolder folder = project.getWorkspace().getRoot().getFolder(outputPath); ajFilesFound = ajFilesFound || containsAJFiles(folder); } } if (ajFilesFound) { IWorkbenchWindow window = AspectJUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); boolean remove = MessageDialog.openQuestion(window.getShell(), UIMessages.AJFiles_title, UIMessages.AJFiles_message); if (remove) { if (!defaultOutputLocationIsSrcFolder) { AJBuilder.cleanAJFilesFromOutputFolder(defaultOutputLocation); } for (IPath extraLocationPath : extraOutputLocations) { AJBuilder.cleanAJFilesFromOutputFolder(extraLocationPath); } } } }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void includeAJfiles(IProject project, boolean prompt) { IJavaProject jp = JavaCore.create(project); try {/* w w w . j a va2 s. c om*/ boolean changed = false; IClasspathEntry[] cpEntry = jp.getRawClasspath(); for (int i = 0; i < cpEntry.length; i++) { IClasspathEntry entry = cpEntry[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath[] exc = entry.getExclusionPatterns(); if (exc != null) { List<IPath> removeList = new ArrayList<IPath>(); for (int j = 0; j < exc.length; j++) { String ext = exc[j].getFileExtension(); if ((ext != null) && ext.equals("aj")) { //$NON-NLS-1$ removeList.add(exc[j]); } } if (removeList.size() > 0) { IPath[] exc2 = new IPath[exc.length - removeList.size()]; int ind = 0; for (int j = 0; j < exc.length; j++) { if (!removeList.contains(exc[j])) { exc2[ind++] = exc[j]; } } IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc2); cpEntry[i] = classpathEntry; changed = true; } } } } if (changed) { boolean restore = true; if (prompt) { IWorkbenchWindow window = AspectJUIPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); restore = MessageDialog.openQuestion(window.getShell(), UIMessages.ExcludedAJ_title, UIMessages.ExcludedAJ_message); } if (restore) { jp.setRawClasspath(cpEntry, null); } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void excludeAJfiles(IProject project) { IJavaProject jp = JavaCore.create(project); try {//from ww w. j ava 2s. c o m boolean changed = false; IClasspathEntry[] cpEntry = jp.getRawClasspath(); for (int i = 0; i < cpEntry.length; i++) { IClasspathEntry entry = cpEntry[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { List<IPath> excludeList = new ArrayList<IPath>(); IPackageFragmentRoot[] roots = jp.findPackageFragmentRoots(entry); for (int j = 0; j < roots.length; j++) { IJavaElement[] rootFragments; try { rootFragments = roots[j].getChildren(); for (int k = 0; k < rootFragments.length; k++) { if (rootFragments[k] instanceof IPackageFragment) { IPackageFragment pack = (IPackageFragment) rootFragments[k]; ICompilationUnit[] files = pack.getCompilationUnits(); for (int l = 0; l < files.length; l++) { IResource resource = files[l].getResource(); if (resource.getFileExtension().equals("aj")) { //$NON-NLS-1$ IPath resPath = resource.getFullPath(); int seg = resPath.matchingFirstSegments(roots[j].getPath()); excludeList.add(resPath.removeFirstSegments(seg)); } } } } } catch (JavaModelException e) { } } if (excludeList.size() > 0) { IPath[] exc = new IPath[excludeList.size()]; excludeList.toArray(exc); IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc); cpEntry[i] = classpathEntry; changed = true; } } } if (changed) { jp.setRawClasspath(cpEntry, null); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
/** * @param current//from ww w . jav a2 s.c om */ public static void verifyAjrtVersion(IProject current) { IJavaProject javaProject = JavaCore.create(current); String ajrtPath = CoreUtils.getAspectjrtClasspath(); try { IClasspathEntry[] originalCP = javaProject.getRawClasspath(); ArrayList<IClasspathEntry> tempCP = new ArrayList<IClasspathEntry>(); boolean changed = false; // Go through each current classpath entry one at a time. If it is a // reference to aspectjrt.jar // replace it - I could look through each reference to check if it // is now invalid - but I don't ... for (int i = 0; i < originalCP.length; i++) { IPath path = originalCP[i].getPath(); if (path.toOSString().endsWith("aspectjrt.jar")) { //$NON-NLS-1$ IClasspathEntry ajrtCP = JavaCore.newLibraryEntry(new Path(ajrtPath), // library location null, // no source null // no source ); tempCP.add(ajrtCP); changed = true; AJLog.log("In project " //$NON-NLS-1$ + current.getName() + " - replacing " //$NON-NLS-1$ + originalCP[i].getPath() + " with " //$NON-NLS-1$ + ajrtCP.getPath()); } else { tempCP.add(originalCP[i]); } } // Set the classpath with only those elements that survived the // above filtration process. if (changed) { IClasspathEntry[] newCP = (IClasspathEntry[]) tempCP.toArray(new IClasspathEntry[tempCP.size()]); javaProject.setRawClasspath(newCP, new NullProgressMonitor()); } } catch (JavaModelException e) { // Thrown if attempted to add a duplicate classpath entry. } }
From source file:org.eclipse.ajdt.ui.AspectJUIPlugin.java
License:Open Source License
/** * Attempt to update the project's build classpath with the AspectJ runtime * library.//www . jav a 2 s. c om * * @param project */ public static void addAjrtToBuildPath(IProject project) { IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] originalCP = javaProject.getRawClasspath(); IPath ajrtPath = new Path(AspectJPlugin.ASPECTJRT_CONTAINER); boolean found = false; for (int i = 0; i < originalCP.length; i++) { if (originalCP[i].getPath().equals(ajrtPath)) { found = true; break; } } if (!found) { IClasspathEntry ajrtLIB = JavaCore.newContainerEntry(ajrtPath, false); // Update the raw classpath with the new ajrtCP entry. int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = ajrtLIB; javaProject.setRawClasspath(newCP, new NullProgressMonitor()); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.ui.AspectJUIPlugin.java
License:Open Source License
/** * Attempt to update the project's build classpath by removing any occurance * of the AspectJ runtime library.//w w w . ja v a 2 s.c o m * * @param project */ public static void removeAjrtFromBuildPath(IProject project) { IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] originalCP = javaProject.getRawClasspath(); ArrayList tempCP = new ArrayList(); // Go through each current classpath entry one at a time. If it // is not a reference to the aspectjrt.jar then do not add it // to the collection of new classpath entries. for (int i = 0; i < originalCP.length; i++) { IPath path = originalCP[i].getPath(); boolean keep = true; if (path.toOSString().endsWith("ASPECTJRT_LIB") //$NON-NLS-1$ || path.toOSString().endsWith("aspectjrt.jar")) { //$NON-NLS-1$ keep = false; } if (originalCP[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (path.segment(0).equals(AspectJPlugin.ASPECTJRT_CONTAINER)) { keep = false; } } if (keep) { tempCP.add(originalCP[i]); } } // end for // Set the classpath with only those elements that survived the // above filtration process. if (originalCP.length != tempCP.size()) { IClasspathEntry[] newCP = (IClasspathEntry[]) tempCP.toArray(new IClasspathEntry[tempCP.size()]); javaProject.setRawClasspath(newCP, new NullProgressMonitor()); } // end if at least one classpath element removed } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.ui.tests.actions.RemoveAJNatureActionTest.java
License:Open Source License
public static boolean hasAjrtOnBuildPath(IProject project) throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] originalCP = javaProject.getRawClasspath(); // Go through each current classpath entry one at a time. If it // is not a reference to the aspectjrt.jar then do not add it // to the collection of new classpath entries. for (int i = 0; i < originalCP.length; i++) { IPath path = originalCP[i].getPath(); if (path.toOSString().endsWith("ASPECTJRT_LIB") //$NON-NLS-1$ || path.toOSString().endsWith("aspectjrt.jar")) { //$NON-NLS-1$ return true; }/* w w w .j a v a 2 s .co m*/ if (originalCP[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (path.segment(0).equals(AspectJPlugin.ASPECTJRT_CONTAINER)) { return true; } } } // end for return false; }