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.internal.buildpath.AddToAspectpathAction.java
License:Open Source License
public void run(IAction action) { if (project == null) { return;//from ww w. ja v a 2s . c o m } if (cpEntry != null) { // add to aspect path and ensure restrictions are properly set up IClasspathEntry newEntry = cpEntry; if (shouldAskForClasspathRestrictions(cpEntry)) { String restriction = askForClasspathRestrictions(newEntry, fileName, "Aspect path"); if (restriction != null && restriction.length() > 0) { newEntry = AspectJCorePreferences.updatePathRestrictions(newEntry, restriction, AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME); } else { newEntry = AspectJCorePreferences.ensureHasAttribute(newEntry, AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME, ""); } } newEntry = AspectJCorePreferences.ensureHasAttribute(newEntry, AspectJCorePreferences.ASPECTPATH_ATTRIBUTE_NAME, AspectJCorePreferences.ASPECTPATH_ATTRIBUTE_NAME); AspectJCorePreferences.updateClasspathEntry(project, newEntry); } else { String jarPath = jarFile.getFullPath().toPortableString(); AspectJCorePreferences.addToAspectPath(project, jarPath, IClasspathEntry.CPE_LIBRARY); } AJDTUtils.refreshPackageExplorer(); }
From source file:org.eclipse.ajdt.internal.buildpath.AddToInpathAction.java
License:Open Source License
public void run(IAction action) { if (project == null) { return;/*from w ww . j a v a2 s .co m*/ } if (cpEntry != null) { // add to in path and ensure restrictions are properly set up IClasspathEntry newEntry = cpEntry; if (shouldAskForClasspathRestrictions(cpEntry)) { String restriction = askForClasspathRestrictions(newEntry, fileName, "In path"); if (restriction != null && restriction.length() > 0) { newEntry = AspectJCorePreferences.updatePathRestrictions(newEntry, restriction, AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME); } else { newEntry = AspectJCorePreferences.ensureHasAttribute(newEntry, AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME, ""); } } newEntry = AspectJCorePreferences.ensureHasAttribute(newEntry, AspectJCorePreferences.INPATH_ATTRIBUTE_NAME, AspectJCorePreferences.INPATH_ATTRIBUTE_NAME); AspectJCorePreferences.updateClasspathEntry(project, newEntry); } else { String jarPath = jarFile.getFullPath().toPortableString(); AspectJCorePreferences.addToInPath(project, jarPath, IClasspathEntry.CPE_LIBRARY); } AJDTUtils.refreshPackageExplorer(); }
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]); }/* www . j a v 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.core.builder.BuildClasspathResolver.java
License:Open Source License
private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject, SimpleLookupTable binaryLocationsPerProject) throws CoreException { /* Update cycle marker */ IMarker cycleMarker = javaProject.getCycleMarker(); if (cycleMarker != null) { int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true)) ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING; if (severity != ((Integer) cycleMarker.getAttribute(IMarker.SEVERITY)).intValue()) cycleMarker.setAttribute(IMarker.SEVERITY, severity); }/* w ww . jav a 2 s . c om*/ IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath(); ArrayList sLocations = new ArrayList(classpathEntries.length); ArrayList bLocations = new ArrayList(classpathEntries.length); nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) { ClasspathEntry entry = (ClasspathEntry) classpathEntries[i]; IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, true); if (target == null) continue nextEntry; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!(target instanceof IContainer)) continue nextEntry; IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); IContainer outputFolder; if (outputPath.segmentCount() == 1) { outputFolder = javaProject.getProject(); } else { outputFolder = root.getFolder(outputPath); // AspectJ Change Begin // This method can be executing on the wrong thread, where createFolder() will hang, so don't do it! // if (!outputFolder.exists()) // createFolder(outputFolder); // AspectJ Change End } sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder, entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars())); continue nextEntry; case IClasspathEntry.CPE_PROJECT: if (!(target instanceof IProject)) continue nextEntry; IProject prereqProject = (IProject) target; if (!JavaProject.hasJavaNature(prereqProject)) continue nextEntry; // if project doesn't have java nature or is not accessible JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject); IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath(); ArrayList seen = new ArrayList(); nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) { IClasspathEntry prereqEntry = prereqClasspathEntries[j]; if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true); if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry; IPath prereqOutputPath = prereqEntry.getOutputLocation() != null ? prereqEntry.getOutputLocation() : prereqJavaProject.getOutputLocation(); IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject : (IContainer) root.getFolder(prereqOutputPath); if (binaryFolder.exists() && !seen.contains(binaryFolder)) { seen.add(binaryFolder); ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true, entry.getAccessRuleSet()); bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(prereqProject); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(prereqProject, existingLocations); } } } } continue nextEntry; case IClasspathEntry.CPE_LIBRARY: if (target instanceof IResource) { IResource resource = (IResource) target; ClasspathLocation bLocation = null; if (resource instanceof IFile) { if (!(org.eclipse.jdt.internal.compiler.util.Util .isPotentialZipArchive(path.lastSegment()))) continue nextEntry; AccessRuleSet accessRuleSet = JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet); } else if (resource instanceof IContainer) { AccessRuleSet accessRuleSet = JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder } bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode IProject p = resource.getProject(); // can be the project being built ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(p); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(p, existingLocations); } } else if (target instanceof File) { if (!(org.eclipse.jdt.internal.compiler.util.Util.isPotentialZipArchive(path.lastSegment()))) continue nextEntry; AccessRuleSet accessRuleSet = JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) ? null : entry.getAccessRuleSet(); bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet)); } continue nextEntry; } } // now split the classpath locations... place the output folders ahead of the other .class file folders & jars ArrayList outputFolders = new ArrayList(1); this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()]; if (!sLocations.isEmpty()) { sLocations.toArray(this.sourceLocations); // collect the output folders, skipping duplicates next: for (int i = 0, l = sourceLocations.length; i < l; i++) { ClasspathMultiDirectory md = sourceLocations[i]; IPath outputPath = md.binaryFolder.getFullPath(); for (int j = 0; j < i; j++) { // compare against previously walked source folders if (outputPath.equals(sourceLocations[j].binaryFolder.getFullPath())) { md.hasIndependentOutputFolder = sourceLocations[j].hasIndependentOutputFolder; continue next; } } outputFolders.add(md); // also tag each source folder whose output folder is an independent folder & is not also a source folder for (int j = 0, m = sourceLocations.length; j < m; j++) if (outputPath.equals(sourceLocations[j].sourceFolder.getFullPath())) continue next; md.hasIndependentOutputFolder = true; } } // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()]; int index = 0; for (int i = 0, l = outputFolders.size(); i < l; i++) this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i); for (int i = 0, l = bLocations.size(); i < l; i++) this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i); }
From source file:org.eclipse.ajdt.internal.ui.AspectJProjectPropertiesPage.java
License:Open Source License
private boolean commit() { // ignore changes to .classpath that occur during commits thisProject.getWorkspace().removeResourceChangeListener(fListener); // update the output jar try {/*from w ww. ja va 2s. c o m*/ String oldOutJar = AspectJCorePreferences.getProjectOutJar(thisProject); IClasspathEntry oldEntry = null; if (oldOutJar != null && !oldOutJar.equals("")) { //$NON-NLS-1$ oldEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(IPackageFragmentRoot.K_BINARY, // content kind IClasspathEntry.CPE_LIBRARY, // entry kind new Path(thisProject.getName() + '/' + oldOutJar).makeAbsolute(), // path new IPath[] {}, // inclusion patterns new IPath[] {}, // exclusion patterns null, // src attachment path null, // src attachment root path null, // output location false, // is exported ? null, //accessRules false, //combine access rules? new IClasspathAttribute[0] // extra attributes? ); } String outJar = outputJarEditor.getStringValue(); IClasspathEntry newEntry = null; if (outJar != null && !outJar.equals("")) { //$NON-NLS-1$ newEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(IPackageFragmentRoot.K_BINARY, // content kind IClasspathEntry.CPE_LIBRARY, // entry kind new Path(thisProject.getName() + '/' + outJar).makeAbsolute(), // path new IPath[] {}, // inclusion patterns new IPath[] {}, // exclusion patterns null, // src attachment path null, // src attachment root path null, // output location false, // is exported ? null, //accessRules false, //combine access rules? new IClasspathAttribute[0] // extra attributes? ); } if (checkIfOnInpath(thisProject, outJar) || checkIfOnAspectpath(thisProject, outJar)) { MessageDialog.openInformation(getShell(), UIMessages.buildpathwarning_title, UIMessages.buildConfig_invalidOutjar); outputJarEditor.setStringValue(oldOutJar); } else { LaunchConfigurationManagementUtils.updateOutJar(JavaCore.create(thisProject), oldEntry, newEntry); AspectJCorePreferences.setProjectOutJar(thisProject, outputJarEditor.getStringValue()); } if (fInPathBlock != null && fInPathBlock.hasChangesInDialog()) { new ConfigurePathBlockJob(fInPathBlock).schedule(); getSettings().put(INDEX, fInPathBlock.getPageIndex()); // set the inpath's output folder // we should only be setting the out path if it is different // from the default // probably should do more checking on this, but hold off for now. AspectJCorePreferences.setProjectInpathOutFolder(getProject(), fInPathBlock.getOutputFolder()); } if (fAspectPathBlock != null && fAspectPathBlock.hasChangesInDialog()) { new ConfigurePathBlockJob(fAspectPathBlock).schedule(); getSettings().put(INDEX, fAspectPathBlock.getPageIndex()); } AJDTUtils.refreshPackageExplorer(); initializeTimeStamps(); return true; } finally { // now we care about resource changes again thisProject.getWorkspace().addResourceChangeListener(fListener); } }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarPackageWizardPage.java
License:Open Source License
protected boolean validateSourceGroup() { if (!(fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection() || fExportJavaFilesCheckbox.getSelection())) { setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_noExportTypeChecked); return false; }/* w w w . j av a 2 s .c om*/ if (getSelectedResources().size() == 0) { if (getErrorMessage() != null) setErrorMessage(null); return false; } if (fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection()) return true; // Source file only export - check if there are source files Iterator iter = getSelectedResourcesIterator(); while (iter.hasNext()) { Object element = iter.next(); if (element instanceof IClassFile) { IPackageFragmentRoot root = (IPackageFragmentRoot) ((IClassFile) element) .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root == null) continue; IClasspathEntry cpEntry; try { cpEntry = root.getRawClasspathEntry(); } catch (JavaModelException e) { continue; } if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { return true; } } else { return true; } } if (getErrorMessage() != null) setErrorMessage(null); return false; }
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 a v a 2 s. 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[] openExtJarFileDialog() { IPath[] selected = BuildPathDialogAccess.chooseExternalJAREntries(getShell()); if (selected != null) { ArrayList<CPListElement> res = new ArrayList<CPListElement>(); for (int i = 0; i < selected.length; i++) { res.add(new CPListElement(fCurrJProject, IClasspathEntry.CPE_LIBRARY, selected[i], null)); }/* ww w. j a v a2 s . com*/ return res.toArray(new CPListElement[res.size()]); } return null; }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
private CPListElement newCPLibraryElement(IResource res) { return new CPListElement(fCurrJProject, IClasspathEntry.CPE_LIBRARY, res.getFullPath(), res); }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
private IPath[] getUsedContainers() { ArrayList<IPath> res = new ArrayList<IPath>(); if (fCurrJProject.exists()) { try {/*from w ww .j a v a 2s . c o m*/ IPath outputLocation = fCurrJProject.getOutputLocation(); if (outputLocation != null && outputLocation.segmentCount() > 1) { // != // Project res.add(outputLocation); } } catch (JavaModelException e) { } } List cplist = fPathList.getElements(); for (int i = 0; i < cplist.size(); i++) { CPListElement elem = (CPListElement) cplist.get(i); if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource resource = elem.getResource(); if (resource instanceof IContainer) { res.add(resource.getFullPath()); } } } return res.toArray(new IPath[res.size()]); }