Search in sources :

Example 1 with VFileContentChangeEvent

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

the class JarFileSystemTest method testJarRefresh.

@Test
public void testJarRefresh() throws IOException {
    File jar = IoTestUtil.createTestJar(tempDir.newFile("test.jar"));
    assertTrue(jar.setLastModified(jar.lastModified() - 1000));
    VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
    assertNotNull(vFile);
    VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR);
    assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactly("META-INF");
    VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME);
    assertEquals("", VfsUtilCore.loadText(entry));
    Ref<Boolean> updated = Ref.create(false);
    ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void before(@NotNull List<? extends VFileEvent> events) {
            for (VFileEvent event : events) {
                if (event instanceof VFileContentChangeEvent && entry.equals(event.getFile())) {
                    updated.set(true);
                    break;
                }
            }
        }
    });
    IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text");
    vFile.refresh(false, false);
    assertTrue(updated.get());
    assertTrue(entry.isValid());
    assertEquals("update", VfsUtilCore.loadText(entry));
    assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactlyInAnyOrder("META-INF", "some.txt");
    VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt");
    assertEquals("some text", VfsUtilCore.loadText(newEntry));
}
Also used : VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) JarFile(java.util.jar.JarFile) Test(org.junit.Test)

Example 2 with VFileContentChangeEvent

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

the class LocalFileSystemTest method testFileContentChangeEvents.

public void testFileContentChangeEvents() throws IOException {
    File file = IoTestUtil.createTestFile("file.txt");
    long stamp = file.lastModified();
    VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file);
    assertNotNull(vFile);
    int[] updated = { 0 };
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable());
    connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {

        @Override
        public void after(@NotNull List<? extends VFileEvent> events) {
            for (VFileEvent event : events) {
                if (event instanceof VFileContentChangeEvent && vFile.equals(event.getFile())) {
                    updated[0]++;
                    break;
                }
            }
        }
    });
    FileUtil.writeToFile(file, "content");
    assertTrue(file.setLastModified(stamp));
    vFile.refresh(false, false);
    assertEquals(1, updated[0]);
    FileUtil.writeToFile(file, "more content");
    assertTrue(file.setLastModified(stamp));
    vFile.refresh(false, false);
    assertEquals(2, updated[0]);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) File(java.io.File)

Example 3 with VFileContentChangeEvent

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

the class JrtFileSystemImpl method checkSubscription.

private void checkSubscription() {
    if (mySubscribed.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) {
            Set<VirtualFile> toRefresh = null;
            for (VFileEvent event : events) {
                if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) {
                    VirtualFile file = event.getFile();
                    if (file != null && "release".equals(file.getName())) {
                        String homePath = file.getParent().getPath();
                        ArchiveHandler handler = myHandlers.remove(homePath);
                        if (handler != null) {
                            handler.dispose();
                            VirtualFile root = findFileByPath(composeRootPath(homePath));
                            if (root != null) {
                                ((NewVirtualFile) root).markDirtyRecursively();
                                if (toRefresh == null)
                                    toRefresh = ContainerUtil.newHashSet();
                                toRefresh.add(root);
                            }
                        }
                    }
                }
            }
            if (toRefresh != null) {
                boolean async = !ApplicationManager.getApplication().isUnitTestMode();
                RefreshQueue.getInstance().refresh(async, true, null, toRefresh);
            }
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) Set(java.util.Set) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) Application(com.intellij.openapi.application.Application)

Example 4 with VFileContentChangeEvent

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

use of com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent in project intellij by bazelbuild.

the class BulkSymbolTableBuildingChangeListener method after.

@Override
public void after(List<? extends VFileEvent> events) {
    if (!enabled) {
        return;
    }
    for (VFileEvent event : events) {
        VirtualFile modifiedFile = null;
        // Skip delete events.
        if (event instanceof VFileContentChangeEvent || event instanceof VFileCreateEvent) {
            modifiedFile = event.getFile();
        } else if (event instanceof VFileCopyEvent) {
            VFileCopyEvent copyEvent = (VFileCopyEvent) event;
            modifiedFile = copyEvent.getNewParent();
        } else if (event instanceof VFileMoveEvent) {
            VFileMoveEvent moveEvent = (VFileMoveEvent) event;
            modifiedFile = moveEvent.getNewParent();
        } else if (event instanceof VFilePropertyChangeEvent) {
            VFilePropertyChangeEvent propEvent = (VFilePropertyChangeEvent) event;
            // actually changing though)
            if (propEvent.getPropertyName().equals(VirtualFile.PROP_NAME) && !propEvent.getOldValue().equals(propEvent.getNewValue())) {
                modifiedFile = propEvent.getFile();
            }
        }
        if (SymbolTableProvider.isSourceFile(modifiedFile)) {
            queueChange(modifiedFile);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) VFilePropertyChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VFileCopyEvent(com.intellij.openapi.vfs.newvfs.events.VFileCopyEvent) VFileMoveEvent(com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent)

Aggregations

VFileContentChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent)5 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)3 Application (com.intellij.openapi.application.Application)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 ArchiveHandler (com.intellij.openapi.vfs.impl.ArchiveHandler)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 VFileCopyEvent (com.intellij.openapi.vfs.newvfs.events.VFileCopyEvent)1 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)1 VFileMoveEvent (com.intellij.openapi.vfs.newvfs.events.VFileMoveEvent)1 VFilePropertyChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 File (java.io.File)1 Set (java.util.Set)1 JarFile (java.util.jar.JarFile)1 Test (org.junit.Test)1