Search in sources :

Example 11 with VFileEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project intellij-leiningen-plugin by derkork.

the class LeiningenProjectsManagerWatcher method start.

public synchronized void start() {
    final MessageBusConnection myBusConnection = project.getMessageBus().connect(myQueue);
    myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        public void before(List<? extends VFileEvent> vFileEvents) {
        }

        public void after(List<? extends VFileEvent> vFileEvents) {
            for (VFileEvent vFileEvent : vFileEvents) {
                //                    }
                if (vFileEvent instanceof VFileCreateEvent) {
                    if (isRelevant(vFileEvent.getPath())) {
                        manager.importLeiningenProject(vFileEvent.getFileSystem().findFileByPath(vFileEvent.getPath()), project);
                    }
                }
            }
        }

        private boolean isRelevant(String path) {
            return path != null && path.endsWith(LeiningenConstants.PROJECT_CLJ);
        }
    });
    myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
        }

        public void rootsChanged(ModuleRootEvent moduleRootEvent) {
        }
    });
    myQueue.activate();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 12 with VFileEvent

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

the class JrtFileSystemTest method refresh.

@Test
public void refresh() throws IOException {
    assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a");
    Path modules = myTempPath.resolve("lib/modules");
    Files.move(modules, myTempPath.resolve("lib/modules.bak"), StandardCopyOption.ATOMIC_MOVE);
    Files.copy(myTestData.resolve("image2"), modules);
    Files.write(myTempPath.resolve("release"), "JAVA_VERSION=9.0.1\n".getBytes(CharsetToolkit.UTF8_CHARSET));
    VirtualFile local = LocalFileSystem.getInstance().findFileByIoFile(myTempDir.getRoot());
    assertThat(local).isNotNull();
    List<VFileEvent> events = VfsTestUtil.getEvents(() -> local.refresh(false, true));
    assertThat(childNames(myRoot)).describedAs("events=" + events).containsExactlyInAnyOrder("java.base", "test.a", "test.b");
}
Also used : Path(java.nio.file.Path) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) Test(org.junit.Test)

Example 13 with VFileEvent

use of com.intellij.openapi.vfs.newvfs.events.VFileEvent 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 14 with VFileEvent

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

the class LocalFileSystemTest method doTestPartialRefresh.

public static void doTestPartialRefresh(@NotNull File top) throws IOException {
    File sub = IoTestUtil.createTestDir(top, "sub");
    File file1 = IoTestUtil.createTestFile(top, "file1.txt", ".");
    File file2 = IoTestUtil.createTestFile(sub, "file2.txt", ".");
    LocalFileSystem lfs = LocalFileSystem.getInstance();
    VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top);
    assertNotNull(topDir);
    VirtualFile subDir = lfs.refreshAndFindFileByIoFile(sub);
    assertNotNull(subDir);
    VirtualFile vFile1 = lfs.refreshAndFindFileByIoFile(file1);
    assertNotNull(vFile1);
    VirtualFile vFile2 = lfs.refreshAndFindFileByIoFile(file2);
    assertNotNull(vFile2);
    topDir.refresh(false, true);
    Set<VirtualFile> processed = ContainerUtil.newHashSet();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            events.forEach(e -> processed.add(e.getFile()));
        }
    });
    try {
        IoTestUtil.updateFile(file1, "++");
        IoTestUtil.updateFile(file2, "++");
        ((NewVirtualFile) topDir).markDirtyRecursively();
        topDir.refresh(false, false);
        // vFile2 should stay unvisited after non-recursive refresh
        assertThat(processed).containsExactly(vFile1);
        processed.clear();
        topDir.refresh(false, true);
        // vFile2 changes should be picked up by a next recursive refresh
        assertThat(processed).containsExactly(vFile2);
    } finally {
        connection.disconnect();
    }
}
Also used : VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) ArrayUtil(com.intellij.util.ArrayUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileAttributes(com.intellij.openapi.util.io.FileAttributes) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileSystemUtil(com.intellij.openapi.util.io.FileSystemUtil) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) com.intellij.openapi.vfs.newvfs(com.intellij.openapi.vfs.newvfs) PersistentFSImpl(com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) FileUtil(com.intellij.openapi.util.io.FileUtil) VFileDeleteEvent(com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent) Path(java.nio.file.Path) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) RefreshWorker(com.intellij.openapi.vfs.newvfs.persistent.RefreshWorker) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) Files(java.nio.file.Files) StringUtil(com.intellij.openapi.util.text.StringUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS) IOException(java.io.IOException) VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IoTestUtil(com.intellij.openapi.util.io.IoTestUtil) com.intellij.openapi.vfs(com.intellij.openapi.vfs) GeneralSettings(com.intellij.ide.GeneralSettings) VirtualFileSystemEntry(com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) File(java.io.File)

Example 15 with VFileEvent

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

the class LocalFileSystemTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable());
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void before(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, true);
        }

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            checkFiles(events, false);
        }

        private void checkFiles(List<? extends VFileEvent> events, boolean before) {
            for (VFileEvent event : events) {
                VirtualFile file = event.getFile();
                if (file != null) {
                    boolean shouldBeInvalid = event instanceof VFileCreateEvent && before && !((VFileCreateEvent) event).isReCreation() || event instanceof VFileDeleteEvent && !before;
                    assertEquals(event.toString(), !shouldBeInvalid, file.isValid());
                }
            }
        }
    });
    myFS = LocalFileSystem.getInstance();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileDeleteEvent(com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)

Aggregations

VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)16 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)5 VFileContentChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent)5 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)5 File (java.io.File)4 VFileDeleteEvent (com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)3 GeneralSettings (com.intellij.ide.GeneralSettings)2 Application (com.intellij.openapi.application.Application)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 WriteAction (com.intellij.openapi.application.WriteAction)2 SystemInfo (com.intellij.openapi.util.SystemInfo)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 FileSystemUtil (com.intellij.openapi.util.io.FileSystemUtil)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 IoTestUtil (com.intellij.openapi.util.io.IoTestUtil)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 com.intellij.openapi.vfs (com.intellij.openapi.vfs)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2