Search in sources :

Example 1 with FileIndexFacade

use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.

the class SvnCheckoutProvider method doImport.

public static void doImport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean includeIgnored, final String message) {
    final Ref<String> errorMessage = new Ref<>();
    final SvnVcs vcs = SvnVcs.getInstance(project);
    final String targetPath = FileUtil.toSystemIndependentName(target.getAbsolutePath());
    ExclusiveBackgroundVcsAction.run(project, () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(project, FileIndexFacade.class);
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        try {
            progressIndicator.setText(message("progress.text.import", target.getAbsolutePath()));
            final VirtualFile targetVf = SvnUtil.getVirtualFile(targetPath);
            if (targetVf == null) {
                errorMessage.set("Can not find file: " + targetPath);
            } else {
                final boolean isInContent = getApplication().runReadAction((Computable<Boolean>) () -> facade.isInContent(targetVf));
                CommitEventHandler handler = new IdeaCommitHandler(progressIndicator);
                boolean useFileFilter = !project.isDefault() && isInContent;
                ISVNCommitHandler commitHandler = useFileFilter ? new MyFilter(LocalFileSystem.getInstance(), new SvnExcludingIgnoredOperation.Filter(project)) : null;
                long revision = vcs.getFactoryFromSettings().createImportClient().doImport(target, url, depth, message, includeIgnored, handler, commitHandler);
                if (revision > 0) {
                    StatusBar.Info.set(message("status.text.comitted.revision", revision), project);
                }
            }
        } catch (VcsException e) {
            errorMessage.set(e.getMessage());
        }
    }, message("message.title.import"), true, project));
    if (!errorMessage.isNull()) {
        showErrorDialog(message("message.text.cannot.import", errorMessage.get()), message("message.title.import"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaCommitHandler(org.jetbrains.idea.svn.checkin.IdeaCommitHandler) ISVNCommitHandler(org.tmatesoft.svn.core.wc.ISVNCommitHandler) CommitEventHandler(org.jetbrains.idea.svn.checkin.CommitEventHandler) SvnVcs(org.jetbrains.idea.svn.SvnVcs) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnExcludingIgnoredOperation(org.jetbrains.idea.svn.actions.SvnExcludingIgnoredOperation) VcsException(com.intellij.openapi.vcs.VcsException) Computable(com.intellij.openapi.util.Computable) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 2 with FileIndexFacade

use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.

the class PsiElementFinderImpl method getClassNames.

@NotNull
@Override
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
    Set<String> names = null;
    FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
    for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
        for (PsiFile file : dir.getFiles()) {
            if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
                VirtualFile vFile = file.getVirtualFile();
                if (vFile != null && !(file instanceof PsiCompiledElement) && !facade.isInSourceContent(vFile) && (!scope.isForceSearchingInLibrarySources() || !StubTreeLoader.getInstance().canHaveStub(vFile))) {
                    continue;
                }
                Set<String> inFile = file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx) file).getClassNames() : getClassNames(((PsiClassOwner) file).getClasses());
                if (inFile.isEmpty())
                    continue;
                if (names == null)
                    names = new HashSet<>();
                names.addAll(inFile);
            }
        }
    }
    return names == null ? Collections.<String>emptySet() : names;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FileIndexFacade

use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.

the class SingleRootFileViewProvider method createFile.

private PsiFile createFile() {
    try {
        final VirtualFile vFile = getVirtualFile();
        if (vFile.isDirectory())
            return null;
        if (isIgnored())
            return null;
        final Project project = myManager.getProject();
        if (isPhysical() && vFile.isInLocalFileSystem()) {
            // check directories consistency
            final VirtualFile parent = vFile.getParent();
            if (parent == null)
                return null;
            final PsiDirectory psiDir = getManager().findDirectory(parent);
            if (psiDir == null) {
                FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
                if (!indexFacade.isInLibrarySource(vFile) && !indexFacade.isInLibraryClasses(vFile)) {
                    return null;
                }
            }
        }
        return createFile(project, vFile, myFileType);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Project(com.intellij.openapi.project.Project) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 with FileIndexFacade

use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.

the class MappingsToRoots method getRootsUnderVcs.

@NotNull
public VirtualFile[] getRootsUnderVcs(@NotNull AbstractVcs vcs) {
    List<VirtualFile> result = myMappings.getMappingsAsFilesUnderVcs(vcs);
    final AbstractVcs.RootsConvertor convertor = vcs.getCustomConvertor();
    if (convertor != null) {
        result = convertor.convertRoots(result);
    }
    Collections.sort(result, FilePathComparator.getInstance());
    if (!vcs.allowsNestedRoots()) {
        final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
        final List<VirtualFile> finalResult = result;
        ApplicationManager.getApplication().runReadAction(() -> {
            int i = 1;
            while (i < finalResult.size()) {
                final VirtualFile previous = finalResult.get(i - 1);
                final VirtualFile current = finalResult.get(i);
                if (facade.isValidAncestor(previous, current)) {
                    finalResult.remove(i);
                } else {
                    i++;
                }
            }
        });
    }
    result.removeIf(file -> !file.isDirectory());
    return VfsUtilCore.toVirtualFileArray(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FileIndexFacade

use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.

the class IndexCacheManagerImpl method collectVirtualFilesWithWord.

// IMPORTANT!!!
// Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
// we cannot call it inside FileBasedIndex.processValues() method except in collecting form
// If we do, deadlocks are possible (IDEADEV-42137). Process the files without not holding indices' read lock.
private boolean collectVirtualFilesWithWord(@NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively, @NotNull final Processor<VirtualFile> fileProcessor) {
    if (myProject.isDefault()) {
        return true;
    }
    try {
        return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

            @Override
            public Boolean compute() {
                return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {

                    final FileIndexFacade index = FileIndexFacade.getInstance(myProject);

                    @Override
                    public boolean process(final VirtualFile file, final Integer value) {
                        ProgressIndicatorProvider.checkCanceled();
                        final int mask = value.intValue();
                        if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
                            if (!fileProcessor.process(file))
                                return false;
                        }
                        return true;
                    }
                }, scope);
            }
        });
    } catch (IndexNotReadyException e) {
        throw new ProcessCanceledException();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

FileIndexFacade (com.intellij.openapi.roots.FileIndexFacade)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 ItemPresentation (com.intellij.navigation.ItemPresentation)1 Attachment (com.intellij.openapi.diagnostic.Attachment)1 Document (com.intellij.openapi.editor.Document)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 Computable (com.intellij.openapi.util.Computable)1 Ref (com.intellij.openapi.util.Ref)1 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)1 VcsDirectoryMapping (com.intellij.openapi.vcs.VcsDirectoryMapping)1