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:com.cisco.yangide.core.indexing.DeltaProcessor.java
License:Open Source License
private OutputsInfo outputsInfo(IResource res) { try {/* w w w . j a v a 2 s.co m*/ JavaProject proj = (JavaProject) JavaCore.create(res.getProject()); if (proj != null) { IPath projectOutput = proj.getOutputLocation(); int traverseMode = IGNORE; if (proj.getProject().getFullPath().equals(projectOutput)) { // case of // proj==bin==src return new OutputsInfo(new IPath[] { projectOutput }, new int[] { SOURCE }, 1); } IClasspathEntry[] classpath = proj.getResolvedClasspath(); IPath[] outputs = new IPath[classpath.length + 1]; int[] traverseModes = new int[classpath.length + 1]; int outputCount = 1; outputs[0] = projectOutput; traverseModes[0] = traverseMode; for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; IPath entryPath = entry.getPath(); IPath output = entry.getOutputLocation(); if (output != null) { outputs[outputCount] = output; // check case of src==bin if (entryPath.equals(output)) { traverseModes[outputCount++] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY; } else { traverseModes[outputCount++] = IGNORE; } } // check case of src==bin if (entryPath.equals(projectOutput)) { traverseModes[0] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY; } } return new OutputsInfo(outputs, traverseModes, outputCount); } } catch (JavaModelException e) { // java project doesn't exist: ignore } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form. *//*w w w .jav a 2 s .c o m*/ static int kindFromString(String kindStr) { if (kindStr.equalsIgnoreCase("prj")) //$NON-NLS-1$ return IClasspathEntry.CPE_PROJECT; if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ return IClasspathEntry.CPE_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ return IClasspathEntry.CPE_LIBRARY; if (kindStr.equalsIgnoreCase("output")) //$NON-NLS-1$ return ClasspathEntry.K_OUTPUT; return -1; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a <code>String</code> for the kind of a class path entry. */// w w w. j av a 2 s .c o m static String kindToString(int kind) { switch (kind) { case IClasspathEntry.CPE_PROJECT: return "src"; // backward compatibility //$NON-NLS-1$ case IClasspathEntry.CPE_SOURCE: return "src"; //$NON-NLS-1$ case IClasspathEntry.CPE_LIBRARY: return "lib"; //$NON-NLS-1$ case IClasspathEntry.CPE_VARIABLE: return "var"; //$NON-NLS-1$ case IClasspathEntry.CPE_CONTAINER: return "con"; //$NON-NLS-1$ case ClasspathEntry.K_OUTPUT: return "output"; //$NON-NLS-1$ default: return "unknown"; //$NON-NLS-1$ } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a printable representation of this classpath entry. *//*from ww w . ja va2 s. co m*/ public String toString() { StringBuffer buffer = new StringBuffer(); Object target = JavaModel.getTarget(getPath(), true); if (target instanceof File) buffer.append(getPath().toOSString()); else buffer.append(String.valueOf(getPath())); buffer.append('['); switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: buffer.append("CPE_LIBRARY"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: buffer.append("CPE_PROJECT"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: buffer.append("CPE_SOURCE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: buffer.append("CPE_VARIABLE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: buffer.append("CPE_CONTAINER"); //$NON-NLS-1$ break; } buffer.append("]["); //$NON-NLS-1$ switch (getContentKind()) { case IPackageFragmentRoot.K_BINARY: buffer.append("K_BINARY"); //$NON-NLS-1$ break; case IPackageFragmentRoot.K_SOURCE: buffer.append("K_SOURCE"); //$NON-NLS-1$ break; case ClasspathEntry.K_OUTPUT: buffer.append("K_OUTPUT"); //$NON-NLS-1$ break; } buffer.append(']'); if (getSourceAttachmentPath() != null) { buffer.append("[sourcePath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentPath()); buffer.append(']'); } if (getSourceAttachmentRootPath() != null) { buffer.append("[rootPath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentRootPath()); buffer.append(']'); } buffer.append("[isExported:"); //$NON-NLS-1$ buffer.append(this.isExported); buffer.append(']'); IPath[] patterns = this.inclusionPatterns; int length; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[including:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } patterns = this.exclusionPatterns; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[excluding:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } if (this.accessRuleSet != null) { buffer.append('['); buffer.append(this.accessRuleSet.toString(false/*on one line*/)); buffer.append(']'); } if (this.entryKind == CPE_PROJECT) { buffer.append("[combine access rules:"); //$NON-NLS-1$ buffer.append(this.combineAccessRules); buffer.append(']'); } if (getOutputLocation() != null) { buffer.append("[output:"); //$NON-NLS-1$ buffer.append(getOutputLocation()); buffer.append(']'); } if ((length = this.extraAttributes == null ? 0 : this.extraAttributes.length) > 0) { buffer.append("[attributes:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(this.extraAttributes[i]); if (i != length - 1) { buffer.append(','); } } buffer.append(']'); } return buffer.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Answers an ID which is used to distinguish entries during package * fragment root computations//w ww . j ava 2 s. c om */ public String rootID() { if (this.rootID == null) { switch (this.entryKind) { case IClasspathEntry.CPE_LIBRARY: this.rootID = "[LIB]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: this.rootID = "[PRJ]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: this.rootID = "[SRC]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: this.rootID = "[VAR]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: this.rootID = "[CON]" + this.path; //$NON-NLS-1$ break; default: this.rootID = ""; //$NON-NLS-1$ break; } } return this.rootID; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
public boolean ignoreOptionalProblems() { if (this.entryKind == IClasspathEntry.CPE_SOURCE) { for (int i = 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attrib = this.extraAttributes[i]; if (IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS.equals(attrib.getName())) { return "true".equals(attrib.getValue()); //$NON-NLS-1$ }//from www . j a va2 s . c o m } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java
License:Open Source License
private void updateIndex(Openable element, IResourceDelta delta) { IndexManager indexManager = this.manager.indexManager; if (indexManager == null) return;//from ww w. j a va 2 s. co m switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: switch (delta.getKind()) { case IResourceDelta.ADDED: indexManager.indexAll((JavaProject) element.getJavaProject()); break; case IResourceDelta.REMOVED: indexManager.removeIndexFamily(element.getJavaProject().getProject().getFullPath()); // NB: Discarding index jobs belonging to this project was done during PRE_DELETE break; // NB: Update of index if project is opened, closed, or its java nature is added or removed // is done in updateCurrentDeltaAndIndex } break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (element instanceof JarPackageFragmentRoot) { JarPackageFragmentRoot root = (JarPackageFragmentRoot) element; // index jar file only once (if the root is in its declaring project) IPath jarPath = root.getPath(); switch (delta.getKind()) { case IResourceDelta.ADDED: // index the new jar indexManager.indexLibrary(jarPath, root.getIndexPath()); break; case IResourceDelta.CHANGED: // first remove the index so that it is forced to be re-indexed indexManager.removeIndex(jarPath); // then index the jar indexManager.indexLibrary(jarPath, root.getIndexPath()); break; case IResourceDelta.REMOVED: // the jar was physically removed: remove the index indexManager.discardJobs(jarPath.toString()); indexManager.removeIndex(jarPath); break; } break; } int kind = delta.getKind(); if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED || (kind == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.LOCAL_CHANGED) != 0)) { PackageFragmentRoot root = (PackageFragmentRoot) element; updateRootIndex(root, CharOperation.NO_STRINGS, delta); break; } // don't break as packages of the package fragment root can be indexed below // $FALL-THROUGH$ case IJavaElement.PACKAGE_FRAGMENT: switch (delta.getKind()) { case IResourceDelta.CHANGED: if ((delta.getFlags() & IResourceDelta.LOCAL_CHANGED) == 0) break; // $FALL-THROUGH$ case IResourceDelta.ADDED: case IResourceDelta.REMOVED: IPackageFragment pkg = null; if (element instanceof IPackageFragmentRoot) { PackageFragmentRoot root = (PackageFragmentRoot) element; pkg = root.getPackageFragment(CharOperation.NO_STRINGS); } else { pkg = (IPackageFragment) element; } RootInfo rootInfo = rootInfo(pkg.getParent().getPath(), delta.getKind()); boolean isSource = rootInfo == null // if null, defaults to source || rootInfo.entryKind == IClasspathEntry.CPE_SOURCE; IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren(); for (int i = 0, length = children.length; i < length; i++) { IResourceDelta child = children[i]; IResource resource = child.getResource(); // TODO (philippe) Why do this? Every child is added anyway as the delta is walked if (resource instanceof IFile) { String name = resource.getName(); if (isSource) { if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) { Openable cu = (Openable) pkg.getCompilationUnit(name); updateIndex(cu, child); } } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) { Openable classFile = (Openable) pkg.getClassFile(name); updateIndex(classFile, child); } } } break; } break; case IJavaElement.CLASS_FILE: // IFile file = (IFile) delta.getResource(); // IJavaProject project = element.getJavaProject(); // PackageFragmentRoot root = element.getPackageFragmentRoot(); // IPath binaryFolderPath = root.isExternal() && !root.isArchive() ? root.resource().getFullPath() : root.getPath(); // // if the class file is part of the binary output, it has been created by // // the java builder -> ignore // try { // if (binaryFolderPath.equals(project.getOutputLocation())) { // break; // } // } catch (JavaModelException e) { // // project doesn't exist: ignore // } // switch (delta.getKind()) { // case IResourceDelta.CHANGED : // // no need to index if the content has not changed // int flags = delta.getFlags(); // if ((flags & IResourceDelta.CONTENT) == 0 && (flags & IResourceDelta.ENCODING) == 0) // break; // // $FALL-THROUGH$ // case IResourceDelta.ADDED : // indexManager.addBinary(file, binaryFolderPath); // break; // case IResourceDelta.REMOVED : // String containerRelativePath = Util.relativePath(file.getFullPath(), binaryFolderPath.segmentCount()); // indexManager.remove(containerRelativePath, binaryFolderPath); // break; // } break; case IJavaElement.COMPILATION_UNIT: File file = delta.getFile(); switch (delta.getKind()) { case IResourceDelta.CHANGED: // no need to index if the content has not changed int flags = delta.getFlags(); if ((flags & IResourceDelta.CONTENT) == 0 && (flags & IResourceDelta.ENCODING) == 0) break; // $FALL-THROUGH$ case IResourceDelta.ADDED: indexManager.addSource(file.toPath(), element.getJavaProject().getPath(), getSourceElementParser(element)); // Clean file from secondary types cache but do not update indexing secondary type cache as it will be updated through indexing itself this.manager.secondaryTypesRemoving(file, false); break; case IResourceDelta.REMOVED: indexManager.remove( file.getPath().substring(element.getJavaProject().getPath().toOSString().length()), element.getJavaProject().getPath()); // Clean file from secondary types cache and update indexing secondary type cache as indexing cannot remove secondary types from cache this.manager.secondaryTypesRemoving(file, true); break; } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexAllProject.java
License:Open Source License
/** * Ensure consistency of a project index. Need to walk all nested resources, * and discover resources which have either been changed, added or deleted * since the index was produced./* ww w.ja v a 2 s . c o m*/ */ public boolean execute(IProgressMonitor progressMonitor) { if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; // if (!this.project.isAccessible()) return true; // nothing to do ReadWriteMonitor monitor = null; try { // Get source folder entries. Libraries are done as a separate job // JavaProject javaProject = (JavaProject)JavaCore.create(this.project); // Do not create marker while getting raw classpath (see bug 41859) IClasspathEntry[] entries = project.getRawClasspath(); int length = entries.length; IClasspathEntry[] sourceEntries = new IClasspathEntry[length]; int sourceEntriesNumber = 0; for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) sourceEntries[sourceEntriesNumber++] = entry; } if (sourceEntriesNumber == 0) { IPath projectPath = project.getPath(); for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) { // the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815) // ensure a job exists to index it as a binary folder this.manager.indexLibrary(projectPath, /*this.project,*/ ((ClasspathEntry) entry).getLibraryIndexLocation()); return true; } } // nothing to index but want to save an empty index file so its not 'rebuilt' when part of a search request Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); if (index != null) this.manager.saveIndex(index); return true; } if (sourceEntriesNumber != length) System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber); Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); if (index == null) return true; monitor = index.monitor; if (monitor == null) return true; // index got deleted since acquired monitor.enterRead(); // ask permission to read String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ int max = paths == null ? 0 : paths.length; final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11); final String OK = "OK"; //$NON-NLS-1$ final String DELETED = "DELETED"; //$NON-NLS-1$ if (paths != null) { for (int i = 0; i < max; i++) indexedFileNames.put(paths[i], DELETED); } final long indexLastModified = max == 0 ? 0L : index.getIndexLastModified(); // IWorkspaceRoot root = this.project.getWorkspace().getRoot(); for (int i = 0; i < sourceEntriesNumber; i++) { if (this.isCancelled) return false; IClasspathEntry entry = sourceEntries[i]; // IResource sourceFolder = root.findMember(entry.getPath()); Path sourceFolder = FileSystems.getDefault().getPath(entry.getPath().toOSString()); if (sourceFolder != null) { // collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041) final HashSet outputs = new HashSet(); //TODO // if (sourceFolder.getType() == IResource.PROJECT) { // // Do not create marker while getting output location (see bug 41859) // outputs.add(javaProject.getOutputLocation()); // for (int j = 0; j < sourceEntriesNumber; j++) { // IPath output = sourceEntries[j].getOutputLocation(); // if (output != null) { // outputs.add(output); // } // } // } final boolean hasOutputs = !outputs.isEmpty(); final char[][] inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars(); final char[][] exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars(); if (max == 0) { Files.walkFileTree(sourceFolder, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (exclusionPatterns != null && inclusionPatterns == null) { // if there are inclusion patterns then we must walk the children if (Util.isExcluded(new org.eclipse.core.runtime.Path(dir.toFile().getPath()), inclusionPatterns, exclusionPatterns, true)) return FileVisitResult.SKIP_SUBTREE; } if (hasOutputs && outputs.contains(dir.toAbsolutePath())) return FileVisitResult.SKIP_SUBTREE; return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.getFileName().toString())) { // IFile file = (IFile) proxy.requestResource(); org.eclipse.core.runtime.Path resourcePath = new org.eclipse.core.runtime.Path( file.toFile().getPath()); if (exclusionPatterns != null || inclusionPatterns != null) { if (Util.isExcluded(resourcePath, inclusionPatterns, exclusionPatterns, false)) return FileVisitResult.CONTINUE; } indexedFileNames.put(resourcePath.makeRelativeTo(containerPath).toOSString(), file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); // sourceFolder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) { // if (IndexAllProject.this.isCancelled) return false; // switch(proxy.getType()) { // case IResource.FILE : // // case IResource.FOLDER : // // } // return true; // } // }, // IResource.NONE // ); } else { Files.walkFileTree(sourceFolder, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (exclusionPatterns != null || inclusionPatterns != null) if (Util.isExcluded(new org.eclipse.core.runtime.Path(dir.toFile().getPath()), inclusionPatterns, exclusionPatterns, true)) return FileVisitResult.SKIP_SUBTREE; if (hasOutputs && outputs.contains(dir.toAbsolutePath())) return FileVisitResult.SKIP_SUBTREE; return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.getFileName().toString())) { // IFile file = (IFile) proxy.requestResource(); URI location = file.toUri(); if (location == null) return FileVisitResult.CONTINUE; if (exclusionPatterns != null || inclusionPatterns != null) if (Util.isExcluded( new org.eclipse.core.runtime.Path(file.toFile().getPath()), inclusionPatterns, exclusionPatterns, false)) return FileVisitResult.CONTINUE; String relativePathString = new org.eclipse.core.runtime.Path( file.toFile().getPath()).makeRelativeTo(containerPath).toOSString(); //Util.relativePath(new org.eclipse.core.runtime.Path(file.toFile().getPath()), 1/*remove project segment*/); indexedFileNames.put(relativePathString, indexedFileNames .get(relativePathString) == null || indexLastModified < 0 /*EFS.getStore(location).fetchInfo().getLastModified()*/ ? (Object) file : (Object) OK); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); // sourceFolder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) throws CoreException { // if (IndexAllProject.this.isCancelled) return false; // switch(proxy.getType()) { // case IResource.FILE : // if (Util.isJavaLikeFileName(proxy.getName())) { // IFile file = (IFile) proxy.requestResource(); // URI location = file.getLocationURI(); // if (location == null) return false; // if (exclusionPatterns != null || inclusionPatterns != null) // if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns)) // return false; // String relativePathString = Util // .relativePath(file.getFullPath(), 1/*remove project segment*/); // indexedFileNames.put(relativePathString, // indexedFileNames.get(relativePathString) == null // || indexLastModified < 0 /*EFS.getStore(location).fetchInfo().getLastModified()*/ // ? (Object) file // : (Object) OK); // } // return false; // case IResource.FOLDER : // if (exclusionPatterns != null || inclusionPatterns != null) // if (Util.isExcluded(proxy.requestResource(), inclusionPatterns, exclusionPatterns)) // return false; // if (hasOutputs && outputs.contains(proxy.requestFullPath())) // return false; // } // return true; // } // }, // IResource.NONE // ); } } } SourceElementParser parser = this.manager.getSourceElementParser(project, null/*requestor will be set by indexer*/); Object[] names = indexedFileNames.keyTable; Object[] values = indexedFileNames.valueTable; for (int i = 0, namesLength = names.length; i < namesLength; i++) { String name = (String) names[i]; if (name != null) { if (this.isCancelled) return false; Object value = values[i]; if (value != OK) { if (value == DELETED) this.manager.remove(name, this.containerPath); else this.manager.addSource((Path) value, this.containerPath, parser); } } } // request to save index when all cus have been indexed... also sets state to SAVED_STATE this.manager.request(new SaveIndex(this.containerPath, this.manager)); } catch (CoreException e) { if (JobManager.VERBOSE) { Util.verbose("-> failed to index " + this.project + " because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } this.manager.removeIndex(this.containerPath); return false; } catch (IOException e) { if (JobManager.VERBOSE) { Util.verbose("-> failed to index " + this.project + " because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } this.manager.removeIndex(this.containerPath); return false; } finally { if (monitor != null) monitor.exitRead(); // free read lock } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add a path to current java search scope or all project fragment roots if null. * Use project resolved classpath to retrieve and store access restriction on each classpath entry. * Recurse if dependent projects are found. * * @param javaProject/*from www . j a v a2s .co m*/ * Project used to get resolved classpath entries * @param pathToAdd * Path to add in case of single element or null if user want to add all project package fragment roots * @param includeMask * Mask to apply on classpath entries * @param projectsToBeAdded * Set to avoid infinite recursion * @param visitedProjects * Set to avoid adding twice the same project * @param referringEntry * Project raw entry in referring project classpath * @throws org.eclipse.jdt.core.JavaModelException * May happen while getting java model info */ void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { // IProject project = javaProject.getProject(); // if (!project.isAccessible() || !visitedProjects.add(project)) return; IPath projectPath = javaProject.getFullPath(); String projectPathString = projectPath.toString(); addEnclosingProjectOrJar(projectPath); IClasspathEntry[] entries = javaProject.getResolvedClasspath(); // IJavaModel model = javaProject.getJavaModel(); // JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; AccessRuleSet access = null; ClasspathEntry cpEntry = (ClasspathEntry) entry; if (referringEntry != null) { // Add only exported entries. // Source folder are implicitly exported. if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry); // cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry); } access = cpEntry.getAccessRuleSet(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IClasspathEntry rawEntry = null; // Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries; // if (rootPathToRawEntries != null) { // rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath()); // } // if (rawEntry == null) break; rawKind: switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: if ((includeMask & APPLICATION_LIBRARIES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { // Object target = JavaModel.getTarget(path, false/*don't check existence*/); // if (target instanceof IFolder) // case of an external folder // path = ((IFolder)target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject); if (container == null) break; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind; break; case IClasspathContainer.K_SYSTEM: case IClasspathContainer.K_DEFAULT_SYSTEM: if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind; break; default: break rawKind; } IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } break; } break; case IClasspathEntry.CPE_PROJECT: // if ((includeMask & REFERENCED_PROJECTS) != 0) { // IPath path = entry.getPath(); // if (pathToAdd == null || pathToAdd.equals(path)) { // JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment()); // if (!projectsToBeAdded // .contains(referencedProject)) { // do not recurse if depending project was used to create the scope // add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry); // } // } // } break; case IClasspathEntry.CPE_SOURCE: if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { add(projectPath.toString(), Util.relativePath(path, 1/*remove project segment*/), projectPathString, false/*not a package*/, access); } } break; } } }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Makes an Eclipse project a Java project. * <p>//from w w w . j a v a2 s.c o m * If the project does not exist, or is not accessible, then nothing is done.<br /> * If the project does not have the Java nature, this nature is added. * </p> * <p> * The default output directory is "bin". If this directory does not exist, it is created. * If the creation fails, then no output directory is set. * </p> * <p> * The default source directory is "src/main/java". If this directory does not exist, it is created. * If the creation fails, then no source directory is set. * </p> * * @param project the project to transform into a Java project * @return the created Java project * @throws CoreException if something went wrong */ public static IJavaProject createJavaProject(IProject project) throws CoreException { IJavaProject jp = null; if (project.isAccessible()) { // Add the Java nature? if (!project.hasNature(JavaCore.NATURE_ID)) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } // Set the default class path jp = JavaCore.create(project); IProgressMonitor monitor = new NullProgressMonitor(); // // Output location IPath ppath = project.getFullPath(); IPath binPath = ppath.append(PetalsConstants.LOC_BIN_FOLDER); File binFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(binPath).toFile(); if (binFile.exists() && binFile.isDirectory() || !binFile.exists() && binFile.mkdirs()) { jp.setOutputLocation(binPath, monitor); } Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); entries.addAll(Arrays.asList(jp.getRawClasspath())); entries.add(JavaRuntime.getDefaultJREContainerEntry()); // // Remove the "src" entry IClasspathEntry srcEntry = null; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcEntry = entry; break; } } // // Specify a new source entry if (srcEntry != null) entries.remove(srcEntry); String[] srcPaths = new String[] { PetalsConstants.LOC_SRC_FOLDER, PetalsConstants.LOC_JAVA_RES_FOLDER }; for (String s : srcPaths) { IPath srcPath = ppath.append(s); File srcFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(srcPath).toFile(); if (srcFile.exists() && srcFile.isDirectory() || !srcFile.exists() && srcFile.mkdirs()) { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); srcEntry = JavaCore.newSourceEntry(srcPath); entries.add(srcEntry); } else { PetalsCommonPlugin.log("Could not set '" + s + "' as a source folder.", IStatus.ERROR); } } jp.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); } return jp; }