Search in sources :

Example 11 with VirtualFilePointer

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

the class VirtualFilePointerTest method testMultipleNotifications.

public void testMultipleNotifications() throws Exception {
    final File tempDir = createTempDirectory();
    final File file_f1 = new File(tempDir, "f1");
    final File file_f2 = new File(tempDir, "f2");
    final LoggingListener listener = new LoggingListener();
    final VirtualFilePointer pointer_f1 = createPointerByFile(file_f1, listener);
    final VirtualFilePointer pointer_f2 = createPointerByFile(file_f2, listener);
    assertFalse(pointer_f1.isValid());
    assertFalse(pointer_f2.isValid());
    assertTrue(file_f1.createNewFile());
    assertTrue(file_f2.createNewFile());
    ApplicationManager.getApplication().runWriteAction(() -> LocalFileSystem.getInstance().refresh(false));
    assertEquals("[before:false:false, after:true:true]", listener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 12 with VirtualFilePointer

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

the class VirtualFilePointerTest method testMovePointedFileUnderAnotherPointer.

public void testMovePointedFileUnderAnotherPointer() throws Exception {
    File tempDirectory = createTempDirectory();
    final File moveTarget = new File(tempDirectory, "moveTarget");
    assertTrue(moveTarget.mkdir());
    final File fileToMove = new File(tempDirectory, "toMove.txt");
    assertTrue(fileToMove.createNewFile());
    final LoggingListener listener = new LoggingListener();
    final LoggingListener targetListener = new LoggingListener();
    final VirtualFilePointer fileToMovePointer = createPointerByFile(fileToMove, listener);
    final VirtualFilePointer fileToMoveTargetPointer = createPointerByFile(new File(moveTarget, fileToMove.getName()), targetListener);
    assertFalse(fileToMoveTargetPointer.isValid());
    ApplicationManager.getApplication().runWriteAction(() -> {
        final VirtualFile virtualFile = getVirtualFile(fileToMove);
        assertTrue(virtualFile.isValid());
        final VirtualFile target = getVirtualFile(moveTarget);
        assertTrue(target.isValid());
        try {
            virtualFile.move(null, target);
        } catch (IOException e) {
            fail();
        }
    });
    assertTrue(fileToMovePointer.isValid());
    assertTrue(fileToMoveTargetPointer.isValid());
    assertEquals("[before:true, after:true]", listener.getLog().toString());
    assertEquals("[before:false, after:true]", targetListener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 13 with VirtualFilePointer

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

the class VirtualFilePointerTest method testJars2.

public void testJars2() throws Exception {
    final File tempDir = createTempDirectory();
    final File jarParent = new File(tempDir, "jarParent");
    assertTrue(jarParent.mkdir());
    final File jar = new File(jarParent, "x.jar");
    final File originalJar = new File(PathManagerEx.getTestDataPath() + "/psi/generics22/collect-2.2.jar");
    FileUtil.copy(originalJar, jar);
    // Make sure we receive events when jar changes
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
    final VirtualFilePointer[] pointersToWatch = new VirtualFilePointer[1];
    final VirtualFilePointerListener listener = new VirtualFilePointerListener() {

        @Override
        public void beforeValidityChanged(@NotNull VirtualFilePointer[] pointers) {
            verifyPointersInCorrectState(pointersToWatch);
        }

        @Override
        public void validityChanged(@NotNull VirtualFilePointer[] pointers) {
            verifyPointersInCorrectState(pointersToWatch);
        }
    };
    final String pathInJar = jar.getPath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
    final String jarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, pathInJar);
    final VirtualFilePointer jarPointer = myVirtualFilePointerManager.create(jarUrl, disposable, listener);
    pointersToWatch[0] = jarPointer;
    assertTrue(jarPointer.isValid());
    assertTrue(jar.delete());
    refreshVFS();
    verifyPointersInCorrectState(pointersToWatch);
    assertFalse(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
    assertTrue(jarParent.exists());
    FileUtil.copy(originalJar, jar);
    assert jar.exists();
    refreshVFS();
    verifyPointersInCorrectState(pointersToWatch);
    assertTrue(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
    assertTrue(jar.delete());
    refreshVFS();
    UIUtil.dispatchAllInvocationEvents();
    verifyPointersInCorrectState(pointersToWatch);
    assertFalse(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
}
Also used : VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 14 with VirtualFilePointer

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

the class VirtualFilePointerTest method testTwoPointersBecomeOneAfterFileRenamedUnderTheOtherName.

public void testTwoPointersBecomeOneAfterFileRenamedUnderTheOtherName() throws IOException {
    final File tempDir = createTempDirectory();
    final File f1 = new File(tempDir, "f1");
    boolean created = f1.createNewFile();
    assertTrue(created);
    final String url1 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, f1.getCanonicalPath().replace(File.separatorChar, '/'));
    final VirtualFile vFile1 = refreshAndFind(url1);
    final LoggingListener listener1 = new LoggingListener();
    VirtualFilePointer pointer1 = myVirtualFilePointerManager.create(url1, disposable, listener1);
    assertTrue(pointer1.isValid());
    String url2 = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, tempDir.getCanonicalPath().replace(File.separatorChar, '/') + "/f2");
    final LoggingListener listener2 = new LoggingListener();
    VirtualFilePointer pointer2 = myVirtualFilePointerManager.create(url2, disposable, listener2);
    assertFalse(pointer2.isValid());
    rename(vFile1, "f2");
    assertTrue(pointer1.isValid());
    assertTrue(pointer2.isValid());
    assertEquals("[]", listener1.getLog().toString());
    assertEquals("[before:false, after:true]", listener2.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 15 with VirtualFilePointer

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

the class VirtualFilePointerTest method testMovePointedFile.

public void testMovePointedFile() throws Exception {
    File tempDirectory = createTempDirectory();
    final File moveTarget = new File(tempDirectory, "moveTarget");
    assertTrue(moveTarget.mkdir());
    final File fileToMove = new File(tempDirectory, "toMove.txt");
    assertTrue(fileToMove.createNewFile());
    final LoggingListener fileToMoveListener = new LoggingListener();
    final VirtualFilePointer fileToMovePointer = createPointerByFile(fileToMove, fileToMoveListener);
    assertTrue(fileToMovePointer.isValid());
    ApplicationManager.getApplication().runWriteAction(() -> {
        final VirtualFile virtualFile = getVirtualFile(fileToMove);
        assertTrue(virtualFile.isValid());
        final VirtualFile target = getVirtualFile(moveTarget);
        assertTrue(target.isValid());
        try {
            virtualFile.move(null, target);
        } catch (IOException e) {
            fail();
        }
    });
    assertTrue(fileToMovePointer.isValid());
    assertEquals("[before:true, after:true]", fileToMoveListener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2