use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testDotDot.
public void testDotDot() throws IOException {
File tempDirectory = createTempDirectory();
final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
VirtualFile dir1 = createChildDirectory(root, "dir1");
VirtualFile dir2 = createChildDirectory(root, "dir2");
VirtualFile file = createChildData(dir1, "x.txt");
VirtualFilePointer pointer = myVirtualFilePointerManager.create(dir2.getUrl() + "/../" + dir1.getName() + "/" + file.getName(), disposable, null);
assertEquals(file, pointer.getFile());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testRenamingPointedFile.
public void testRenamingPointedFile() throws IOException {
final File tempDir = createTempDirectory();
final File file = new File(tempDir, "f1");
assertTrue(file.createNewFile());
final LoggingListener listener = new LoggingListener();
VirtualFilePointer pointer = createPointerByFile(file, listener);
assertTrue(pointer.isValid());
rename(getVirtualFile(file), "f2");
assertTrue(pointer.isValid());
assertEquals("[]", listener.getLog().toString());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testTwoPointersMergingIntoOne.
public void testTwoPointersMergingIntoOne() throws IOException {
File tempDirectory = createTempDirectory();
final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory);
VirtualFile dir1 = createChildDirectory(root, "dir1");
VirtualFile dir2 = createChildDirectory(root, "dir2");
VirtualFilePointer p1 = myVirtualFilePointerManager.create(dir1, disposable, null);
VirtualFilePointer p2 = myVirtualFilePointerManager.create(dir2, disposable, null);
assertTrue(p1.isValid());
assertEquals(dir1, p1.getFile());
assertTrue(p2.isValid());
assertEquals(dir2, p2.getFile());
delete(dir1);
assertNull(p1.getFile());
assertEquals(dir2, p2.getFile());
rename(dir2, "dir1");
assertEquals(dir2, p1.getFile());
assertEquals(dir2, p2.getFile());
rename(dir2, "dir2");
assertEquals(dir2, p1.getFile());
assertEquals(dir2, p2.getFile());
createChildDirectory(root, "dir1");
assertEquals(dir2, p1.getFile());
assertEquals(dir2, p2.getFile());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testCreate.
public void testCreate() throws Exception {
final File tempDirectory = createTempDirectory();
final File fileToCreate = new File(tempDirectory, "toCreate.txt");
final LoggingListener fileToCreateListener = new LoggingListener();
final VirtualFilePointer fileToCreatePointer = createPointerByFile(fileToCreate, fileToCreateListener);
assertFalse(fileToCreatePointer.isValid());
assertTrue(fileToCreate.createNewFile());
ApplicationManager.getApplication().runWriteAction(() -> {
VirtualFileManager.getInstance().syncRefresh();
final VirtualFile virtualFile = getVirtualFile(tempDirectory);
virtualFile.refresh(false, true);
});
assertTrue(fileToCreatePointer.isValid());
assertEquals("[before:false, after:true]", fileToCreateListener.getLog().toString());
try {
String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, fileToCreate.getCanonicalPath().replace(File.separatorChar, '/'));
assertEquals(expectedUrl.toUpperCase(), fileToCreatePointer.getUrl().toUpperCase());
} catch (IOException e) {
fail();
}
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testCreate1.
public void testCreate1() throws Exception {
final File tempDirectory = createTempDirectory();
final File fileToCreate = new File(tempDirectory, "toCreate1.txt");
final LoggingListener fileToCreateListener = new LoggingListener();
final VirtualFilePointer fileToCreatePointer = createPointerByFile(fileToCreate, fileToCreateListener);
assertFalse(fileToCreatePointer.isValid());
assertTrue(fileToCreate.createNewFile());
final Runnable postRunnable = () -> {
assertTrue(fileToCreatePointer.isValid());
assertEquals("[before:false, after:true]", fileToCreateListener.getLog().toString());
try {
String expectedUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, fileToCreate.getCanonicalPath().replace(File.separatorChar, '/'));
assertEquals(expectedUrl.toUpperCase(), fileToCreatePointer.getUrl().toUpperCase());
} catch (IOException e) {
fail();
}
};
ApplicationManager.getApplication().runWriteAction(() -> {
VirtualFileManager.getInstance().syncRefresh();
final VirtualFile virtualFile = getVirtualFile(tempDirectory);
virtualFile.refresh(false, true);
});
postRunnable.run();
}
Aggregations