Search in sources :

Example 16 with VirtualFilePointer

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

the class VirtualFilePointerTest method testMoveFileUnderExistingPointer.

public void testMoveFileUnderExistingPointer() 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 VirtualFilePointer fileToMoveTargetPointer = createPointerByFile(new File(moveTarget, fileToMove.getName()), listener);
    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(fileToMoveTargetPointer.isValid());
    assertEquals("[before:false, after:true]", listener.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 17 with VirtualFilePointer

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

the class VirtualFilePointerTest method testRenamingFileUnderTheExistingPointer.

public void testRenamingFileUnderTheExistingPointer() throws IOException {
    final File tempDir = createTempDirectory();
    final File file = new File(tempDir, "f1");
    assertTrue(file.createNewFile());
    final LoggingListener listener = new LoggingListener();
    VirtualFilePointer pointer = createPointerByFile(new File(file.getParent(), "f2"), listener);
    assertFalse(pointer.isValid());
    rename(getVirtualFile(file), "f2");
    assertTrue(pointer.isValid());
    assertEquals("[before:false, after:true]", listener.getLog().toString());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 18 with VirtualFilePointer

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

the class VirtualFilePointerTest method checkFileName.

private void checkFileName(String prefix, String suffix) throws IOException {
    final File tempDirectory = createTempDirectory();
    final VirtualFile temp = getVirtualFile(tempDirectory);
    String name = "toCreate.txt";
    final VirtualFilePointer fileToCreatePointer = createPointerByFile(new File(tempDirectory.getPath() + prefix + name + suffix), null);
    assertFalse(fileToCreatePointer.isValid());
    assertNull(fileToCreatePointer.getFile());
    VirtualFile child = createChildData(temp, name);
    assertTrue(fileToCreatePointer.isValid());
    assertEquals(child, fileToCreatePointer.getFile());
    VfsTestUtil.deleteFile(child);
    assertFalse(fileToCreatePointer.isValid());
    assertNull(fileToCreatePointer.getFile());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 19 with VirtualFilePointer

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

the class VirtualFilePointerTest method testJars.

public void testJars() throws Exception {
    final File tempDir = createTempDirectory();
    VirtualFile vTemp = refreshAndFindFile(tempDir);
    assertTrue(vTemp.isValid());
    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[2];
    final VirtualFilePointerListener listener = new VirtualFilePointerListener() {

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

        @Override
        public void validityChanged(@NotNull VirtualFilePointer[] pointers) {
            verifyPointersInCorrectState(pointersToWatch);
        }
    };
    final VirtualFilePointer jarParentPointer = createPointerByFile(jarParent, listener);
    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] = jarParentPointer;
    pointersToWatch[1] = jarPointer;
    assertTrue(jarParentPointer.isValid());
    assertTrue(jarPointer.isValid());
    assertTrue(jar.delete());
    assertTrue(jarParent.delete());
    refreshVFS();
    verifyPointersInCorrectState(pointersToWatch);
    assertFalse(jarParentPointer.isValid());
    assertFalse(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
    assertEmpty(vTemp.getChildren());
    assertTrue(jarParent.mkdir());
    FileUtil.copy(originalJar, jar);
    assertTrue(jar.setLastModified(System.currentTimeMillis()));
    assertTrue(jar.exists());
    assertTrue(jarParent.exists());
    assertTrue(jarParent.getParentFile().exists());
    File child = assertOneElement(jarParent.listFiles());
    assertEquals(jar.getName(), child.getName());
    refreshVFS();
    verifyPointersInCorrectState(pointersToWatch);
    assertTrue(jarParentPointer.isValid());
    assertTrue(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
    assertTrue(jar.delete());
    assertTrue(jarParent.delete());
    refreshVFS();
    UIUtil.dispatchAllInvocationEvents();
    verifyPointersInCorrectState(pointersToWatch);
    assertFalse(jarParentPointer.isValid());
    assertFalse(jarPointer.isValid());
    UIUtil.dispatchAllInvocationEvents();
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) 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 20 with VirtualFilePointer

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

the class JpsLibraryDelegate method getInvalidRootUrls.

@Override
public List<String> getInvalidRootUrls(OrderRootType type) {
    final VirtualFilePointerContainer container = myRoots.get(type);
    if (container == null)
        return Collections.emptyList();
    final List<VirtualFilePointer> pointers = container.getList();
    List<String> invalidPaths = null;
    for (VirtualFilePointer pointer : pointers) {
        if (!pointer.isValid()) {
            if (invalidPaths == null) {
                invalidPaths = new SmartList<>();
            }
            invalidPaths.add(pointer.getUrl());
        }
    }
    return invalidPaths == null ? Collections.<String>emptyList() : invalidPaths;
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

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