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());
}
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());
}
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();
}
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());
}
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());
}
Aggregations