mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vfs: .jar refresh test
This commit is contained in:
@@ -15,11 +15,20 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.IoTestUtil;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.testFramework.IdeaTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual;
|
||||
|
||||
@@ -57,6 +66,38 @@ public class JarFileSystemTest extends IdeaTestCase {
|
||||
assertEquals(1, children.length);
|
||||
}
|
||||
|
||||
public void testJarRefresh() throws IOException {
|
||||
File jar = IoTestUtil.createTestJar();
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
|
||||
assertNotNull(vFile);
|
||||
|
||||
final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "entry.txt");
|
||||
assertContent(entry, "test");
|
||||
|
||||
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.writeEntry(jar, "entry.txt", "update");
|
||||
vFile.refresh(false, false);
|
||||
|
||||
assertTrue(updated.get());
|
||||
assertTrue(entry.isValid());
|
||||
assertContent(entry, "update");
|
||||
}
|
||||
|
||||
private String getJdkRtPath(String relativePath) {
|
||||
Sdk jdk = ModuleRootManager.getInstance(myModule).getSdk();
|
||||
assertNotNull(jdk);
|
||||
@@ -71,4 +112,9 @@ public class JarFileSystemTest extends IdeaTestCase {
|
||||
assertPathsEqual(path, file.getPath());
|
||||
return file;
|
||||
}
|
||||
|
||||
private static void assertContent(VirtualFile file, String expected) throws IOException {
|
||||
String content = new String(file.contentsToByteArray());
|
||||
assertEquals(expected, content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,16 +211,20 @@ public class IoTestUtil {
|
||||
@NotNull
|
||||
public static File createTestJar() throws IOException {
|
||||
File jarFile = FileUtil.createTempFile("test.", ".jar");
|
||||
writeEntry(jarFile, "entry.txt", "test");
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
public static void writeEntry(@NotNull File jarFile, @NotNull String name, @NotNull String content) throws IOException {
|
||||
JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFile));
|
||||
try {
|
||||
stream.putNextEntry(new JarEntry("entry.txt"));
|
||||
stream.write("test".getBytes("UTF-8"));
|
||||
stream.putNextEntry(new JarEntry(name));
|
||||
stream.write(content.getBytes("UTF-8"));
|
||||
stream.closeEntry();
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
return jarFile;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user