Search in sources :

Example 11 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class NewMappings method removeRedundantMappings.

// todo area for optimization
private void removeRedundantMappings() {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    final AllVcsesI allVcses = AllVcses.getInstance(myProject);
    for (Iterator<String> iterator = myVcsToPaths.keySet().iterator(); iterator.hasNext(); ) {
        final String vcsName = iterator.next();
        final Collection<VcsDirectoryMapping> mappings = myVcsToPaths.get(vcsName);
        final List<Pair<VirtualFile, VcsDirectoryMapping>> objects = ObjectsConvertor.convert(mappings, new Convertor<VcsDirectoryMapping, Pair<VirtualFile, VcsDirectoryMapping>>() {

            public Pair<VirtualFile, VcsDirectoryMapping> convert(final VcsDirectoryMapping dm) {
                VirtualFile vf = lfs.findFileByPath(dm.getDirectory());
                if (vf == null) {
                    vf = lfs.refreshAndFindFileByPath(dm.getDirectory());
                }
                return vf == null ? null : Pair.create(vf, dm);
            }
        }, ObjectsConvertor.NOT_NULL);
        final List<Pair<VirtualFile, VcsDirectoryMapping>> filteredFiles;
        // todo static
        final Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile> fileConvertor = new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VirtualFile>() {

            public VirtualFile convert(Pair<VirtualFile, VcsDirectoryMapping> o) {
                return o.getFirst();
            }
        };
        if (StringUtil.isEmptyOrSpaces(vcsName)) {
            filteredFiles = AbstractVcs.filterUniqueRootsDefault(objects, fileConvertor);
        } else {
            final AbstractVcs<?> vcs = allVcses.getByName(vcsName);
            if (vcs == null) {
                VcsBalloonProblemNotifier.showOverChangesView(myProject, "VCS plugin not found for mapping to : '" + vcsName + "'", MessageType.ERROR);
                continue;
            }
            filteredFiles = vcs.filterUniqueRoots(objects, fileConvertor);
        }
        final List<VcsDirectoryMapping> filteredMappings = ObjectsConvertor.convert(filteredFiles, new Convertor<Pair<VirtualFile, VcsDirectoryMapping>, VcsDirectoryMapping>() {

            public VcsDirectoryMapping convert(final Pair<VirtualFile, VcsDirectoryMapping> o) {
                return o.getSecond();
            }
        });
        // to calculate what had been removed
        mappings.removeAll(filteredMappings);
        if (filteredMappings.isEmpty()) {
            iterator.remove();
        } else {
            mappings.clear();
            mappings.addAll(filteredMappings);
        }
    }
    sortedMappingsByMap();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Convertor(com.intellij.util.containers.Convertor) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Pair(com.intellij.openapi.util.Pair)

Example 12 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class RefreshSessionImpl method scan.

public void scan() {
    List<VirtualFile> workQueue = myWorkQueue;
    myWorkQueue = new ArrayList<>();
    boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty();
    if (!workQueue.isEmpty()) {
        LocalFileSystem fs = LocalFileSystem.getInstance();
        if (fs instanceof LocalFileSystemImpl) {
            ((LocalFileSystemImpl) fs).markSuspiciousFilesDirty(workQueue);
        }
        long t = 0;
        if (LOG.isTraceEnabled()) {
            LOG.trace("scanning " + workQueue);
            t = System.currentTimeMillis();
        }
        int count = 0;
        refresh: do {
            if (LOG.isTraceEnabled())
                LOG.trace("try=" + count);
            for (VirtualFile file : workQueue) {
                if (myCancelled)
                    break refresh;
                NewVirtualFile nvf = (NewVirtualFile) file;
                if (!myIsRecursive && !myIsAsync) {
                    // always scan when non-recursive AND synchronous - needed e.g. when refreshing project files on open
                    nvf.markDirty();
                }
                RefreshWorker worker = new RefreshWorker(nvf, myIsRecursive);
                myWorker = worker;
                worker.scan();
                haveEventsToFire |= myEvents.addAll(worker.getEvents());
            }
            count++;
            if (LOG.isTraceEnabled())
                LOG.trace("events=" + myEvents.size());
        } while (!myCancelled && myIsRecursive && count < 3 && workQueue.stream().anyMatch(f -> ((NewVirtualFile) f).isDirty()));
        if (t != 0) {
            t = System.currentTimeMillis() - t;
            LOG.trace((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents);
        }
    }
    myWorker = null;
    myHaveEventsToFire = haveEventsToFire;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefreshWorker(com.intellij.openapi.vfs.newvfs.persistent.RefreshWorker) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) LocalFileSystemImpl(com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl)

Example 13 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class VfsImplUtil method checkSubscription.

private static void checkSubscription() {
    if (ourSubscribed.getAndSet(true))
        return;
    Application app = ApplicationManager.getApplication();
    app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            InvalidationState state = null;
            synchronized (ourLock) {
                for (VFileEvent event : events) {
                    if (!(event.getFileSystem() instanceof LocalFileSystem))
                        continue;
                    // created file should not invalidate + getFile is costly
                    if (event instanceof VFileCreateEvent)
                        continue;
                    if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent) event).getPropertyName())) {
                        continue;
                    }
                    String path = event.getPath();
                    if (event instanceof VFilePropertyChangeEvent) {
                        path = ((VFilePropertyChangeEvent) event).getOldPath();
                    } else if (event instanceof VFileMoveEvent) {
                        path = ((VFileMoveEvent) event).getOldPath();
                    }
                    VirtualFile file = event.getFile();
                    if (file == null || !file.isDirectory()) {
                        state = InvalidationState.invalidate(state, path);
                    } else {
                        Collection<String> affectedPaths = ourDominatorsMap.get(path);
                        if (affectedPaths != null) {
                            // defensive copying; original may be updated on invalidation
                            affectedPaths = ContainerUtil.newArrayList(affectedPaths);
                            for (String affectedPath : affectedPaths) {
                                state = InvalidationState.invalidate(state, affectedPath);
                            }
                        }
                    }
                }
            }
            if (state != null)
                state.scheduleRefresh();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileMoveEvent(com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Collection(java.util.Collection) Application(com.intellij.openapi.application.Application)

Example 14 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class WinPathChooserDialog method fileToVirtualFile.

private VirtualFile fileToVirtualFile(File file) {
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
    return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
Also used : LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Example 15 with LocalFileSystem

use of com.intellij.openapi.vfs.LocalFileSystem in project intellij-community by JetBrains.

the class MacFileSaverDialog method fileToVirtualFile.

private static VirtualFile fileToVirtualFile(File file) {
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
    return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
Also used : LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem)

Aggregations

LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)52 File (java.io.File)27 Nullable (org.jetbrains.annotations.Nullable)9 NotNull (org.jetbrains.annotations.NotNull)8 IOException (java.io.IOException)6 Project (com.intellij.openapi.project.Project)5 Change (com.intellij.openapi.vcs.changes.Change)5 Test (org.junit.Test)5 Module (com.intellij.openapi.module.Module)4 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 PsiFile (com.intellij.psi.PsiFile)3 Notification (com.intellij.notification.Notification)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)2