diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdPresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdPresentationProvider.java index 9cc9b9d0262..90d2a0a9a46 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdPresentationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdPresentationProvider.java @@ -17,15 +17,18 @@ package org.jetbrains.jet.plugin.framework; import com.intellij.framework.library.LibraryVersionProperties; +import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil; import com.intellij.openapi.roots.libraries.LibraryPresentationProvider; +import com.intellij.openapi.vfs.JarFile; +import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.plugin.JetIcons; -import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil; import org.jetbrains.jet.utils.PathUtil; import javax.swing.*; +import java.io.IOException; import java.util.List; public class JSLibraryStdPresentationProvider extends CachingLibraryPresentationProvider { @@ -58,7 +61,15 @@ public class JSLibraryStdPresentationProvider extends CachingLibraryPresentation for (VirtualFile root : classesRoots) { if (root.getName().equals(PathUtil.JS_LIB_JAR_NAME)) { assert JsHeaderLibraryPresentationProvider.getInstance().detect(classesRoots) != null : "StdLib should also be detected as headers library"; - return new LibraryVersionProperties(KotlinRuntimeLibraryUtil.getLibraryVersion(root)); + + try { + JarFile zipFile = JarFileSystem.getInstance().getJarFile(root); + String version = JarVersionDetectionUtil.detectJarVersion(zipFile); + return new LibraryVersionProperties(version); + } + catch (IOException e) { + return null; + } } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java index 0089d2a4797..5ea9bbcebeb 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java @@ -18,16 +18,19 @@ package org.jetbrains.jet.plugin.framework; import com.intellij.framework.library.LibraryVersionProperties; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryPresentationProvider; +import com.intellij.openapi.vfs.JarFile; +import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.plugin.JetIcons; -import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil; import org.jetbrains.jet.utils.PathUtil; import javax.swing.*; +import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -51,7 +54,14 @@ public class JavaRuntimePresentationProvider extends CachingLibraryPresentationP public LibraryVersionProperties detect(@NotNull List classesRoots) { VirtualFile stdJar = getRuntimeJar(classesRoots); if (stdJar != null) { - return new LibraryVersionProperties(KotlinRuntimeLibraryUtil.getLibraryVersion(stdJar)); + try { + JarFile zipFile = JarFileSystem.getInstance().getJarFile(stdJar); + String version = JarVersionDetectionUtil.detectJarVersion(zipFile); + return new LibraryVersionProperties(version); + } + catch (IOException e) { + return null; + } } return null; diff --git a/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java b/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java index 720187e9a84..0313f491d65 100644 --- a/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java @@ -33,7 +33,6 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.packaging.impl.elements.ManifestFileUtil; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.search.GlobalSearchScope; @@ -54,12 +53,8 @@ import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.Set; -import java.util.jar.Attributes; -import java.util.jar.JarFile; public class KotlinRuntimeLibraryUtil { - public static final String UNKNOWN_VERSION = "UNKNOWN"; - private KotlinRuntimeLibraryUtil() {} @NotNull @@ -168,20 +163,6 @@ public class KotlinRuntimeLibraryUtil { }); } - @Nullable - public static String getLibraryVersion(@Nullable VirtualFile kotlinStdJar) { - if (kotlinStdJar == null) return null; - VirtualFile manifestFile = kotlinStdJar.findFileByRelativePath(JarFile.MANIFEST_NAME); - if (manifestFile != null) { - Attributes attributes = ManifestFileUtil.readManifest(manifestFile).getMainAttributes(); - if (attributes.containsKey(Attributes.Name.IMPLEMENTATION_VERSION)) { - return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); - } - } - - return UNKNOWN_VERSION; - } - @Nullable private static VirtualFile getKotlinRuntimeJar(@NotNull Project project) { PsiClass markerClass = getKotlinRuntimeMarkerClass(ProjectScope.getAllScope(project));