List of usage examples for org.eclipse.jdt.internal.core.util Util verbose
public static synchronized void verbose(String log, PrintStream printStream)
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.AddFolderToIndex.java
License:Open Source License
public boolean execute(IProgressMonitor progressMonitor) { if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; // if (!this.project.isAccessible()) return true; // nothing to do // IResource folder = this.project.getParent().findMember(this.folderPath); File folder = new File(folderPath.toOSString()); if (!folder.exists()) return true; // nothing to do, source folder was removed /* ensure no concurrent write access to index */ Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ true /*create if none*/); if (index == null) return true; ReadWriteMonitor monitor = index.monitor; if (monitor == null) return true; // index got deleted since acquired try {/* ww w.j a va2s .co m*/ monitor.enterRead(); // ask permission to read final IPath container = this.containerPath; final IndexManager indexManager = this.manager; final SourceElementParser parser = indexManager.getSourceElementParser(this.project, null/*requestor will be set by indexer*/); Path path = FileSystems.getDefault().getPath(folderPath.toOSString()); if (this.exclusionPatterns == null && this.inclusionPatterns == null) { Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return null; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.toFile().getName())) indexManager.addSource(file, container, parser); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return null; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return null; } }); // folder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) /* throws CoreException */{ // if (proxy.getType() == IResource.FILE) { // // return false; // } // return true; // } // }, // IResource.NONE // ); } else { Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (AddFolderToIndex.this.exclusionPatterns != null && AddFolderToIndex.this.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()), AddFolderToIndex.this.inclusionPatterns, AddFolderToIndex.this.exclusionPatterns, true)) return FileVisitResult.SKIP_SUBTREE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.getFileName().toString())) { // IResource resource = proxy.requestResource(); if (!Util.isExcluded(new org.eclipse.core.runtime.Path(file.toFile().getPath()), AddFolderToIndex.this.inclusionPatterns, AddFolderToIndex.this.exclusionPatterns, false)) indexManager.addSource(file, container, parser); } return null; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return null; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return null; } }); // folder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) /* throws CoreException */{ // switch(proxy.getType()) { // case IResource.FILE : // // return false; // case IResource.FOLDER : // // } // return true; // } // }, // IResource.NONE // ); } } catch (IOException e) { if (JobManager.VERBOSE) { Util.verbose( "-> failed to add " + this.folderPath + " to index because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } return false; } finally { monitor.exitRead(); // free read lock } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private boolean hasJavaLikeNamesChanged() { char[][] currentNames = com.codenvy.ide.ext.java.server.internal.core.search.Util.getJavaLikeExtensions(); int current = currentNames.length; char[][] prevNames = readJavaLikeNamesFile(); if (prevNames == null) { if (VERBOSE && current != 1) Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$ System.err);/* w w w. j a va 2 s. co m*/ return (current != 1); //Ignore if only java } int prev = prevNames.length; if (current != prev) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } if (current > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current); Util.sort(currentNames); } // The JavaLikeNames would have been sorted before getting stored in the file, // hence just do a direct compare. for (int i = 0; i < current; i++) { if (!CharOperation.equals(currentNames[i], prevNames[i])) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
/** * Commit all index memory changes to disk *//* w w w.j av a 2 s .c om*/ public void saveIndexes() { // only save cached indexes... the rest were not modified ArrayList toSave = new ArrayList(); synchronized (this) { Object[] valueTable = this.indexes.valueTable; for (int i = 0, l = valueTable.length; i < l; i++) { Index index = (Index) valueTable[i]; if (index != null) toSave.add(index); } } boolean allSaved = true; for (int i = 0, length = toSave.size(); i < length; i++) { Index index = (Index) toSave.get(i); ReadWriteMonitor monitor = index.monitor; if (monitor == null) continue; // index got deleted since acquired try { // take read lock before checking if index has changed // don't take write lock yet since it can cause a deadlock (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50571) monitor.enterRead(); if (index.hasChanged()) { if (monitor.exitReadEnterWrite()) { try { saveIndex(index); } catch (IOException e) { if (VERBOSE) { Util.verbose("-> got the following exception while saving:", System.err); //$NON-NLS-1$ e.printStackTrace(); } allSaved = false; } finally { monitor.exitWriteEnterRead(); } } else { allSaved = false; } } } finally { monitor.exitRead(); } } if (this.participantsContainers != null && this.participantUpdated) { writeParticipantsIndexNamesFile(); this.participantUpdated = false; } this.needToSave = !allSaved; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeJavaLikeNamesFile() { BufferedWriter writer = null; String pathName = getJavaPluginWorkingLocation().toOSString(); try {//from ww w. j av a 2 s .c o m char[][] currentNames = com.codenvy.ide.ext.java.server.internal.core.search.Util .getJavaLikeExtensions(); int length = currentNames.length; if (length > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[length][], 0, length); Util.sort(currentNames); } File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); //$NON-NLS-1$ writer = new BufferedWriter(new FileWriter(javaLikeNamesFile)); for (int i = 0; i < length - 1; i++) { writer.write(currentNames[i]); writer.write('\n'); } if (length > 0) writer.write(currentNames[length - 1]); } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write javaLikeNames file", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeIndexMapFile() { BufferedWriter writer = null; try {//from w w w . jav a 2 s . co m writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile)); writer.write(DiskIndex.SIGNATURE); writer.write('\n'); Object[] keys = this.indexStates.keyTable; Object[] states = this.indexStates.valueTable; for (int i = 0, l = states.length; i < l; i++) { IndexLocation location = (IndexLocation) keys[i]; if (location != null && states[i] == REUSE_STATE) { IPath container = (IPath) this.indexLocations.keyForValue(location); if (container != null) { writer.write(location.toString()); writer.write('\n'); writer.write(container.toOSString()); writer.write('\n'); } } } } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write saved index file names", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeParticipantsIndexNamesFile() { BufferedWriter writer = null; try {//w w w . ja v a 2 s.c o m writer = new BufferedWriter(new FileWriter(this.participantIndexNamesFile)); writer.write(DiskIndex.SIGNATURE); writer.write('\n'); Object[] indexFiles = this.participantsContainers.keyTable; Object[] containers = this.participantsContainers.valueTable; for (int i = 0, l = indexFiles.length; i < l; i++) { IndexLocation indexFile = (IndexLocation) indexFiles[i]; if (indexFile != null) { writer.write(indexFile.getIndexFile().getPath()); writer.write('\n'); writer.write(((IPath) containers[i]).toOSString()); writer.write('\n'); } } } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write participant index file names", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeSavedIndexNamesFile() { BufferedWriter writer = null; try {// w w w . j a va 2s . com writer = new BufferedWriter(new FileWriter(this.savedIndexNamesFile)); writer.write(DiskIndex.SIGNATURE); writer.write('+'); writer.write(getJavaPluginWorkingLocation().toOSString()); writer.write('\n'); Object[] keys = this.indexStates.keyTable; Object[] states = this.indexStates.valueTable; for (int i = 0, l = states.length; i < l; i++) { IndexLocation key = (IndexLocation) keys[i]; if (key != null && states[i] == SAVED_STATE) { writer.write(key.fileName()); writer.write('\n'); } } } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write saved index file names", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.RemoveFolderFromIndex.java
License:Open Source License
public boolean execute(IProgressMonitor progressMonitor) { if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; /* ensure no concurrent write access to index */ Index index = this.manager.getIndex(this.containerPath, true, /*reuse index file*/ false /*create if none*/); if (index == null) return true; ReadWriteMonitor monitor = index.monitor; if (monitor == null) return true; // index got deleted since acquired try {/*w w w.j ava 2s.c om*/ monitor.enterRead(); // ask permission to read String containerRelativePath = Util.relativePath(this.folderPath, this.containerPath.segmentCount()); String[] paths = index.queryDocumentNames(containerRelativePath); // all file names belonging to the folder or its subfolders and that are not excluded (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32607) if (paths != null) { if (this.exclusionPatterns == null && this.inclusionPatterns == null) { for (int i = 0, max = paths.length; i < max; i++) { this.manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation } } else { for (int i = 0, max = paths.length; i < max; i++) { String documentPath = this.containerPath.toString() + '/' + paths[i]; if (!Util.isExcluded(new Path(documentPath), this.inclusionPatterns, this.exclusionPatterns, false)) this.manager.remove(paths[i], this.containerPath); // write lock will be acquired by the remove operation } } } } catch (IOException e) { if (JobManager.VERBOSE) { Util.verbose("-> failed to remove " + this.folderPath //$NON-NLS-1$ + " from index because of the following exception:", System.err); //$NON-NLS-1$ e.printStackTrace(); } return false; } finally { monitor.exitRead(); // free read lock } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.SaveIndex.java
License:Open Source License
public boolean execute(IProgressMonitor progressMonitor) { if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; /* ensure no concurrent write access to index */ Index index = this.manager.getIndex(this.containerPath, true /*reuse index file*/, false /*don't create if none*/); if (index == null) return true; ReadWriteMonitor monitor = index.monitor; if (monitor == null) return true; // index got deleted since acquired try {/* w w w .j av a2s .c o m*/ monitor.enterWrite(); // ask permission to write this.manager.saveIndex(index); } catch (IOException e) { if (JobManager.VERBOSE) { Util.verbose( "-> failed to save index " + this.containerPath + " because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } return false; } finally { monitor.exitWrite(); // free write lock } return true; }
From source file:org.eclipse.che.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
private boolean hasJavaLikeNamesChanged() { char[][] currentNames = org.eclipse.che.jdt.internal.core.search.Util.getJavaLikeExtensions(); int current = currentNames.length; char[][] prevNames = readJavaLikeNamesFile(); if (prevNames == null) { if (VERBOSE && current != 1) Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$ System.err);//from w ww. j a v a2 s. c o m return (current != 1); //Ignore if only java } int prev = prevNames.length; if (current != prev) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } if (current > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current); Util.sort(currentNames); } // The JavaLikeNames would have been sorted before getting stored in the file, // hence just do a direct compare. for (int i = 0; i < current; i++) { if (!CharOperation.equals(currentNames[i], prevNames[i])) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } } return false; }