List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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; }/*from ww w. j a v a2s . c o m*/ } } return false; }
From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest2.java
License:Open Source License
private boolean projectHasProjectDependency(IJavaProject proj, IProject projectDependedOn) throws JavaModelException { IClasspathEntry[] entries = proj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (entry.getPath().equals(projectDependedOn.getFullPath()) || entry.getPath().equals(projectDependedOn.getFullPath().makeAbsolute())) { return true; }/*from w w w .j a v a 2s.c om*/ } } return false; }
From source file:org.eclipse.ajdt.core.tests.builder.Bug99133Test.java
License:Open Source License
private void removeProjectDependency(IProject project, IProject projectDependedOn) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); List newEntries = new ArrayList(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (!entry.getPath().equals(projectDependedOn.getFullPath()) && !entry.getPath().equals(projectDependedOn.getFullPath().makeAbsolute())) { newEntries.add(entry);/*from w w w .j a v a2s. c o m*/ } } else { newEntries.add(entry); } } IClasspathEntry[] newCP = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(newCP, null); }
From source file:org.eclipse.ajdt.internal.buildpath.AJBuildPathAction.java
License:Open Source License
protected boolean shouldAskForClasspathRestrictions(IClasspathEntry entry) { return entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER; }
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 w w . j a va 2 s . com } 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); }/*from w w w. java 2s . co m*/ 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.launching.LaunchConfigurationManagementUtils.java
License:Open Source License
/** * Update the aspect path for launch configurations relating to the given * project/*from ww w . j a va 2s . c o m*/ * * @param project - * the project * @param existingAspectPathEntries - * current aspect path * @param newAspectPathEntries - * new aspect path */ public static void updateAspectPaths(IJavaProject project, List existingAspectPathEntries, List newAspectPathEntries) { try { String projectName = project.getElementName(); List configs = getLaunchConfigsForProject(projectName); for (Iterator iter = configs.iterator(); iter.hasNext();) { ILaunchConfiguration configuration = (ILaunchConfiguration) iter.next(); IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); List entriesAsList = new ArrayList(Arrays.asList(entries)); for (Iterator iterator = existingAspectPathEntries.iterator(); iterator.hasNext();) { IClasspathEntry entryToRemove = ((CPListElement) iterator.next()).getClasspathEntry(); for (Iterator iterator2 = entriesAsList.iterator(); iterator2.hasNext();) { IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) iterator2.next(); if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { if (entryToRemove.equals(entry.getClasspathEntry())) { iterator2.remove(); break; } } } } for (Iterator iterator = newAspectPathEntries.iterator(); iterator.hasNext();) { IClasspathEntry newEntry = ((CPListElement) iterator.next()).getClasspathEntry(); if (newEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { entriesAsList.add(new RuntimeClasspathEntry(newEntry)); } else { IClasspathContainer container = JavaCore.getClasspathContainer(newEntry.getPath(), project); if (container != null) { IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int i = 0; i < containerEntries.length; i++) { entriesAsList.add(new RuntimeClasspathEntry(containerEntries[i])); } } } } IRuntimeClasspathEntry[] updatedEntries = (IRuntimeClasspathEntry[]) entriesAsList .toArray(new IRuntimeClasspathEntry[0]); updateConfigurationClasspath(configuration, updatedEntries); } } catch (CoreException cEx) { AJLog.log(cEx.getMessage()); } }
From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java
License:Open Source License
private IResource tryToFindResource(String fileName, IProject project) { IResource ret = null;/*www . j a v a 2 s . c om*/ String toFind = fileName.replace('\\', '/'); IJavaProject jProject = JavaCore.create(project); try { IClasspathEntry[] classpathEntries = jProject.getResolvedClasspath(false); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry cpEntry = classpathEntries[i]; if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = cpEntry.getPath(); // remove the first segment because the findMember call // following always adds it back in under the covers (doh!) // and we end up with two first segments otherwise! sourcePath = sourcePath.removeFirstSegments(1); IResource memberResource = project.findMember(sourcePath); if (memberResource != null) { IResource[] srcContainer = new IResource[] { memberResource }; ret = findFile(srcContainer, toFind); } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projPath = cpEntry.getPath(); IResource projResource = AspectJPlugin.getWorkspace().getRoot().findMember(projPath); if (projResource != null) { ret = findFile(new IResource[] { projResource }, toFind); } } if (ret != null) { break; } } } catch (JavaModelException jmEx) { AJDTErrorHandler.handleAJDTError(UIMessages.jmCoreException, jmEx); } if (ret == null) ret = project; return ret; }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
private IContainer[] getOutputContainers(IJavaProject javaProject) throws CoreException { Set<IPath> outputPaths = new HashSet<IPath>(); boolean includeDefaultOutputPath = false; IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i] != null) { IClasspathEntry cpEntry = roots[i].getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = cpEntry.getOutputLocation(); if (location != null) outputPaths.add(location); else includeDefaultOutputPath = true; }/* ww w .j av a2 s.c o m*/ } } if (includeDefaultOutputPath) { // Use default output location outputPaths.add(javaProject.getOutputLocation()); } // Convert paths to containers Set<IContainer> outputContainers = new HashSet<IContainer>(outputPaths.size()); Iterator<IPath> iter = outputPaths.iterator(); while (iter.hasNext()) { IPath path = iter.next(); if (javaProject.getProject().getFullPath().equals(path)) outputContainers.add(javaProject.getProject()); else { IFolder outputFolder = createFolderHandle(path); if (outputFolder == null || !outputFolder.isAccessible()) { String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible; addToStatus(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null))); } else outputContainers.add(outputFolder); } } return outputContainers.toArray(new IContainer[outputContainers.size()]); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
/** * Returns an iterator on a list with files that correspond to the * passed file and that are on the classpath of its project. * * @param file the file for which to find the corresponding classpath resources * @param pathInJar the path that the file has in the JAR (i.e. project and source folder segments removed) * @param javaProject the javaProject that contains the file * @param pkgRoot the package fragment root that contains the file * @return the iterator over the corresponding classpath files for the given file *///from w w w . j av a2 s . c om protected Iterator<IFile> filesOnClasspath(IFile file, IPath pathInJar, IJavaProject javaProject, IPackageFragmentRoot pkgRoot, IProgressMonitor progressMonitor) throws CoreException { // Allow JAR Package to provide its own strategy IFile[] classFiles = fJarPackage.findClassfilesFor(file); if (classFiles != null) return Arrays.asList(classFiles).iterator(); if (!isJavaFile(file)) return Collections.<IFile>emptyList().iterator(); IPath outputPath = null; if (pkgRoot != null) { IClasspathEntry cpEntry = pkgRoot.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) outputPath = cpEntry.getOutputLocation(); } if (outputPath == null) // Use default output location outputPath = javaProject.getOutputLocation(); IContainer outputContainer; if (javaProject.getProject().getFullPath().equals(outputPath)) outputContainer = javaProject.getProject(); else { outputContainer = createFolderHandle(outputPath); if (outputContainer == null || !outputContainer.isAccessible()) { String msg = JarPackagerMessages.JarFileExportOperation_outputContainerNotAccessible; throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null)); } } // Java CU - search files with .class ending boolean hasErrors = hasCompileErrors(file); boolean hasWarnings = hasCompileWarnings(file); boolean canBeExported = canBeExported(hasErrors, hasWarnings); if (!canBeExported) return Collections.<IFile>emptyList().iterator(); reportPossibleCompileProblems(file, hasErrors, hasWarnings, canBeExported); IContainer classContainer = outputContainer; if (pathInJar.segmentCount() > 1) classContainer = outputContainer.getFolder(pathInJar.removeLastSegments(1)); if (fExportedClassContainers.contains(classContainer)) return Collections.<IFile>emptyList().iterator(); if (fClassFilesMapContainer == null || !fClassFilesMapContainer.equals(classContainer)) { fJavaNameToClassFilesMap = buildJavaToClassMap(classContainer); if (fJavaNameToClassFilesMap == null) { // Could not fully build map. fallback is to export whole directory IPath location = classContainer.getLocation(); String containerName = ""; //$NON-NLS-1$ if (location != null) containerName = location.toFile().toString(); String msg = Messages.format( JarPackagerMessages.JarFileExportOperation_missingSourceFileAttributeExportedAll, containerName); addInfo(msg, null); fExportedClassContainers.add(classContainer); return getClassesIn(classContainer); } fClassFilesMapContainer = classContainer; } ArrayList classFileList = (ArrayList) fJavaNameToClassFilesMap.get(file.getName()); if (classFileList == null || classFileList.isEmpty()) { String msg = Messages.format( JarPackagerMessages.JarFileExportOperation_classFileOnClasspathNotAccessible, file.getFullPath()); throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, msg, null)); } return classFileList.iterator(); }