Search in sources :

Example 6 with BulkFileListener

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

the class JarDirectoryWatcherImpl method updateWatchedRoots.

@Override
public void updateWatchedRoots() {
    final LocalFileSystem fs = LocalFileSystem.getInstance();
    if (!myJarDirectories.isEmpty()) {
        final Set<String> recursiveRoots = new HashSet<>();
        final Set<String> flatRoots = new HashSet<>();
        final VirtualFileManager fm = VirtualFileManager.getInstance();
        for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
            for (String url : myJarDirectories.getDirectories(rootType)) {
                if (fm.getFileSystem(VirtualFileManager.extractProtocol(url)) instanceof LocalFileSystem) {
                    final boolean watchRecursively = myJarDirectories.isRecursive(rootType, url);
                    final String path = VirtualFileManager.extractPath(url);
                    (watchRecursively ? recursiveRoots : flatRoots).add(path);
                }
            }
        }
        myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots);
        if (myBusConnection == null) {
            myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
            myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

                @Override
                public void after(@NotNull final List<? extends VFileEvent> events) {
                    boolean changesDetected = false;
                    for (VFileEvent event : events) {
                        if (event instanceof VFileCopyEvent) {
                            final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
                            final VirtualFile file = copyEvent.getFile();
                            if (isUnderJarDirectory(copyEvent.getNewParent() + "/" + copyEvent.getNewChildName()) || file != null && isUnderJarDirectory(file.getUrl())) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileMoveEvent) {
                            final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
                            final VirtualFile file = moveEvent.getFile();
                            if (file != null && (isUnderJarDirectory(file.getUrl()) || isUnderJarDirectory(moveEvent.getOldParent().getUrl() + "/" + file.getName()))) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileDeleteEvent) {
                            final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
                            if (isUnderJarDirectory(deleteEvent.getFile().getUrl())) {
                                changesDetected = true;
                                break;
                            }
                        } else if (event instanceof VFileCreateEvent) {
                            final VFileCreateEvent createEvent = (VFileCreateEvent) event;
                            if (isUnderJarDirectory(createEvent.getParent().getUrl() + "/" + createEvent.getChildName())) {
                                changesDetected = true;
                                break;
                            }
                        }
                    }
                    if (changesDetected) {
                        fireRootSetChanged();
                    }
                }

                private boolean isUnderJarDirectory(String url) {
                    for (String rootUrl : myJarDirectories.getAllDirectories()) {
                        if (FileUtil.startsWith(url, rootUrl)) {
                            return true;
                        }
                    }
                    return false;
                }
            });
        }
    } else {
        cleanup();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) OrderRootType(com.intellij.openapi.roots.OrderRootType)

Example 7 with BulkFileListener

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

the class DirectoryIndexImpl method subscribeToFileChanges.

protected void subscribeToFileChanges() {
    myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {

        @Override
        public void fileTypesChanged(@NotNull FileTypeEvent event) {
            myRootIndex = null;
        }
    });
    myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myRootIndex = null;
        }
    });
    myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            RootIndex rootIndex = myRootIndex;
            if (rootIndex != null && rootIndex.resetOnEvents(events)) {
                myRootIndex = null;
            }
        }
    });
}
Also used : FileTypeListener(com.intellij.openapi.fileTypes.FileTypeListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) FileTypeEvent(com.intellij.openapi.fileTypes.FileTypeEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 8 with BulkFileListener

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

the class FileContentUtilCore method reparseFiles.

/**
   * Forces a reparse of the specified collection of files.
   *
   * @param files the files to reparse.
   */
public static void reparseFiles(@NotNull final Collection<VirtualFile> files) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        // files must be processed under one write action to prevent firing event for invalid files.
        final Set<VFilePropertyChangeEvent> events = new THashSet<>();
        for (VirtualFile file : files) {
            saveOrReload(file, events);
        }
        BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
        List<VFileEvent> eventList = new ArrayList<>(events);
        publisher.before(eventList);
        publisher.after(eventList);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) THashSet(gnu.trove.THashSet)

Example 9 with BulkFileListener

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

the class SvnTestCase method imitateEvent.

public static void imitateEvent(VirtualFile dir) {
    final VirtualFile child = dir.findChild(".svn");
    assertNotNull(child);
    final VirtualFile wcdb = child.findChild("wc.db");
    assertNotNull(wcdb);
    final BulkFileListener listener = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
    final VFileContentChangeEvent event = new VFileContentChangeEvent(null, wcdb, wcdb.getModificationStamp() - 1, wcdb.getModificationStamp(), true);
    final List<VFileContentChangeEvent> events = Collections.singletonList(event);
    listener.before(events);
    listener.after(events);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener)

Example 10 with BulkFileListener

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

the class VirtualFileManagerImpl method notifyPropertyChanged.

@Override
public void notifyPropertyChanged(@NotNull final VirtualFile virtualFile, @NotNull final String property, final Object oldValue, final Object newValue) {
    final Application application = ApplicationManager.getApplication();
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
            if (virtualFile.isValid() && !application.isDisposed()) {
                application.runWriteAction(new Runnable() {

                    @Override
                    public void run() {
                        List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
                        BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
                        listener.before(events);
                        listener.after(events);
                    }
                });
            }
        }
    };
    application.invokeLater(runnable, ModalityState.NON_MODAL);
}
Also used : VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ArrayList(java.util.ArrayList) List(java.util.List) Application(com.intellij.openapi.application.Application)

Aggregations

BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)10 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 VFileContentChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent)3 Application (com.intellij.openapi.application.Application)2 ModuleRootEvent (com.intellij.openapi.roots.ModuleRootEvent)2 ModuleRootListener (com.intellij.openapi.roots.ModuleRootListener)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)2 VFilePropertyChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 ArrayList (java.util.ArrayList)2 PowerSaveMode (com.intellij.ide.PowerSaveMode)1 ApplicationAdapter (com.intellij.openapi.application.ApplicationAdapter)1 FileTypeEvent (com.intellij.openapi.fileTypes.FileTypeEvent)1 FileTypeListener (com.intellij.openapi.fileTypes.FileTypeListener)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 ArchiveHandler (com.intellij.openapi.vfs.impl.ArchiveHandler)1 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)1