diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSHeadersPresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/JSHeadersPresentationProvider.java index cebeb6b77cd..857791169a2 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSHeadersPresentationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSHeadersPresentationProvider.java @@ -22,6 +22,8 @@ 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.util.List; @@ -44,9 +46,15 @@ public class JSHeadersPresentationProvider extends LibraryPresentationProvider classesRoots) { - // TODO: Ask for better api of library detection if (classesRoots.isEmpty()) { - return new LibraryVersionProperties("Unknown"); + // TODO: Deprecated - remove after some iterations + return new LibraryVersionProperties(null); + } + + for (VirtualFile root : classesRoots) { + if (root.getName().equals(PathUtil.JS_LIB_JAR_NAME)) { + return new LibraryVersionProperties(KotlinRuntimeLibraryUtil.getLibraryVersion(root)); + } } return null; diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java index 2b792f2bd76..f8adb5c5ffa 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryDescription.java @@ -94,6 +94,7 @@ public class JSLibraryDescription extends CustomLibraryDescription { return new NewLibraryConfiguration(libraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) { @Override public void addRoots(@NotNull LibraryEditor editor) { + editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); editor.addRoot(libraryFileUrl, OrderRootType.SOURCES); } }; diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java index ccd815764ab..c39f9e0dc81 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimePresentationProvider.java @@ -22,6 +22,7 @@ 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.*; @@ -47,8 +48,7 @@ public class JavaRuntimePresentationProvider extends LibraryPresentationProvider public LibraryVersionProperties detect(@NotNull List classesRoots) { for (VirtualFile root : classesRoots) { if (root.getName().equals(PathUtil.KOTLIN_JAVA_RUNTIME_JAR)) { - // TODO: Detect library version - return new LibraryVersionProperties("Unknown"); + return new LibraryVersionProperties(KotlinRuntimeLibraryUtil.getLibraryVersion(root)); } } diff --git a/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java b/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java index b6641a0390a..606710fdd8c 100644 --- a/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/versions/KotlinRuntimeLibraryUtil.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.impl.elements.ManifestFileUtil; import com.intellij.psi.JavaPsiFacade; @@ -178,15 +179,30 @@ public class KotlinRuntimeLibraryUtil { @Nullable public static String getRuntimeVersion(@NotNull Project project) { - VirtualFile kotlinRuntimeJar = getKotlinRuntimeJar(project); - if (kotlinRuntimeJar == null) return null; - VirtualFile manifestFile = kotlinRuntimeJar.findFileByRelativePath(JarFile.MANIFEST_NAME); + return getLibraryVersion(getKotlinRuntimeJar(project)); + } + + @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); } } + + VirtualFile buildVersionFile = kotlinStdJar.findFileByRelativePath("META-INF/build.txt"); + if (buildVersionFile != null) { + try { + return VfsUtilCore.loadText(buildVersionFile); + } + catch (IOException e) { + // Fall to default return + } + } + return UNKNOWN_VERSION; }