public void testDeleteSubstRoots() throws Exception { if (!SystemInfo.isWindows) return; File tempDirectory = FileUtil.createTempDirectory(getTestName(false), null); File substRoot = IoTestUtil.createSubst(tempDirectory.getPath()); VirtualFile subst = myLocalFs.refreshAndFindFileByIoFile(substRoot); assertNotNull(subst); try { final File[] children = substRoot.listFiles(); assertNotNull(children); } finally { IoTestUtil.deleteSubst(substRoot.getPath()); } subst.refresh(false, true); VirtualFile[] roots = myFs.getRoots(myLocalFs); for (VirtualFile root : roots) { String rootPath = root.getPath(); String prefix = StringUtil.commonPrefix(rootPath, substRoot.getPath()); assertEmpty(prefix); } }
public void testJarRefreshOnRenameOrMove() throws IOException { File jar = IoTestUtil.createTestJar(); final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar); assertNotNull(vFile); new WriteCommandAction.Simple(myProject) { @Override protected void run() throws Throwable { PsiTestUtil.addContentRoot(myModule, vFile.getParent()); } }.execute(); VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); final PsiFile file = getPsiManager().findFile(vFile); final String newName = vFile.getName() + ".jar"; rename(file, newName); assertFalse(jarRoot.isValid()); checkMove(jar, vFile, file); }
public void testCopyToPointDir() throws Exception { File top = createTempDirectory(false); File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "file.txt", "hi there"); VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); VirtualFile parentDir = myFS.refreshAndFindFileByIoFile(sub); assertNotNull(parentDir); assertEquals(2, topDir.getChildren().length); try { sourceFile.copy(this, parentDir, "."); fail("Copying a file into a '.' path should have failed"); } catch (IOException e) { System.out.println(e.getMessage()); } topDir.refresh(false, true); assertTrue(topDir.exists()); assertEquals(2, topDir.getChildren().length); }
public void testBrokenSymlinkMove() throws IOException, InterruptedException { if (!SystemInfo.areSymLinksSupported) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } final File srcDir = IoTestUtil.createTestDir("src"); final File link = IoTestUtil.createSymLink(srcDir.getPath() + "/missing", srcDir.getPath() + "/link", false); final File dstDir = IoTestUtil.createTestDir("dst"); new WriteAction() { @Override protected void run(@NotNull Result result) throws Throwable { VirtualFile file = myFS.refreshAndFindFileByIoFile(link); assertNotNull(file); VirtualFile target = myFS.refreshAndFindFileByIoFile(dstDir); assertNotNull(target); myFS.moveFile(this, file, target); } }.execute(); assertOrderedEquals(ArrayUtil.EMPTY_STRING_ARRAY, srcDir.list()); assertOrderedEquals(new String[]{link.getName()}, dstDir.list()); }
public void testFindRootPerformance() throws IOException { File tempJar = IoTestUtil.createTestJar(); final VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); final JarFileSystem fs = JarFileSystem.getInstance(); final String path = jar.getPath() + "!/"; final NewVirtualFile root = ManagingFS.getInstance().findRoot(path, fs); PlatformTestUtil.startPerformanceTest("find root is slow", 5000, new ThrowableRunnable() { @Override public void run() throws Throwable { JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, false, new Processor<Object>() { @Override public boolean process(Object o) { for (int i = 0; i < 20000; i++) { NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs); assertNotNull(rootJar); assertSame(root, rootJar); } return true; } }); } }).assertTiming(); }
public static void createEmptyJar(@NotNull String dir, @NotNull String name) throws IOException { File jar = new File(dir, name); FileUtil.ensureExists(jar.getParentFile()); IoTestUtil.createTestJar(jar); MessageDigest digest; try { digest = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } digest.update(FileUtil.loadFileBytes(jar)); byte[] sha1 = digest.digest(); PrintWriter out = new PrintWriter(new File(dir, name + ".sha1"), "UTF-8"); try { for (byte b : sha1) out.printf("%02x", b); out.println(" " + name); } finally { out.close(); } }
public void testHiddenFiles() throws Exception { if (!SystemInfo.isWindows) { System.err.println("Ignored: Windows required"); return; } File topDir = createTestDir("topDir"); File testDir = createTestDir(topDir, "dir"); File testFile = createTestFile(testDir, "file", "123"); refresh(topDir); LocalFileSystem.WatchRequest request = watch(topDir); try { myAccept = true; IoTestUtil.setHidden(testFile.getPath(), true); assertEvent(VFilePropertyChangeEvent.class, testFile.getPath()); } finally { unwatch(request); } }
public void testCopyToPointDir() throws Exception { File top = createTempDirectory(false); File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "file.txt", "hi there"); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = lfs.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); VirtualFile parentDir = lfs.refreshAndFindFileByIoFile(sub); assertNotNull(parentDir); assertEquals(2, topDir.getChildren().length); try { sourceFile.copy(this, parentDir, "."); fail("Copying a file into a '.' path should have failed"); } catch (IOException e) { System.out.println(e.getMessage()); } topDir.refresh(false, true); assertTrue(topDir.exists()); assertEquals(2, topDir.getChildren().length); }
public void testDeleteSubstRoots() throws IOException, InterruptedException { if (!SystemInfo.isWindows) return; File tempDirectory = FileUtil.createTempDirectory(getTestName(false), null); File substRoot = IoTestUtil.createSubst(tempDirectory.getPath()); VirtualFile subst = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(substRoot); assertNotNull(subst); try { final File[] children = substRoot.listFiles(); assertNotNull(children); } finally { IoTestUtil.deleteSubst(substRoot.getPath()); } subst.refresh(false, true); PersistentFS fs = PersistentFS.getInstance(); VirtualFile[] roots = fs.getRoots(LocalFileSystem.getInstance()); for (VirtualFile root : roots) { String rootPath = root.getPath(); String prefix = StringUtil.commonPrefix(rootPath, substRoot.getPath()); assertEmpty(prefix); } }
public void testClassFileUpdate() throws IOException { File testFile = IoTestUtil.createTestFile("TestClass.class"); File file1 = new File(PathManagerEx.getTestDataPath() + TEST_DATA_PATH + "/1_TestClass.class"); FileUtil.copy(file1, testFile); VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(testFile); assertNotNull(testFile.getPath(), vFile); FileBasedIndex.getInstance().requestReindex(vFile); PsiFile file = PsiManager.getInstance(getProject()).findFile(vFile); assertNotNull(file); PsiClass aClass = ((PsiJavaFile)file).getClasses()[0]; assertTrue(aClass.isValid()); assertEquals(2, aClass.getFields().length); assertEquals("field11", aClass.getFields()[0].getName()); assertEquals("field12", aClass.getFields()[1].getName()); assertEquals(2, aClass.getMethods().length); assertEquals("TestClass", aClass.getMethods()[0].getName()); assertEquals("method1", aClass.getMethods()[1].getName()); File file2 = new File(PathManagerEx.getTestDataPath() + TEST_DATA_PATH + "/2_TestClass.class"); FileUtil.copy(file2, testFile); assertTrue(testFile.setLastModified(System.currentTimeMillis() + 5000)); vFile.refresh(false, false); aClass = ((PsiJavaFile)file).getClasses()[0]; assertTrue(aClass.isValid()); assertTrue(aClass.isValid()); assertEquals(1, aClass.getFields().length); assertEquals("field2", aClass.getFields()[0].getName()); assertEquals(2, aClass.getMethods().length); assertEquals("TestClass", aClass.getMethods()[0].getName()); assertEquals("method2", aClass.getMethods()[1].getName()); }
public void testFileTypeModificationDocumentPreservation() throws Exception { File ioFile = IoTestUtil.createTestFile("test.html", "<html>some text</html>"); VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile); assertNotNull(ioFile.getPath(), file); FileDocumentManager documentManager = FileDocumentManager.getInstance(); Document original = documentManager.getDocument(file); assertNotNull(file.getPath(), original); renameFile(file, "test.wtf"); Document afterRename = documentManager.getDocument(file); assertTrue(afterRename + " != " + original, afterRename == original); }
public void testFileTypeChangeDocumentDetach() throws Exception { File ioFile = IoTestUtil.createTestFile("test.html", "<html>some text</html>"); VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile); assertNotNull(ioFile.getPath(), file); FileDocumentManager documentManager = FileDocumentManager.getInstance(); Document original = documentManager.getDocument(file); assertNotNull(file.getPath(), original); renameFile(file, "test.png"); Document afterRename = documentManager.getDocument(file); assertNull(afterRename + " != null", afterRename); }
public void testBrokenJarRoots() throws Exception { final File jarFile = IoTestUtil.createTestFile("empty.jar"); final int[] logCount = {0}; LoggedErrorProcessor.setNewInstance(new LoggedErrorProcessor() { @Override public void processWarn(String message, Throwable t, @NotNull Logger logger) { super.processWarn(message, t, logger); if (message.contains(jarFile.getName())) logCount[0]++; } }); try { String rootUrl = "jar://" + FileUtil.toSystemIndependentName(jarFile.getPath()) + "!/"; String entryUrl = rootUrl + JarFile.MANIFEST_NAME; assertNotNull(getVirtualFile(jarFile)); VirtualFile jarRoot = VirtualFileManager.getInstance().findFileByUrl(rootUrl); assertNotNull(jarRoot); assertTrue(jarRoot.isValid()); assertEquals(0, jarRoot.getChildren().length); assertNull(VirtualFileManager.getInstance().findFileByUrl(entryUrl)); VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(jarRoot); assertNotNull(local); IoTestUtil.createTestJar(jarFile); local.refresh(false, false); assertTrue(jarRoot.isValid()); assertEquals(1, jarRoot.getChildren().length); assertNotNull(VirtualFileManager.getInstance().findFileByUrl(entryUrl)); } finally { LoggedErrorProcessor.restoreDefaultProcessor(); } assertEquals(1, logCount[0]); }
public void testJarRefresh() throws IOException { File jar = IoTestUtil.createTestJar(); assertTrue(jar.setLastModified(jar.lastModified() - 1000)); VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar); assertNotNull(vFile); VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); assertEquals(1, jarRoot.getChildren().length); final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME); assertContent(entry, ""); final Ref<Boolean> updated = Ref.create(false); ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe( VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void before(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent && entry.equals(event.getFile())) { updated.set(true); break; } } } } ); IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text"); vFile.refresh(false, false); assertTrue(updated.get()); assertTrue(entry.isValid()); assertContent(entry, "update"); assertEquals(2, jarRoot.getChildren().length); VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt"); assertContent(newEntry, "some text"); }
public void testHardLinks() throws Exception { if (!SystemInfo.isWindows && !SystemInfo.isUnix) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } final boolean safeWrite = GeneralSettings.getInstance().isUseSafeWrite(); final File dir = FileUtil.createTempDirectory("hardlinks.", ".dir", false); final SafeWriteRequestor requestor = new SafeWriteRequestor() { }; try { GeneralSettings.getInstance().setUseSafeWrite(false); final File targetFile = new File(dir, "targetFile"); assertTrue(targetFile.createNewFile()); final File hardLinkFile = IoTestUtil.createHardLink(targetFile.getAbsolutePath(), "hardLinkFile"); final VirtualFile file = myFS.refreshAndFindFileByIoFile(targetFile); assertNotNull(file); file.setBinaryContent("hello".getBytes(CharsetToolkit.UTF8_CHARSET), 0, 0, requestor); assertTrue(file.getLength() > 0); final VirtualFile check = myFS.refreshAndFindFileByIoFile(hardLinkFile); assertNotNull(check); assertEquals(file.getLength(), check.getLength()); assertEquals("hello", VfsUtilCore.loadText(check)); } finally { GeneralSettings.getInstance().setUseSafeWrite(safeWrite); FileUtil.delete(dir); } }
public void testFileCaseChange() throws Exception { if (SystemInfo.isFileSystemCaseSensitive) { System.err.println("Ignored: case-insensitive FS required"); return; } File top = createTempDirectory(false); File file = IoTestUtil.createTestFile(top, "file.txt", "test"); VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); String newName = StringUtil.capitalize(file.getName()); FileUtil.rename(file, newName); topDir.refresh(false, true); assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); topDir.getChildren(); newName = newName.toLowerCase(Locale.ENGLISH); FileUtil.rename(file, newName); topDir.refresh(false, true); assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); }
public static void doTestPartialRefresh(@NotNull File top) throws IOException { File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "sub.txt"); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); NewVirtualFile subDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(sub); assertNotNull(subDir); NewVirtualFile subFile = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file); assertNotNull(subFile); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subDir.isDirty()); assertFalse(subFile.isDirty()); subFile.markDirty(); subDir.markDirty(); assertTrue(topDir.isDirty()); assertTrue(subFile.isDirty()); assertTrue(subDir.isDirty()); topDir.refresh(false, false); assertFalse(subFile.isDirty()); assertTrue(subDir.isDirty()); // should stay unvisited after non-recursive refresh topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile.isDirty()); assertFalse(subDir.isDirty()); }
public void testSymlinkTargetBlink() throws Exception { if (!SystemInfo.areSymLinksSupported) { System.err.println("Ignored: symlinks not supported"); return; } File top = createTempDirectory(true); File target = IoTestUtil.createTestDir(top, "target"); File link = IoTestUtil.createSymLink(target.getPath(), top.getPath() + "/link"); VirtualFile vTop = myFS.refreshAndFindFileByIoFile(top); assertNotNull(vTop); assertTrue(vTop.isValid()); VirtualFile vTarget = myFS.refreshAndFindFileByIoFile(target); assertNotNull(vTarget); assertTrue(vTarget.isValid()); VirtualFile vLink = myFS.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertTrue(vLink.isDirectory()); FileUtil.delete(target); vTop.refresh(false, true); assertFalse(vTarget.isValid()); assertFalse(vLink.isValid()); vLink = myFS.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertFalse(vLink.isDirectory()); FileUtil.createDirectory(target); vTop.refresh(false, true); assertFalse(vLink.isValid()); vLink = myFS.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertTrue(vLink.isDirectory()); }
public static void doTestInterruptedRefresh(@NotNull File top) throws Exception { File sub = IoTestUtil.createTestDir(top, "sub"); File subSub = IoTestUtil.createTestDir(sub, "sub_sub"); File file1 = IoTestUtil.createTestFile(sub, "sub_file_to_stop_at"); File file2 = IoTestUtil.createTestFile(subSub, "sub_sub_file"); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); NewVirtualFile subFile1 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file1); assertNotNull(subFile1); NewVirtualFile subFile2 = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file2); assertNotNull(subFile2); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile1.isDirty()); assertFalse(subFile2.isDirty()); try { subFile1.markDirty(); subFile2.markDirty(); RefreshWorker.setCancellingCondition(file -> "sub_file_to_stop_at".equals(file.getName())); topDir.refresh(false, true); // should remain dirty after aborted refresh assertTrue(subFile1.isDirty()); assertTrue(subFile2.isDirty()); RefreshWorker.setCancellingCondition(null); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile1.isDirty()); assertFalse(subFile2.isDirty()); } finally { RefreshWorker.setCancellingCondition(null); } }
public void testFileContentChangeEvents() throws IOException { File file = IoTestUtil.createTestFile("file.txt"); long stamp = file.lastModified(); VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(vFile); int[] updated = {0}; MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent && vFile.equals(event.getFile())) { updated[0]++; break; } } } }); FileUtil.writeToFile(file, "content"); assertTrue(file.setLastModified(stamp)); vFile.refresh(false, false); assertEquals(1, updated[0]); FileUtil.writeToFile(file, "more content"); assertTrue(file.setLastModified(stamp)); vFile.refresh(false, false); assertEquals(2, updated[0]); }
public void testFindRootWithDenormalizedPath() throws IOException { File tempJar = IoTestUtil.createTestJar(); VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); JarFileSystem fs = JarFileSystem.getInstance(); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", fs); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//" + jar.getName() + "!/", fs); assertNotNull(root1); assertSame(root1, root2); }
public void testHardLinks() throws Exception { if (!SystemInfo.isWindows && !SystemInfo.isUnix) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } final boolean safeWrite = GeneralSettings.getInstance().isUseSafeWrite(); final File dir = FileUtil.createTempDirectory("hardlinks.", ".dir", false); final SafeWriteRequestor requestor = new SafeWriteRequestor() { }; try { GeneralSettings.getInstance().setUseSafeWrite(false); final File targetFile = new File(dir, "targetFile"); assertTrue(targetFile.createNewFile()); final File hardLinkFile = IoTestUtil.createHardLink(targetFile.getAbsolutePath(), "hardLinkFile"); final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); assertNotNull(file); file.setBinaryContent("hello".getBytes("UTF-8"), 0, 0, requestor); assertTrue(file.getLength() > 0); final VirtualFile check = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(hardLinkFile); assertNotNull(check); assertEquals(file.getLength(), check.getLength()); assertEquals("hello", VfsUtilCore.loadText(check)); } finally { GeneralSettings.getInstance().setUseSafeWrite(safeWrite); FileUtil.delete(dir); } }
@Override protected void tearDown() throws Exception { try { IoTestUtil.delete(myTempDir); } finally { super.tearDown(); } }
public void testFileCaseChange() throws Exception { if (SystemInfo.isFileSystemCaseSensitive) { System.err.println("Ignored: case-insensitive FS required"); return; } File top = createTempDirectory(false); File file = IoTestUtil.createTestFile(top, "file.txt", "test"); File intermediate = new File(top, "_intermediate_"); VirtualFile topDir = myFS.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); String newName = StringUtil.capitalize(file.getName()); FileUtil.rename(file, intermediate); FileUtil.rename(intermediate, new File(top, newName)); topDir.refresh(false, true); assertFalse(((VirtualDirectoryImpl)topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); topDir.getChildren(); newName = newName.toLowerCase(Locale.ENGLISH); FileUtil.rename(file, intermediate); FileUtil.rename(intermediate, new File(top, newName)); topDir.refresh(false, true); assertTrue(((VirtualDirectoryImpl)topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); }
public static void doTestPartialRefresh(@Nonnull File top) throws IOException { File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "sub.txt"); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile topDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); NewVirtualFile subDir = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(sub); assertNotNull(subDir); NewVirtualFile subFile = (NewVirtualFile)lfs.refreshAndFindFileByIoFile(file); assertNotNull(subFile); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subDir.isDirty()); assertFalse(subFile.isDirty()); subFile.markDirty(); subDir.markDirty(); assertTrue(topDir.isDirty()); assertTrue(subFile.isDirty()); assertTrue(subDir.isDirty()); topDir.refresh(false, false); assertFalse(subFile.isDirty()); assertTrue(subDir.isDirty()); // should stay unvisited after non-recursive refresh topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile.isDirty()); assertFalse(subDir.isDirty()); }
public void testInvalidJarRootsIgnored() throws Exception { File file = IoTestUtil.createTestFile("file.txt"); String url = "jar://" + FileUtil.toSystemIndependentName(file.getPath()) + "!/"; assertNull(VirtualFileManager.getInstance().findFileByUrl(url)); }
public void testFindRoot() throws IOException { VirtualFile root = myFS.findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = myFS.findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = myFS.findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = myFS.findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = myFS.findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = myFS.findFileByPath("C:\\"); assertSame(String.valueOf(root), root, root2); VirtualFileManager fm = VirtualFileManager.getInstance(); root = fm.findFileByUrl("file://C:/"); assertNotNull(root); root2 = fm.findFileByUrl("file:///c:/"); assertSame(String.valueOf(root), root, root2); } } else if (SystemInfo.isUnix) { root = myFS.findFileByPath("/"); assertNotNull(root); assertEquals("/", root.getPath()); } root = myFS.findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); assertNotNull(getVirtualFile(jarFile)); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }
@Before public void setUp() throws Exception { myTempFile = IoTestUtil.createTestFile("repo.xml"); }
public void testSubst() throws Exception { if (!SystemInfo.isWindows) { System.err.println("Ignored: Windows required"); return; } File targetDir = createTestDir("top"); File subDir = createTestDir(targetDir, "sub"); File file = createTestFile(subDir, "test.txt"); File rootFile = createSubst(targetDir.getAbsolutePath()); VirtualDirectoryImpl.allowRootAccess(rootFile.getPath()); VirtualFile vfsRoot = myFileSystem.findFileByIoFile(rootFile); try { assertNotNull(rootFile.getPath(), vfsRoot); File substDir = new File(rootFile, subDir.getName()); File substFile = new File(substDir, file.getName()); refresh(targetDir); refresh(substDir); LocalFileSystem.WatchRequest request = watch(substDir); try { myAccept = true; FileUtil.writeToFile(file, "new content"); assertEvent(VFileContentChangeEvent.class, substFile.getAbsolutePath()); LocalFileSystem.WatchRequest request2 = watch(targetDir); try { myAccept = true; FileUtil.delete(file); assertEvent(VFileDeleteEvent.class, file.getAbsolutePath(), substFile.getAbsolutePath()); } finally { unwatch(request2); } myAccept = true; FileUtil.writeToFile(file, "re-creation"); assertEvent(VFileCreateEvent.class, substFile.getAbsolutePath()); } finally { unwatch(request); } } finally { delete(targetDir); IoTestUtil.deleteSubst(rootFile.getPath()); if (vfsRoot != null) { ((NewVirtualFile)vfsRoot).markDirty(); myFileSystem.refresh(false); } VirtualDirectoryImpl.disallowRootAccess(rootFile.getPath()); } }
public void testFindRoot() throws IOException { VirtualFile root = LocalFileSystem.getInstance().findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = LocalFileSystem.getInstance().findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = LocalFileSystem.getInstance().findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = LocalFileSystem.getInstance().findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = LocalFileSystem.getInstance().findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = LocalFileSystem.getInstance().findFileByPath("C:\\"); assertEquals(String.valueOf(root2), root, root2); } } else if (SystemInfo.isUnix) { root = LocalFileSystem.getInstance().findFileByPath("/"); assertNotNull(root); assertEquals(root.getPath(), "/"); } root = LocalFileSystem.getInstance().findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }
public void testFindRoot() throws IOException { VirtualFile root = myFS.findFileByPath("wrong_path"); assertNull(root); VirtualFile root2; if (SystemInfo.isWindows) { root = myFS.findFileByPath("\\\\unit-133"); assertNotNull(root); root2 = myFS.findFileByPath("//UNIT-133"); assertNotNull(root2); assertEquals(String.valueOf(root2), root, root2); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); root = myFS.findFileByIoFile(new File("\\\\unit-133")); assertNotNull(root); RefreshQueue.getInstance().processSingleEvent(new VFileDeleteEvent(this, root, false)); if (new File("c:").exists()) { root = myFS.findFileByPath("c:"); assertNotNull(root); assertEquals("C:/", root.getPath()); root2 = myFS.findFileByPath("C:\\"); assertSame(String.valueOf(root), root, root2); VirtualFileManager fm = VirtualFileManager.getInstance(); root = fm.findFileByUrl("file://C:/"); assertNotNull(root); root2 = fm.findFileByUrl("file:///c:/"); assertSame(String.valueOf(root), root, root2); } } else if (SystemInfo.isUnix) { root = myFS.findFileByPath("/"); assertNotNull(root); assertEquals(root.getPath(), "/"); } root = myFS.findFileByPath(""); assertNotNull(root); File jarFile = IoTestUtil.createTestJar(); root = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath() + "!/"); assertNotNull(root); root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().replace(File.separator, "//") + "!/"); assertEquals(String.valueOf(root2), root, root2); if (!SystemInfo.isFileSystemCaseSensitive) { root2 = VirtualFileManager.getInstance().findFileByUrl("jar://" + jarFile.getPath().toUpperCase(Locale.US) + "!/"); assertEquals(String.valueOf(root2), root, root2); } }