Example usage for org.eclipse.jdt.internal.core.search.processing JobManager VERBOSE

List of usage examples for org.eclipse.jdt.internal.core.search.processing JobManager VERBOSE

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.search.processing JobManager VERBOSE.

Prototype

boolean VERBOSE

To view the source code for org.eclipse.jdt.internal.core.search.processing JobManager VERBOSE.

Click Source Link

Usage

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./*from ww w  .j  a 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.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 {/*from w  ww .  j  a v a 2s  .c o m*/
        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 {//  ww w.  jav a 2  s  .  c om
        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.jdt.internal.core.JavaModelManager.java

License:Open Source License

/**
 * Configure the plugin with respect to option settings defined in ".options" file
 *///from  w w w . j av  a 2 s . c om
public void configurePluginDebugOptions() {
    if (JavaCore.getPlugin().isDebugging()) {
        String option = Platform.getDebugOption(BUFFER_MANAGER_DEBUG);
        if (option != null)
            BufferManager.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(BUILDER_DEBUG);
        if (option != null)
            JavaBuilder.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(COMPILER_DEBUG);
        if (option != null)
            Compiler.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(BUILDER_STATS_DEBUG);
        if (option != null)
            JavaBuilder.SHOW_STATS = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(COMPLETION_DEBUG);
        if (option != null)
            CompletionEngine.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(CP_RESOLVE_DEBUG);
        if (option != null)
            JavaModelManager.CP_RESOLVE_VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(CP_RESOLVE_ADVANCED_DEBUG);
        if (option != null)
            JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(CP_RESOLVE_FAILURE_DEBUG);
        if (option != null)
            JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(DELTA_DEBUG);
        if (option != null)
            DeltaProcessor.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(DELTA_DEBUG_VERBOSE);
        if (option != null)
            DeltaProcessor.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(HIERARCHY_DEBUG);
        if (option != null)
            TypeHierarchy.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(INDEX_MANAGER_DEBUG);
        if (option != null)
            JobManager.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(INDEX_MANAGER_ADVANCED_DEBUG);
        if (option != null)
            IndexManager.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(JAVAMODEL_DEBUG);
        if (option != null)
            JavaModelManager.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(JAVAMODELCACHE_DEBUG);
        if (option != null)
            JavaModelCache.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(POST_ACTION_DEBUG);
        if (option != null)
            JavaModelOperation.POST_ACTION_VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(RESOLUTION_DEBUG);
        if (option != null)
            NameLookup.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(SEARCH_DEBUG);
        if (option != null)
            BasicSearchEngine.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(SELECTION_DEBUG);
        if (option != null)
            SelectionEngine.DEBUG = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(ZIP_ACCESS_DEBUG);
        if (option != null)
            JavaModelManager.ZIP_ACCESS_VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(SOURCE_MAPPER_DEBUG_VERBOSE);
        if (option != null)
            SourceMapper.VERBOSE = option.equalsIgnoreCase(TRUE);

        option = Platform.getDebugOption(FORMATTER_DEBUG);
        if (option != null)
            DefaultCodeFormatter.DEBUG = option.equalsIgnoreCase(TRUE);
    }

    // configure performance options
    if (PerformanceStats.ENABLED) {
        CompletionEngine.PERF = PerformanceStats.isEnabled(COMPLETION_PERF);
        SelectionEngine.PERF = PerformanceStats.isEnabled(SELECTION_PERF);
        DeltaProcessor.PERF = PerformanceStats.isEnabled(DELTA_LISTENER_PERF);
        JavaModelManager.PERF_VARIABLE_INITIALIZER = PerformanceStats.isEnabled(VARIABLE_INITIALIZER_PERF);
        JavaModelManager.PERF_CONTAINER_INITIALIZER = PerformanceStats.isEnabled(CONTAINER_INITIALIZER_PERF);
        ReconcileWorkingCopyOperation.PERF = PerformanceStats.isEnabled(RECONCILE_PERF);
    }
}