From 2a3d27b18cd0a0760c00fbb03e2b580e4ef0997e Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 17 Nov 2016 17:44:20 +0100 Subject: [PATCH] [java] uses "JDK_HOME/release" file to watch for JDK updates --- .../openapi/vfs/impl/jrt/JrtFileSystemImpl.java | 15 ++++++--------- .../intellij/openapi/vfs/JrtFileSystemTest.java | 2 ++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java index 100e4ccb0649..891d20d2d5e7 100644 --- a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java +++ b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java @@ -132,10 +132,9 @@ public class JrtFileSystemImpl extends JrtFileSystem { if (handler == null) { handler = isSupported() ? new JrtHandler(homePath) : new JrtHandlerStub(homePath); myHandlers.put(homePath, handler); - ApplicationManager.getApplication().invokeLater(() -> { - VirtualFile modules = LocalFileSystem.getInstance().refreshAndFindFileByPath(homePath + "/lib/modules"); - if (modules != null && modules.isDirectory()) modules.getChildren(); - }, ModalityState.defaultModalityState()); + ApplicationManager.getApplication().invokeLater( + () -> LocalFileSystem.getInstance().refreshAndFindFileByPath(homePath + "/release"), + ModalityState.defaultModalityState()); } return handler; } @@ -152,11 +151,9 @@ public class JrtFileSystemImpl extends JrtFileSystem { for (VFileEvent event : events) { if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) { VirtualFile file = event.getFile(); - if (file != null) { - String homePath = null; - if ("modules".equals(file.getName())) homePath = file.getParent().getParent().getPath(); - else if ("jimage".equals(file.getExtension())) homePath = file.getParent().getParent().getParent().getPath(); - if (homePath != null && myHandlers.remove(homePath) != null) { + if (file != null && "release".equals(file.getName())) { + String homePath = file.getParent().getPath(); + if (myHandlers.remove(homePath) != null) { VirtualFile root = findFileByPath(composeRootPath(homePath)); if (root != null) { ((NewVirtualFile)root).markDirtyRecursively(); diff --git a/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java b/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java index fca53f14df83..49ffaae3c71d 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java @@ -52,6 +52,7 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { @Before public void setUp() throws IOException { myTestData = Paths.get(JavaTestUtil.getJavaTestDataPath(), "jrt"); + Files.write(myTempDir.getRoot().toPath().resolve("release"), "JAVA_VERSION=9\n".getBytes(CharsetToolkit.UTF8_CHARSET)); Files.copy(myTestData.resolve("jrt-fs.jar"), myTempDir.getRoot().toPath().resolve("jrt-fs.jar")); Path lib = Files.createDirectory(myTempDir.getRoot().toPath().resolve("lib")); Files.copy(myTestData.resolve("image1"), lib.resolve("modules")); @@ -94,6 +95,7 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { Path modules = myTempDir.getRoot().toPath().resolve("lib/modules"); Files.move(modules, myTempDir.getRoot().toPath().resolve("lib/modules.bak")); Files.copy(myTestData.resolve("image2"), modules, StandardCopyOption.REPLACE_EXISTING); + Files.write(myTempDir.getRoot().toPath().resolve("release"), "JAVA_VERSION=9.0.1\n".getBytes(CharsetToolkit.UTF8_CHARSET)); VirtualFile local = LocalFileSystem.getInstance().findFileByIoFile(myTempDir.getRoot()); assertThat(local).isNotNull();