diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java index e4422331e055..8c40cb4c9c5a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ClassesOrderRootTypeUIFactory.java @@ -23,7 +23,7 @@ import com.intellij.openapi.projectRoots.ui.SdkPathEditor; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.ui.components.JBList; import javax.swing.*; diff --git a/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java b/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java index 2a4a555ad051..a5d3f04f7fb3 100644 --- a/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java +++ b/java/java-impl/src/com/intellij/ide/navigationToolbar/JavaNavBarExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import com.intellij.lang.LangBundle; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.presentation.java.ClassPresentationUtil; diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java index b04ea71d9d6f..713d15931f21 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaSdkImpl.java @@ -36,7 +36,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; @@ -665,12 +665,10 @@ public class JavaSdkImpl extends JavaSdk { List result = ContainerUtil.newArrayList(); VirtualFileManager fileManager = VirtualFileManager.getInstance(); - String path = file.getPath(); - if (JrtFileSystem.isModularJdk(path)) { - String url = VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path) + JrtFileSystem.SEPARATOR); - for (String module : JrtFileSystem.listModules(path)) { - ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url + module)); - } + VirtualFile jrt = fileManager.findFileByUrl( + VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(file.getPath()) + JrtFileSystem.SEPARATOR)); + if (jrt != null) { + ContainerUtil.addAll(result, jrt.getChildren()); } for (File root : JavaSdkUtil.getJdkClassesRoots(file, isJre)) { diff --git a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java similarity index 74% rename from java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java rename to java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java index d9f9c10f9a17..100e4ccb0649 100644 --- a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystem.java +++ b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtFileSystemImpl.java @@ -23,18 +23,22 @@ import com.intellij.notification.Notifications; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.OrderRootType; -import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.impl.ArchiveHandler; -import com.intellij.openapi.vfs.newvfs.*; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.newvfs.BulkFileListener; +import com.intellij.openapi.vfs.newvfs.NewVirtualFile; +import com.intellij.openapi.vfs.newvfs.RefreshQueue; +import com.intellij.openapi.vfs.newvfs.VfsImplUtil; import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.containers.ContainerUtil; @@ -42,36 +46,19 @@ import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.*; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; import java.util.stream.Stream; import static com.intellij.util.containers.ContainerUtil.newTroveMap; -public class JrtFileSystem extends ArchiveFileSystem { - public static final String PROTOCOL = StandardFileSystems.JRT_PROTOCOL; - public static final String PROTOCOL_PREFIX = StandardFileSystems.JRT_PROTOCOL_PREFIX; - public static final String SEPARATOR = JarFileSystem.JAR_SEPARATOR; - - private static final boolean SUPPORTED = - SystemInfo.isJavaVersionAtLeast("9") || SystemInfo.isJavaVersionAtLeast("1.8") && !SystemInfo.isJavaVersionAtLeast("1.9"); - - private static final URI ROOT_URI = URI.create("jrt:/"); - +public class JrtFileSystemImpl extends JrtFileSystem { private final Map myHandlers = newTroveMap(FileUtil.PATH_HASHING_STRATEGY); private final AtomicBoolean mySubscribed = new AtomicBoolean(false); - public JrtFileSystem() { + public JrtFileSystemImpl() { scheduleConfiguredSdkCheck(); } @@ -213,51 +200,4 @@ public class JrtFileSystem extends ArchiveFileSystem { protected boolean isCorrectFileType(@NotNull VirtualFile local) { return isModularJdk(FileUtil.toSystemDependentName(local.getPath())); } - - public static boolean isSupported() { - return SUPPORTED; - } - - public static boolean isModularJdk(@NotNull String homePath) { - return new File(homePath, "lib/modules").exists() && new File(homePath, "jrt-fs.jar").isFile(); - } - - public static boolean isRoot(@NotNull VirtualFile file) { - return file.getParent() == null && file.getFileSystem() instanceof JrtFileSystem; - } - - public static boolean isModuleRoot(@NotNull VirtualFile file) { - VirtualFile parent = file.getParent(); - return parent != null && isRoot(parent); - } - - @NotNull - public static List listModules(@NotNull String path) { - try { - Path root = getFileSystem(path).getPath("/modules"); - return Files.list(root).map(p -> p.getFileName().toString()).collect(Collectors.toList()); - } - catch (IOException | InvalidPathException e) { - Logger.getInstance(JrtFileSystem.class).warn(path, e); - return Collections.emptyList(); - } - } - - static FileSystem getFileSystem(String path) throws IOException { - try { - if (SystemInfo.isJavaVersionAtLeast("9")) { - return FileSystems.newFileSystem(ROOT_URI, Collections.singletonMap("java.home", path)); - } - else { - File file = new File(path, "jrt-fs.jar"); - if (!file.exists()) throw new IOException("Missing provider: " + file); - URL url = file.toURI().toURL(); - ClassLoader loader = new URLClassLoader(new URL[]{url}, null); - return FileSystems.newFileSystem(ROOT_URI, Collections.emptyMap(), loader); - } - } - catch (Error e) { - throw new IOException("Error mounting JRT filesystem at " + path, e); - } - } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java index 8e327d6e29cc..b42c549f9e73 100644 --- a/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java +++ b/java/java-impl/src/com/intellij/openapi/vfs/impl/jrt/JrtHandler.java @@ -15,20 +15,27 @@ */ package com.intellij.openapi.vfs.impl.jrt; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.impl.ArchiveHandler; import com.intellij.reference.SoftReference; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.Map; class JrtHandler extends ArchiveHandler { + private static final URI ROOT_URI = URI.create("jrt:/"); + private SoftReference myFileSystem; public JrtHandler(@NotNull String path) { @@ -38,8 +45,23 @@ class JrtHandler extends ArchiveHandler { private synchronized FileSystem getFileSystem() throws IOException { FileSystem fs = SoftReference.dereference(myFileSystem); if (fs == null) { - fs = JrtFileSystem.getFileSystem(getFile().getPath()); - myFileSystem = new SoftReference<>(fs); + String path = getFile().getPath(); + try { + if (SystemInfo.isJavaVersionAtLeast("9")) { + fs = FileSystems.newFileSystem(ROOT_URI, Collections.singletonMap("java.home", path)); + } + else { + File file = new File(path, "jrt-fs.jar"); + if (!file.exists()) throw new IOException("Missing provider: " + file); + URL url = file.toURI().toURL(); + ClassLoader loader = new URLClassLoader(new URL[]{url}, null); + fs = FileSystems.newFileSystem(ROOT_URI, Collections.emptyMap(), loader); + } + myFileSystem = new SoftReference<>(fs); + } + catch (RuntimeException | Error e) { + throw new IOException("Error mounting JRT filesystem at " + path, e); + } } return fs; } diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java index 784da4e17cdd..f6b3baa8b3a7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java +++ b/java/java-impl/src/com/intellij/psi/impl/JavaDirectoryIconProvider.java @@ -27,7 +27,7 @@ import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.roots.ui.configuration.SourceRootPresentation; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem; import com.intellij.psi.JavaDirectoryService; import com.intellij.psi.PsiDirectory; 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 73a738088ff5..fca53f14df83 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/vfs/JrtFileSystemTest.java @@ -17,7 +17,7 @@ package com.intellij.openapi.vfs; import com.intellij.JavaTestUtil; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.vfs.impl.jrt.JrtFileSystem; +import com.intellij.openapi.vfs.jrt.JrtFileSystem; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.rules.TempDirectory; import org.junit.Before; @@ -64,9 +64,10 @@ public class JrtFileSystemTest extends BareTestFixtureTestCase { } @Test - public void moduleListing() { - String path = myTempDir.getRoot().getPath(); - assertThat(JrtFileSystem.listModules(path)).containsExactlyInAnyOrder("java.base", "test1"); + public void nonRoot() { + String url = VirtualFileManager.constructUrl(JrtFileSystem.PROTOCOL, JavaTestUtil.getJavaTestDataPath() + JrtFileSystem.SEPARATOR); + VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(url); + assertThat(root).isNull(); } @Test diff --git a/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java b/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java new file mode 100644 index 000000000000..0b9a75ff10cc --- /dev/null +++ b/java/openapi/src/com/intellij/openapi/vfs/jrt/JrtFileSystem.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.vfs.jrt; + +import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.vfs.StandardFileSystems; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem; +import com.intellij.util.io.URLUtil; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public abstract class JrtFileSystem extends ArchiveFileSystem { + public static final String PROTOCOL = StandardFileSystems.JRT_PROTOCOL; + public static final String PROTOCOL_PREFIX = StandardFileSystems.JRT_PROTOCOL_PREFIX; + public static final String SEPARATOR = URLUtil.JAR_SEPARATOR; + + private static final boolean SUPPORTED = + SystemInfo.isJavaVersionAtLeast("9") || SystemInfo.isJavaVersionAtLeast("1.8") && !SystemInfo.isJavaVersionAtLeast("1.9"); + + public static boolean isSupported() { + return SUPPORTED; + } + + public static boolean isModularJdk(@NotNull String homePath) { + return new File(homePath, "lib/modules").exists() && new File(homePath, "jrt-fs.jar").isFile(); + } + + public static boolean isRoot(@NotNull VirtualFile file) { + return file.getParent() == null && file.getFileSystem() instanceof JrtFileSystem; + } + + public static boolean isModuleRoot(@NotNull VirtualFile file) { + VirtualFile parent = file.getParent(); + return parent != null && isRoot(parent); + } +} \ No newline at end of file diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index fb9d585f9942..cb621adf970f 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -46,7 +46,8 @@ - com.intellij.openapi.vfs.impl.jrt.JrtFileSystem + com.intellij.openapi.vfs.jrt.JrtFileSystem + com.intellij.openapi.vfs.impl.jrt.JrtFileSystemImpl com.intellij.util.xml.impl.JavaDomApplicationComponent