Sdk (@NotNull String name, @NotNull String path) { Sdk fromLegacyPath = createMockJdkFromLegacyPath(path); if (fromLegacyPath != null) { return fromLegacyPath; } JavaSdk javaSdk = JavaSdk.getInstance(); if (javaSdk == null) { throw new AssertionError("The test uses classes from Java plugin but Java plugin wasn't loaded; make sure that Java plugin " + "classes are included into classpath and that the plugin isn't disabled " + "by 'idea.load.plugins' or 'idea.load.plugins.id' system properties"); } MultiMap<OrderRootType, VirtualFile> roots = MultiMap.create(); SdkModificator sdkModificator = new SdkModificator() { @NotNull @Override public String getName() { throw new UnsupportedOperationException(); } @Override public void setName(@NotNull String name1) { throw new UnsupportedOperationException(); } @Override public String getHomePath() { throw new UnsupportedOperationException(); } @Override public void setHomePath(String path1) { throw new UnsupportedOperationException(); } @Override public String getVersionString() { throw new UnsupportedOperationException(); } @Override public void setVersionString(String versionString) { throw new UnsupportedOperationException(); } @Override public SdkAdditionalData getSdkAdditionalData() { throw new UnsupportedOperationException(); } @Override public void setSdkAdditionalData(SdkAdditionalData data) { throw new UnsupportedOperationException(); } @Override public VirtualFile @NotNull [] getRoots(@NotNull OrderRootType rootType) { return roots.get(rootType).toArray(VirtualFile.EMPTY_ARRAY); } @Override public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) { throw new UnsupportedOperationException(); } @Override public void removeRoots(@NotNull OrderRootType rootType) { throw new UnsupportedOperationException(); } @Override public void removeAllRoots() { throw new UnsupportedOperationException(); } @Override public void commitChanges() { throw new UnsupportedOperationException(); } @Override public boolean isWritable() { throw new UnsupportedOperationException(); } @Override public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) { roots.putValue(rootType, root); } }; String sdkPath; if (path.endsWith(".jar!/")) { sdkPath = PathUtil.getParentPath(path); sdkModificator.addRoot("jar://"+path, OrderRootType.CLASSES); } else { sdkPath = PathUtil.toSystemIndependentName(path); File[] jars = new File(path, "jre/lib").listFiles(f -> f.getName().endsWith(".jar")); if (jars != null) { for (File jar : jars) { sdkModificator.addRoot("jar://"+PathUtil.toSystemIndependentName(jar.getPath())+"!/", OrderRootType.CLASSES); } } } // only Mock JDKs 1.4/1.7 have src.zip if (path.endsWith("mockJDK-1.7") || path.endsWith("mockJDK-1.4")) { if (new File(path, "src.zip").exists()) { sdkModificator.addRoot("jar://"+PathUtil.toSystemIndependentName(path)+"/src.zip!/", OrderRootType.SOURCES); } } JavaSdkImpl.attachJdkAnnotations(sdkModificator); return new MockSdk(name, sdkPath, name, roots, () -> JavaSdk.getInstance()); }