Search in sources :

Example 1 with VFileDeleteEvent

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

the class LocalFileSystemTest method testFindRoot.

public void testFindRoot() throws IOException {
    VirtualFile root = myFS.findFileByPath("wrong_path");
    assertNull(root);
    VirtualFile root2;
    if (SystemInfo.isWindows) {
        root = myFS.findFileByPath("\\\\unit-133");
        assertNotNull(root);
        root2 = myFS.findFileByPath("//UNIT-133");
        assertNotNull(root2);
        assertEquals(String.valueOf(root2), root, root2);
        RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));
        root = myFS.findFileByIoFile(new File("\\\\unit-133"));
        assertNotNull(root);
        RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false));
        if (new File("c:").exists()) {
            root = myFS.findFileByPath("c:");
            assertNotNull(root);
            assertEquals("C:/", root.getPath());
            root2 = myFS.findFileByPath("C:\\");
            assertSame(String.valueOf(root), root, root2);
            VirtualFileManager fm = VirtualFileManager.getInstance();
            root = fm.findFileByUrl("file://C:/");
            assertNotNull(root);
            root2 = fm.findFileByUrl("file:///c:/");
            assertSame(String.valueOf(root), root, root2);
        }
    } else if (SystemInfo.isUnix) {
        root = myFS.findFileByPath("/");
        assertNotNull(root);
        assertEquals("/", root.getPath());
    }
    root = myFS.findFileByPath("");
    assertNotNull(root);
    File jarFile = IoTestUtil.createTestJar();
    assertNotNull(getVirtualFile(jarFile));
    root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/");
    assertNotNull(root);
    root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/");
    assertEquals(String.valueOf(root2), root, root2);
    if (!SystemInfo.isFileSystemCaseSensitive) {
        root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/");
        assertEquals(String.valueOf(root2), root, root2);
    }
}
Also used : File(java.io.File) VFileDeleteEvent(com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)

Example 2 with VFileDeleteEvent

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

VFileDeleteEvent (com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent)2 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)1 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 File (java.io.File)1