List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.imp.releng.actions.VersionScanner.java
License:Open Source License
/** * @return the list of source folder IPaths for the given java project *//* www. j ava2 s . c om*/ private List<IPath> collectSrcFolders(IJavaProject javaProject) { List<IPath> srcFolders = new ArrayList<IPath>(); try { IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : cpEntries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { if (!entry.getPath().equals(javaProject.getProject().getFullPath())) { srcFolders.add(entry.getPath()); } } } } } catch (CoreException e) { ReleaseEngineeringPlugin.logError(e); } return srcFolders; }
From source file:org.eclipse.imp.releng.CopyrightAdder.java
License:Open Source License
/** * @param projects/*from w w w . j a v a 2 s . c om*/ */ private void collectProjectSourceRoots(Set<IProject> projectsToModify) { IWorkspaceRoot wsRoot = fReleaseTool.fWSRoot; for (IProject project : projectsToModify) { ReleaseEngineeringPlugin.getMsgStream().println("Collecting source folders for " + project.getName()); IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { ReleaseEngineeringPlugin.getMsgStream() .println("Project " + javaProject.getElementName() + " does not exist!"); continue; } try { IClasspathEntry[] cpe = javaProject.getResolvedClasspath(true); for (int j = 0; j < cpe.length; j++) { IClasspathEntry entry = cpe[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // TODO Doesn't handle path inclusion/exclusion constraints if (entry.getPath().segmentCount() == 1) ReleaseEngineeringPlugin.getMsgStream().println("*** Ignoring source path entry " + entry.getPath().toPortableString() + " because it's at a project root."); else fSrcRoots.add(wsRoot.getFolder(entry.getPath())); } } } catch (JavaModelException e) { ReleaseEngineeringPlugin.getMsgStream() .println("Exception encountered while traversing resources:\n " + e.getMessage()); logError(e); } } }
From source file:org.eclipse.imp.smapifier.builder.SmapieBuilder.java
License:Open Source License
/** * @return the set of <code>IFiles</code> representing all of the .class files that * were generated from the given source file *//*from w w w. j a v a2 s.c o m*/ private Set<IFile> getClassFiles(IFile srcFile) { IPath parentPath = srcFile.getParent().getFullPath(); Set<IFile> ret = new HashSet<IFile>(); try { IClasspathEntry[] entries = fJavaProject.getResolvedClasspath(true); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE && entries[i].getPath().isPrefixOf(srcFile.getFullPath()) && !BuildPathUtils.isExcluded(srcFile.getFullPath(), entries[i])) { IPath out = entries[i].getOutputLocation(); if (out == null) // using default output folder out = fJavaProject.getOutputLocation().removeFirstSegments(1); IPath parentSrcPath = parentPath.removeFirstSegments(entries[i].getPath().segmentCount()); IPath parentFullPath = out.append(parentSrcPath); final IResource parent = fProject.findMember(parentFullPath); // RMF 8/4/2006 - If the SMAP builder ran before the Java builder // (e.g. due to a misconfigured project), the output folder might // have been cleaned out, and sub-folders (corresponding to packages) // won't exist, so parent could be null. if (parent == null) continue; IResource[] members = ((IContainer) parent).members(); for (int j = 0; j < members.length; j++) { String name = members[j].getName(); if (members[j] instanceof IFile && classBelongsTo(srcFile, name)) { ret.add((IFile) members[j]); } } } } } catch (JavaModelException e) { SMAPifierPlugin.getInstance().logException(e.getMessage(), e); } catch (CoreException e) { SMAPifierPlugin.getInstance().logException(e.getMessage(), e); } return ret; }
From source file:org.eclipse.imp.smapifier.builder.SmapieBuilder.java
License:Open Source License
/** * @param origSrcFile the workspace-relative path to a source file in the top-level * language (from which Java source is generated) * @return the OS-specific-format filesystem-absolute path to the "main" corresponding .java file *//*from w w w . j a v a2 s . c o m*/ private String getMainGeneratedFile(final IFile origSrcFile) { IWorkspaceRoot wsRoot = fProject.getWorkspace().getRoot(); final IPath wsRelativeFilePath = origSrcFile.getFullPath(); // First, try the same folder as the original src file -- the .java file might live there final IPath javaSrcPath = wsRelativeFilePath.removeFileExtension().addFileExtension("java"); final IFileStore fileStore = EFS.getLocalFileSystem() .getStore(wsRoot.getFile(javaSrcPath).getLocationURI()); if (fileStore.fetchInfo().exists()) { return javaSrcPath.toOSString(); } final IPath wsLocation = wsRoot.getRawLocation(); final IPath projRelJavaFilePath = wsRelativeFilePath.removeFirstSegments(1).removeFileExtension() .addFileExtension("java").makeAbsolute(); try { for (final IClasspathEntry cpEntry : fJavaProject.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpEntry.getPath().isPrefixOf(origSrcFile.getFullPath()) && !BuildPathUtils.isExcluded(origSrcFile.getFullPath(), cpEntry)) { // Skip if this source entry isn't the entry containing 'origSrcFile'. final IPath srcPath = cpEntry.getPath(); if (!srcPath.isPrefixOf(wsRelativeFilePath)) { continue; } // Now look in the output locations - the one for this classpath entry, if any, // or, failing that, the project's output location. final IPath outputLocation; if (cpEntry.getOutputLocation() == null) { outputLocation = fJavaProject.getOutputLocation(); } else { outputLocation = cpEntry.getOutputLocation(); } final int srcPathCount = srcPath.removeFirstSegments(1).segmentCount(); // discounting the project name final IPath generatedFilePath = wsLocation .append(outputLocation.append(projRelJavaFilePath.removeFirstSegments(srcPathCount))); final String generatedFilePathStr = generatedFilePath.toOSString(); if (new File(generatedFilePathStr).exists()) { return generatedFilePath.toOSString(); } } } } catch (CoreException e) { SMAPifierPlugin.getInstance().logException(e.getMessage(), e); } return null; }
From source file:org.eclipse.imp.smapifier.builder.SmapieBuilder.java
License:Open Source License
protected boolean isBinaryFolder(IResource resource) { try {/* ww w .ja v a2s . co m*/ // RMF The following commented-out version is incorrect for projects // whose source and output folders are the project root folder. // IPath bin = JavaCore.create(fProject).getOutputLocation(); // return resource.getFullPath().equals(bin); // // RMF The right check is: resource path is one of the project's output folders. // Not sure the following is quite right... // // Caching would be a really good idea here: save the set of project // output folders in a Set. Seems Path implements equals() properly. IPath projPath = fProject.getFullPath(); boolean projectIsSrcBin = fJavaProject.getOutputLocation().matchingFirstSegments(projPath) == projPath .segmentCount(); if (projectIsSrcBin) return false; final IPath resourcePath = resource.getFullPath(); if (resourcePath.equals(fJavaProject.getOutputLocation())) return true; IClasspathEntry[] cp = fJavaProject.getResolvedClasspath(true); for (int i = 0; i < cp.length; i++) { if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (resourcePath.equals(cp[i].getOutputLocation())) return true; } } } catch (JavaModelException e) { SMAPifierPlugin.getInstance().logException(e.getMessage(), e); } return false; }
From source file:org.eclipse.imp.smapifier.builder.SmapieBuilder.java
License:Open Source License
private List<IPath> getProjectSrcPath() throws JavaModelException { List<IPath> srcPath = new ArrayList<IPath>(); IClasspathEntry[] classPath = fJavaProject.getResolvedClasspath(true); for (int i = 0; i < classPath.length; i++) { IClasspathEntry e = classPath[i]; if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) srcPath.add(e.getPath());/* w ww . j a va 2s .c o m*/ } if (srcPath.size() == 0) srcPath.add(fProject.getLocation()); return srcPath; }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
/** * Returns whether the given full path (for a package) conflicts with the output location * of the given project.// w ww .ja v a 2s . c o m */ public static boolean conflictsWithOutputLocation(IPath folderPath, JavaProject project) { try { IPath outputLocation = project.getOutputLocation(); if (outputLocation == null) { // in doubt, there is a conflict return true; } if (outputLocation.isPrefixOf(folderPath)) { // only allow nesting in project's output if there is a corresponding source folder // or if the project's output is not used (in other words, if all source folders have their custom output) IClasspathEntry[] classpath = project.getResolvedClasspath(); boolean isOutputUsed = false; for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath().equals(outputLocation)) { return false; } if (entry.getOutputLocation() == null) { isOutputUsed = true; } } } return isOutputUsed; } return false; } catch (JavaModelException e) { // in doubt, there is a conflict return true; } }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
/** * Returns the package fragment roots identified by the given entry. In case it refers to * a project, it will follow its classpath so as to find exported roots as well. * Only works with resolved entry/*from w w w .j a v a 2 s . c o m*/ * @param resolvedEntry IClasspathEntry * @param accumulatedRoots ObjectVector * @param rootIDs HashSet * @param referringEntry the CP entry (project) referring to this entry, or null if initial project * @param retrieveExportedRoots boolean * @throws JavaModelException */ public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException { String rootID = ((ClasspathEntry) resolvedEntry).rootID(); if (rootIDs.contains(rootID)) return; IPath projectPath = this.project.getFullPath(); IPath entryPath = resolvedEntry.getPath(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IPackageFragmentRoot root = null; switch (resolvedEntry.getEntryKind()) { // source folder case IClasspathEntry.CPE_SOURCE: if (projectPath.isPrefixOf(entryPath)) { Object target = JavaModel.getTarget(entryPath, true/*check existency*/); if (target == null) return; if (target instanceof IFolder || target instanceof IProject) { root = getPackageFragmentRoot((IResource) target); } } break; // internal/external JAR or folder case IClasspathEntry.CPE_LIBRARY: if (referringEntry != null && !resolvedEntry.isExported()) return; Object target = JavaModel.getTarget(entryPath, true/*check existency*/); if (target == null) return; if (target instanceof IResource) { // internal target root = getPackageFragmentRoot((IResource) target, entryPath); } else if (target instanceof File) { // external target if (JavaModel.isFile(target)) { root = new JarPackageFragmentRoot(entryPath, this); } else if (((File) target).isDirectory()) { root = new ExternalPackageFragmentRoot(entryPath, this); } } break; // recurse into required project case IClasspathEntry.CPE_PROJECT: if (!retrieveExportedRoots) return; if (referringEntry != null && !resolvedEntry.isExported()) return; IResource member = workspaceRoot.findMember(entryPath); if (member != null && member.getType() == IResource.PROJECT) {// double check if bound to project (23977) IProject requiredProjectRsc = (IProject) member; if (JavaProject.hasJavaNature(requiredProjectRsc)) { // special builder binary output rootIDs.add(rootID); JavaProject requiredProject = (JavaProject) JavaCore.create(requiredProjectRsc); requiredProject.computePackageFragmentRoots(requiredProject.getResolvedClasspath(), accumulatedRoots, rootIDs, rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map retrieveExportedRoots, rootToResolvedEntries); } break; } } if (root != null) { accumulatedRoots.add(root); rootIDs.add(rootID); if (rootToResolvedEntries != null) rootToResolvedEntries.put(root, ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry)); } }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
public boolean contains(IResource resource) { IClasspathEntry[] classpath;// ww w. j av a2 s .c o m IPath output; try { classpath = getResolvedClasspath(); output = getOutputLocation(); } catch (JavaModelException e) { return false; } IPath fullPath = resource.getFullPath(); IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null; IClasspathEntry innerMostEntry = null; ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager(); for (int j = 0, cpLength = classpath.length; j < cpLength; j++) { IClasspathEntry entry = classpath[j]; IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource linkedFolder = foldersManager.getFolder(entryPath); if (linkedFolder != null) entryPath = linkedFolder.getFullPath(); } if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath)) && entryPath.isPrefixOf(fullPath)) { innerMostEntry = entry; } IPath entryOutput = classpath[j].getOutputLocation(); if (entryOutput != null && entryOutput.isPrefixOf(fullPath)) { innerMostOutput = entryOutput; } } if (innerMostEntry != null) { // special case prj==src and nested output location if (innerMostOutput != null && innerMostOutput.segmentCount() > 1 // output isn't project && innerMostEntry.getPath().segmentCount() == 1) { // 1 segment must be project name return false; } if (resource instanceof IFolder) { // folders are always included in src/lib entries return true; } switch (innerMostEntry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: // .class files are not visible in source folders return !org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(fullPath.lastSegment()); case IClasspathEntry.CPE_LIBRARY: // .java files are not visible in library folders return !org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(fullPath.lastSegment()); } } if (innerMostOutput != null) { return false; } return true; }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
/** * Answers true if the project potentially contains any source. A project which has no source is immutable. * @return boolean//from w ww . j a va2 s . c o m */ public boolean hasSource() { // look if any source folder on the classpath // no need for resolved path given source folder cannot be abstracted IClasspathEntry[] entries; try { entries = getRawClasspath(); } catch (JavaModelException e) { return true; // unsure } for (int i = 0, max = entries.length; i < max; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { return true; } } return false; }