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