diff --git a/idea/src/org/jetbrains/kotlin/idea/framework/ui/CreateLibraryDialogBase.java b/idea/src/org/jetbrains/kotlin/idea/framework/ui/CreateLibraryDialogBase.java index 5c61d574766..9ce9ac99b5e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/framework/ui/CreateLibraryDialogBase.java +++ b/idea/src/org/jetbrains/kotlin/idea/framework/ui/CreateLibraryDialogBase.java @@ -21,7 +21,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.SeparatorWithText; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.idea.JetPluginUtil; +import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtil; import javax.swing.*; import java.awt.*; @@ -49,7 +49,7 @@ public abstract class CreateLibraryDialogBase extends DialogWrapper { init(); - compilerTextLabel.setText(compilerTextLabel.getText() + " - " + JetPluginUtil.getPluginVersion()); + compilerTextLabel.setText(compilerTextLabel.getText() + " - " + KotlinRuntimeLibraryUtil.bundledRuntimeVersion()); pathPanel = new ChooseLibraryPathPanel(defaultPath); pathPanel.addValidityListener(new ValidityListener() { diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java index 128fdfc006e..dd0d96bcc4b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java @@ -38,6 +38,7 @@ import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.ID; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.idea.JetPluginUtil; import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils; import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator; import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider; @@ -248,6 +249,26 @@ public class KotlinRuntimeLibraryUtil { } } + @NotNull + public static String bundledRuntimeVersion() { + return bundledRuntimeVersion(JetPluginUtil.getPluginVersion()); + } + + @NotNull + public static String bundledRuntimeVersion(@NotNull String pluginVersion) { + int placeToSplit = -1; + + for (int i = 0; i < pluginVersion.toCharArray().length; i++) { + char ch = pluginVersion.charAt(i); + if (Character.isLetter(ch) && i > 0 && pluginVersion.charAt(i - 1) == '.') { + placeToSplit = i - 1; + break; + } + } + + return placeToSplit != - 1 ? pluginVersion.substring(0, placeToSplit) : pluginVersion; + } + @Nullable public static VirtualFile getLocalJar(@Nullable VirtualFile kotlinRuntimeJar) { if (kotlinRuntimeJar == null) return null; diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeNotification.java b/idea/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeNotification.java index fa53fc731a2..b9fb07f17a4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeNotification.java +++ b/idea/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeNotification.java @@ -84,7 +84,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent // user already clicked suppress if (pluginVersion.equals(PropertiesComponent.getInstance(myProject).getValue(SUPPRESSED_PROPERTY_NAME))) return; - Collection versionedOutdatedLibraries = findOutdatedKotlinLibraries(myProject, pluginVersion); + Collection versionedOutdatedLibraries = findOutdatedKotlinLibraries(myProject); if (versionedOutdatedLibraries.isEmpty()) { return; } @@ -130,7 +130,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if ("update".equals(event.getDescription())) { - Collection versionedOutdatedLibraries = findOutdatedKotlinLibraries(myProject, pluginVersion); + Collection versionedOutdatedLibraries = findOutdatedKotlinLibraries(myProject); Collection outdatedLibraries = extractLibraries(versionedOutdatedLibraries); KotlinRuntimeLibraryUtil.updateLibraries(myProject, outdatedLibraries); suggestDeleteKotlinJsIfNeeded(outdatedLibraries); @@ -229,7 +229,7 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent } @NotNull - private static Collection findOutdatedKotlinLibraries(@NotNull Project project, @NotNull String pluginVersion) { + private static Collection findOutdatedKotlinLibraries(@NotNull Project project) { List outdatedLibraries = Lists.newArrayList(); for (Library library : KotlinRuntimeLibraryUtil.findKotlinLibraries(project)) { @@ -244,10 +244,11 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent } String libraryVersion = libraryVersionProperties.getVersionString(); - boolean isOutdated = "snapshot".equals(libraryVersion) - || libraryVersion == null - || libraryVersion.startsWith("internal-") != pluginVersion.startsWith("internal-") - || VersionComparatorUtil.compare(pluginVersion, libraryVersion) > 0; + String runtimeVersion = KotlinRuntimeLibraryUtil.bundledRuntimeVersion(); + + boolean isOutdated = libraryVersion == null + || libraryVersion.startsWith("internal-") != runtimeVersion.startsWith("internal-") + || VersionComparatorUtil.compare(runtimeVersion, libraryVersion) > 0; if (isOutdated) { outdatedLibraries.add(new VersionedLibrary(library, libraryVersion)); @@ -257,7 +258,6 @@ public class OutdatedKotlinRuntimeNotification extends AbstractProjectComponent return outdatedLibraries; } - @NotNull public static Runnable showRuntimeJarNotFoundDialog(@NotNull final Project project, final @NotNull String jarName) { return new Runnable() { diff --git a/idea/tests/org/jetbrains/kotlin/idea/OutdatedKotlinRuntimeNotificationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/OutdatedKotlinRuntimeNotificationTest.kt new file mode 100644 index 00000000000..1ebe3e29db5 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/OutdatedKotlinRuntimeNotificationTest.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2015 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 org.jetbrains.kotlin.idea + +import junit.framework.TestCase +import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtil +import org.jetbrains.kotlin.idea.versions.OutdatedKotlinRuntimeNotification +import org.junit.Assert + + +public class KotlinRuntimeLibraryUtilTest : TestCase() { + public fun testKotlinLibraryRelevantVersion() { + test("0.10.2013", "0.10.2013") + test("0.10.M.2013", "0.10") + test("0.10.2.Idea140.2013", "0.10.2") + test("0.11.1995.1.M.Idea140.2013", "0.11.1995.1") + test("Some.0.10.2", "Some.0.10.2") + test("@snapshot@", "@snapshot@") + test("snapshot", "snapshot") + test("internal-0.1.2", "internal-0.1.2") + test(".0.1.2", ".0.1.2") + test("0.1.2.", "0.1.2.") + } + + private fun test(version: String, expected: String) { + Assert.assertEquals(expected, KotlinRuntimeLibraryUtil.bundledRuntimeVersion(version)) + } +} \ No newline at end of file