diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt index 3de77cf68db..e68655e3c64 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinExternalSystemSyncListener.kt @@ -22,7 +22,7 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerComponent class KotlinExternalSystemSyncListener : ExternalSystemTaskNotificationListenerAdapter() { - override fun onStart(id: ExternalSystemTaskId) { + override fun onStart(id: ExternalSystemTaskId, workingDir: String) { if (id.type == ExternalSystemTaskType.RESOLVE_PROJECT) { id.findProject()?.let { project -> KotlinConfigurationCheckerComponent.getInstance(project).syncStarted() diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt index e12df720f38..45cc357da73 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJavaModuleConfigurator.kt @@ -23,6 +23,7 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.impl.libraries.LibraryEx import com.intellij.openapi.roots.libraries.Library import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments @@ -31,13 +32,13 @@ import org.jetbrains.kotlin.config.TargetPlatformKind import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder import org.jetbrains.kotlin.idea.facet.getOrCreateFacet import org.jetbrains.kotlin.idea.facet.initializeIfNeeded +import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.sdk import org.jetbrains.kotlin.idea.util.projectStructure.version import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor -import org.jetbrains.kotlin.idea.versions.isKotlinJavaRuntime import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform @@ -73,12 +74,13 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr override fun getLibraryJarDescriptors(sdk: Sdk?): List { var result = listOf( - LibraryJarDescriptor.RUNTIME_JAR, - LibraryJarDescriptor.RUNTIME_SRC_JAR, - LibraryJarDescriptor.REFLECT_JAR, - LibraryJarDescriptor.REFLECT_SRC_JAR, - LibraryJarDescriptor.TEST_JAR, - LibraryJarDescriptor.TEST_SRC_JAR) + LibraryJarDescriptor.RUNTIME_JAR, + LibraryJarDescriptor.RUNTIME_SRC_JAR, + LibraryJarDescriptor.REFLECT_JAR, + LibraryJarDescriptor.REFLECT_SRC_JAR, + LibraryJarDescriptor.TEST_JAR, + LibraryJarDescriptor.TEST_SRC_JAR + ) val sdkVersion = sdk?.version ?: return result if (sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7)) { result += listOf(LibraryJarDescriptor.RUNTIME_JDK7_JAR, LibraryJarDescriptor.RUNTIME_JDK7_SOURCES_JAR) @@ -90,8 +92,8 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr return result } - override val libraryMatcher: (Library) -> Boolean - get() = ::isKotlinJavaRuntime + override val libraryMatcher: (Library) -> Boolean = + { library -> JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null } override fun configureKotlinSettings(modules: List) { val project = modules.firstOrNull()?.project ?: return @@ -102,8 +104,7 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr Kotlin2JvmCompilerArgumentsHolder.getInstance(project).update { jvmTarget = "1.8" } - } - else { + } else { for (module in modules) { val sdkVersion = module.sdk?.version if (sdkVersion != null && sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8)) { @@ -118,19 +119,19 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr } override fun configureModule( - module: Module, - classesPath: String, - sourcesPath: String, - collector: NotificationMessageCollector, - forceJarState: FileState?, - useBundled: Boolean + module: Module, + classesPath: String, + sourcesPath: String, + collector: NotificationMessageCollector, + forceJarState: FileState?, + useBundled: Boolean ) { super.configureModule(module, classesPath, sourcesPath, collector, forceJarState, useBundled) addStdlibToJavaModuleInfo(module, collector) } companion object { - val NAME = "java" + const val NAME = "java" val instance: KotlinJavaModuleConfigurator get() = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME, KotlinJavaModuleConfigurator::class.java) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJsModuleConfigurator.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJsModuleConfigurator.kt index d4c2a03be30..e57dfa7b9c9 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJsModuleConfigurator.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/KotlinJsModuleConfigurator.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.idea.framework.JSLibraryType import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.versions.LibraryJarDescriptor -import org.jetbrains.kotlin.idea.versions.isKotlinJsRuntime import org.jetbrains.kotlin.js.JavaScript import org.jetbrains.kotlin.js.resolve.JsPlatform import org.jetbrains.kotlin.resolve.TargetPlatform @@ -60,10 +59,12 @@ open class KotlinJsModuleConfigurator : KotlinWithLibraryConfigurator() { get() = JSLibraryStdDescription.JAVA_SCRIPT_LIBRARY_CREATION override fun getLibraryJarDescriptors(sdk: Sdk?): List = - listOf(LibraryJarDescriptor.JS_STDLIB_JAR, - LibraryJarDescriptor.JS_STDLIB_SRC_JAR) + listOf( + LibraryJarDescriptor.JS_STDLIB_JAR, + LibraryJarDescriptor.JS_STDLIB_SRC_JAR + ) - override val libraryMatcher: (Library) -> Boolean = ::isKotlinJsRuntime + override val libraryMatcher: (Library) -> Boolean = { library -> JsLibraryStdDetectionUtil.hasJsStdlibJar(library) } override val libraryType: LibraryType? get() = JSLibraryType.getInstance() diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt index 45187f23c5d..3e5e8113932 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt @@ -37,10 +37,13 @@ import java.util.concurrent.atomic.AtomicInteger class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectComponent(project) { private val syncDepth = AtomicInteger() - @Volatile private var notificationPostponed = false + + @Volatile + private var notificationPostponed = false init { - NotificationsConfiguration.getNotificationsConfiguration().register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true) + NotificationsConfiguration.getNotificationsConfiguration() + .register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true) val connection = project.messageBus.connect() connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { @@ -50,8 +53,10 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom DumbService.getInstance(myProject).waitForSmartMode() if (!isSyncing) { notificationPostponed = false - showConfigureKotlinNotificationIfNeeded(myProject, - collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(myProject))) + showConfigureKotlinNotificationIfNeeded( + myProject, + collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(myProject)) + ) } } } @@ -81,8 +86,7 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom if (!isSyncing) { val excludeModules = collectModulesWithOutdatedRuntime(libraries) showConfigureKotlinNotificationIfNeeded(myProject, excludeModules) - } - else { + } else { notificationPostponed = true } } @@ -100,9 +104,9 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom } companion object { - val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project" + const val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project" - fun getInstance(project: Project): KotlinConfigurationCheckerComponent - = project.getComponent(KotlinConfigurationCheckerComponent::class.java) + fun getInstance(project: Project): KotlinConfigurationCheckerComponent = + project.getComponent(KotlinConfigurationCheckerComponent::class.java) } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt index 02d295780b4..3f420a20f35 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/KotlinJVMRuntimeLibraryUtil.kt @@ -27,15 +27,18 @@ fun updateLibraries(project: Project, libraries: Collection) { "Automatic library version update for Maven and Gradle projects is currently unsupported. " + "Please update your build scripts manually.", "Update Kotlin Runtime Library", - Messages.getErrorIcon()) + Messages.getErrorIcon() + ) return } - val kJvmConfigurator = getConfiguratorByName(KotlinJavaModuleConfigurator.NAME) as KotlinJavaModuleConfigurator? ?: - error("Configurator with given name doesn't exists: " + KotlinJavaModuleConfigurator.NAME) + val kJvmConfigurator = + getConfiguratorByName(KotlinJavaModuleConfigurator.NAME) as KotlinJavaModuleConfigurator? + ?: error("Configurator with given name doesn't exists: " + KotlinJavaModuleConfigurator.NAME) - val kJsConfigurator = getConfiguratorByName(KotlinJsModuleConfigurator.NAME) as KotlinJsModuleConfigurator? ?: - error("Configurator with given name doesn't exists: " + KotlinJsModuleConfigurator.NAME) + val kJsConfigurator = + getConfiguratorByName(KotlinJsModuleConfigurator.NAME) as KotlinJsModuleConfigurator? + ?: error("Configurator with given name doesn't exists: " + KotlinJsModuleConfigurator.NAME) val collector = createConfigureKotlinNotificationCollector(project) val sdk = ProjectRootManager.getInstance(project).projectSdk @@ -56,9 +59,10 @@ fun updateLibraries(project: Project, libraries: Collection) { } private fun updateJar( - project: Project, - library: Library, - libraryJarDescriptor: LibraryJarDescriptor) { + project: Project, + library: Library, + libraryJarDescriptor: LibraryJarDescriptor +) { val fileToReplace = libraryJarDescriptor.findExistingJar(library) if (fileToReplace == null && !libraryJarDescriptor.shouldExist) { @@ -77,9 +81,11 @@ private fun updateJar( val newVFile = try { replaceFile(jarPath, jarFileToReplace) } catch (e: IOException) { - Messages.showErrorDialog(project, - "Failed to update $jarPath: ${e.message}", - "Library update failed") + Messages.showErrorDialog( + project, + "Failed to update $jarPath: ${e.message}", + "Library update failed" + ) return } @@ -92,8 +98,7 @@ private fun updateJar( } val newRoot = JarFileSystem.getInstance().getJarRootForLocalFile(newVFile)!! model.addRoot(newRoot, libraryJarDescriptor.orderRootType) - } - finally { + } finally { model.commit() } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt index 75d41bcb7c3..744dabb2f59 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/versions/OutdatedKotlinRuntimeChecker.kt @@ -57,7 +57,7 @@ fun findOutdatedKotlinLibraries(project: Project): List { return outdatedLibraries } -fun getOutdatedRuntimeLibraryVersion(library: Library): String? { +private fun getOutdatedRuntimeLibraryVersion(library: Library): String? { val libraryVersion = getKotlinLibraryVersion(library) ?: return null val runtimeVersion = bundledRuntimeVersion() @@ -65,23 +65,22 @@ fun getOutdatedRuntimeLibraryVersion(library: Library): String? { } private fun getKotlinLibraryVersion(library: Library): String? = - JavaRuntimeDetectionUtil.getJavaRuntimeVersion(library) ?: - JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library) + JavaRuntimeDetectionUtil.getJavaRuntimeVersion(library) ?: JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library) fun findKotlinRuntimeLibrary(module: Module, predicate: (Library) -> Boolean = ::isKotlinRuntime): Library? { val orderEntries = ModuleRootManager.getInstance(module).orderEntries.filterIsInstance() return orderEntries.asSequence() - .mapNotNull { it.library } - .firstOrNull(predicate) + .mapNotNull { it.library } + .firstOrNull(predicate) } -fun isKotlinRuntime(library: Library) = isKotlinJavaRuntime(library) || isKotlinJsRuntime(library) +private fun isKotlinRuntime(library: Library) = isKotlinJavaRuntime(library) || isKotlinJsRuntime(library) -fun isKotlinJavaRuntime(library: Library) = - JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null +private fun isKotlinJavaRuntime(library: Library) = + JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null -fun isKotlinJsRuntime(library: Library) = - JsLibraryStdDetectionUtil.hasJsStdlibJar(library) +private fun isKotlinJsRuntime(library: Library) = + JsLibraryStdDetectionUtil.hasJsStdlibJar(library) fun collectModulesWithOutdatedRuntime(libraries: List): List = libraries.flatMap { it.usedInModules } @@ -96,46 +95,50 @@ fun notifyOutdatedKotlinRuntime(project: Project, outdatedLibraries: Collection< val libraryName = versionedLibrary.library.name "

Your version of Kotlin runtime in '$libraryName' library is $readableVersion, while plugin version is $pluginVersion.

" + - "

Runtime library should be updated to avoid compatibility problems.

" + - "

Update Runtime Ignore

" - } - else { + "

Runtime library should be updated to avoid compatibility problems.

" + + "

Update Runtime Ignore

" + } else { val libraryNames = outdatedLibraries.joinToString { it.library.name ?: "unknown library" } "

Version of Kotlin runtime is outdated in several libraries ($libraryNames). Plugin version is $pluginVersion.

" + - "

Runtime libraries should be updated to avoid compatibility problems.

" + - "

Update All Ignore

" + "

Runtime libraries should be updated to avoid compatibility problems.

" + + "

Update All Ignore

" } - Notifications.Bus.notify(Notification(OUTDATED_RUNTIME_GROUP_DISPLAY_ID, "Outdated Kotlin Runtime", message, - NotificationType.WARNING, NotificationListener { notification, event -> - if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) { - when { - "update" == event.description -> { - val outdatedLibraries = findOutdatedKotlinLibraries(project).map { it.library } - ApplicationManager.getApplication().invokeLater { - updateLibraries(project, outdatedLibraries) + Notifications.Bus.notify( + Notification( + OUTDATED_RUNTIME_GROUP_DISPLAY_ID, "Outdated Kotlin Runtime", message, + NotificationType.WARNING, NotificationListener { notification, event -> + if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) { + when { + "update" == event.description -> { + val updatedOutdatedLibraries = findOutdatedKotlinLibraries(project).map { it.library } + ApplicationManager.getApplication().invokeLater { + updateLibraries(project, updatedOutdatedLibraries) + } + } + "ignore" == event.description -> { + if (!project.isDisposed) { + PropertiesComponent.getInstance(project).setValue(SUPPRESSED_PROPERTY_NAME, pluginVersion) + } + } + else -> { + throw AssertionError() + } } - } - "ignore" == event.description -> { - if (!project.isDisposed) { - PropertiesComponent.getInstance(project).setValue(SUPPRESSED_PROPERTY_NAME, pluginVersion) - } - } - else -> { - throw AssertionError() + notification.expire() } } - notification.expire() - } - }), project) + ), + project + ) } -private val SUPPRESSED_PROPERTY_NAME = "oudtdated.runtime.suppressed.plugin.version" -private val OUTDATED_RUNTIME_GROUP_DISPLAY_ID = "Outdated Kotlin Runtime" +private const val SUPPRESSED_PROPERTY_NAME = "oudtdated.runtime.suppressed.plugin.version" +private const val OUTDATED_RUNTIME_GROUP_DISPLAY_ID = "Outdated Kotlin Runtime" fun isRuntimeOutdated(libraryVersion: String?, runtimeVersion: String): Boolean { return libraryVersion == null || libraryVersion.startsWith("internal-") != runtimeVersion.startsWith("internal-") || - VersionComparatorUtil.compare(runtimeVersion.substringBefore("-release-"), libraryVersion) > 0 + VersionComparatorUtil.compare(runtimeVersion.substringBefore("-release-"), libraryVersion) > 0 } diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt index f6fc978994b..7789afbb143 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt @@ -29,13 +29,12 @@ import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.roots.libraries.Library import com.intellij.openapi.ui.Messages -import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.JarFileSystem +import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import com.intellij.psi.search.GlobalSearchScope -import com.intellij.util.PathUtil.getLocalFile import com.intellij.util.containers.MultiMap import com.intellij.util.indexing.FileBasedIndex import com.intellij.util.indexing.ScalarIndexExtension @@ -43,12 +42,9 @@ import com.intellij.util.text.VersionComparatorUtil import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.KotlinCompilerVersion -import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil import org.jetbrains.kotlin.idea.framework.isExternalLibrary import org.jetbrains.kotlin.idea.util.application.runReadAction -import org.jetbrains.kotlin.idea.util.application.runWriteAction -import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.idea.util.projectStructure.version import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex @@ -87,10 +83,12 @@ fun findAllUsedLibraries(project: Project): MultiMap { return libraries } -enum class LibraryJarDescriptor(val jarName: String, - val orderRootType: OrderRootType, - val shouldExist: Boolean, - val getPath: (KotlinPaths) -> File = { paths -> File(paths.libPath, jarName) }) { +enum class LibraryJarDescriptor( + val jarName: String, + val orderRootType: OrderRootType, + val shouldExist: Boolean, + val getPath: (KotlinPaths) -> File = { paths -> File(paths.libPath, jarName) } +) { RUNTIME_JAR(PathUtil.KOTLIN_JAVA_STDLIB_JAR, OrderRootType.CLASSES, true, KotlinPaths::getStdlibPath) { override fun findExistingJar(library: Library): VirtualFile? { if (isExternalLibrary(library)) return null @@ -120,8 +118,10 @@ enum class LibraryJarDescriptor(val jarName: String, RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR, OrderRootType.SOURCES, false, KotlinPaths::getStdlibSourcesPath) { override fun findExistingJar(library: Library): VirtualFile? { - return super.findExistingJar(library) ?: - LibraryUtils.getJarFile(library.getFiles(orderRootType).toList(), PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR_OLD) + return super.findExistingJar(library) ?: LibraryUtils.getJarFile( + library.getFiles(orderRootType).toList(), + PathUtil.KOTLIN_JAVA_STDLIB_SRC_JAR_OLD + ) } }, REFLECT_SRC_JAR(PathUtil.KOTLIN_REFLECT_SRC_JAR, OrderRootType.SOURCES, false), @@ -154,15 +154,16 @@ fun getLocalJar(kotlinRuntimeJar: VirtualFile?): VirtualFile? { data class BinaryVersionedFile(val file: VirtualFile, val version: T, val supportedVersion: T) private fun getLibraryRootsWithAbiIncompatibleVersion( - module: Module, - supportedVersion: T, - index: ScalarIndexExtension + module: Module, + supportedVersion: T, + index: ScalarIndexExtension ): Collection> { val id = index.name val moduleWithAllDependencies = setOf(module) + ModuleUtil.getAllDependentModules(module) val moduleWithAllDependentLibraries = GlobalSearchScope.union( - moduleWithAllDependencies.map { it.moduleWithLibrariesScope }.toTypedArray()) + moduleWithAllDependencies.map { it.moduleWithLibrariesScope }.toTypedArray() + ) val allVersions = FileBasedIndex.getInstance().getAllKeys(id, module.project) val badVersions = allVersions.filterNot(BinaryVersion::isCompatible).toHashSet() @@ -172,10 +173,11 @@ private fun getLibraryRootsWithAbiIncompatibleVersion( for (version in badVersions) { val indexedFiles = FileBasedIndex.getInstance().getContainingFiles(id, version, moduleWithAllDependentLibraries) for (indexedFile in indexedFiles) { - val libraryRoot = fileIndex.getClassRootForFile(indexedFile) ?: - error("Only library roots were requested, and only class files should be indexed with the $id key. " + - "File: ${indexedFile.path}") - badRoots.add(BinaryVersionedFile(getLocalFile(libraryRoot), version, supportedVersion)) + val libraryRoot = fileIndex.getClassRootForFile(indexedFile) ?: error( + "Only library roots were requested, and only class files should be indexed with the $id key. " + + "File: ${indexedFile.path}" + ) + badRoots.add(BinaryVersionedFile(VfsUtil.getLocalFile(libraryRoot), version, supportedVersion)) } } @@ -183,9 +185,11 @@ private fun getLibraryRootsWithAbiIncompatibleVersion( } fun showRuntimeJarNotFoundDialog(project: Project, jarName: String) { - Messages.showErrorDialog(project, - jarName + " is not found. Make sure plugin is properly installed.", - "No Runtime Found") + Messages.showErrorDialog( + project, + jarName + " is not found. Make sure plugin is properly installed.", + "No Runtime Found" + ) } fun getKotlinJvmRuntimeMarkerClass(project: Project, scope: GlobalSearchScope): PsiClass? { @@ -243,72 +247,75 @@ fun isSnapshot(version: String): Boolean { } fun hasJdkLikeUpdatedRuntime(version: String): Boolean = - VersionComparatorUtil.compare(version, "1.2.0-rc-39") >= 0 || - isSnapshot(version) || - version == "default_version" /* for tests */ + VersionComparatorUtil.compare(version, "1.2.0-rc-39") >= 0 || + isSnapshot(version) || + version == "default_version" /* for tests */ fun hasJreSpecificRuntime(version: String): Boolean = - VersionComparatorUtil.compare(version, "1.1.0") >= 0 || - isSnapshot(version) || - version == "default_version" /* for tests */ + VersionComparatorUtil.compare(version, "1.1.0") >= 0 || + isSnapshot(version) || + version == "default_version" /* for tests */ -val MAVEN_STDLIB_ID = PathUtil.KOTLIN_JAVA_STDLIB_NAME +const val MAVEN_STDLIB_ID = PathUtil.KOTLIN_JAVA_STDLIB_NAME -val MAVEN_STDLIB_ID_JRE7 = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME -val MAVEN_STDLIB_ID_JDK7 = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME +const val MAVEN_STDLIB_ID_JRE7 = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME +const val MAVEN_STDLIB_ID_JDK7 = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME -val MAVEN_STDLIB_ID_JRE8 = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME -val MAVEN_STDLIB_ID_JDK8 = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME +const val MAVEN_STDLIB_ID_JRE8 = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME +const val MAVEN_STDLIB_ID_JDK8 = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME -val MAVEN_JS_STDLIB_ID = PathUtil.JS_LIB_NAME -val MAVEN_JS_TEST_ID = PathUtil.KOTLIN_TEST_JS_NAME +const val MAVEN_JS_STDLIB_ID = PathUtil.JS_LIB_NAME +const val MAVEN_JS_TEST_ID = PathUtil.KOTLIN_TEST_JS_NAME -val MAVEN_OLD_JS_STDLIB_ID = "kotlin-js-library" -val MAVEN_COMMON_STDLIB_ID = "kotlin-stdlib-common" // TODO: KotlinCommonMavenConfigurator -val MAVEN_TEST_ID = PathUtil.KOTLIN_TEST_NAME -val MAVEN_TEST_JUNIT_ID = "kotlin-test-junit" -val MAVEN_COMMON_TEST_ID = "kotlin-test-common" -val MAVEN_COMMON_TEST_ANNOTATIONS_ID = "kotlin-test-annotations-common" +const val MAVEN_OLD_JS_STDLIB_ID = "kotlin-js-library" +const val MAVEN_COMMON_STDLIB_ID = "kotlin-stdlib-common" // TODO: KotlinCommonMavenConfigurator +const val MAVEN_TEST_ID = PathUtil.KOTLIN_TEST_NAME +const val MAVEN_TEST_JUNIT_ID = "kotlin-test-junit" +const val MAVEN_COMMON_TEST_ID = "kotlin-test-common" +const val MAVEN_COMMON_TEST_ANNOTATIONS_ID = "kotlin-test-annotations-common" val LOG = Logger.getInstance("org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt") data class LibInfo( - val groupId: String, - val name: String + val groupId: String, + val name: String ) data class DeprecatedLibInfo( - val old: LibInfo, - val new: LibInfo, - val outdatedAfterVersion: String, - val message: String + val old: LibInfo, + val new: LibInfo, + val outdatedAfterVersion: String, + val message: String ) private fun deprecatedLib( - oldGroupId: String, - oldName: String, - newGroupId: String = oldGroupId, - newName: String = oldName, - outdatedAfterVersion: String, - message: String): DeprecatedLibInfo { + oldGroupId: String, + oldName: String, + newGroupId: String = oldGroupId, + newName: String = oldName, + outdatedAfterVersion: String, + message: String +): DeprecatedLibInfo { return DeprecatedLibInfo( - old = LibInfo(groupId = oldGroupId, name = oldName), - new = LibInfo(groupId = newGroupId, name = newName), - outdatedAfterVersion = outdatedAfterVersion, - message = message + old = LibInfo(groupId = oldGroupId, name = oldName), + new = LibInfo(groupId = newGroupId, name = newName), + outdatedAfterVersion = outdatedAfterVersion, + message = message ) } val DEPRECATED_LIBRARIES_INFORMATION = listOf( - deprecatedLib( - oldGroupId = "org.jetbrains.kotlin", - oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME, - outdatedAfterVersion = "1.2.0-rc-39", - message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME}"), + deprecatedLib( + oldGroupId = "org.jetbrains.kotlin", + oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME, + outdatedAfterVersion = "1.2.0-rc-39", + message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE7_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK7_NAME}" + ), - deprecatedLib( - oldGroupId = "org.jetbrains.kotlin", - oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME, - outdatedAfterVersion = "1.2.0-rc-39", - message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME}") + deprecatedLib( + oldGroupId = "org.jetbrains.kotlin", + oldName = PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME, newName = PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME, + outdatedAfterVersion = "1.2.0-rc-39", + message = "${PathUtil.KOTLIN_JAVA_RUNTIME_JRE8_NAME} is deprecated since 1.2.0 and should be replaced with ${PathUtil.KOTLIN_JAVA_RUNTIME_JDK8_NAME}" + ) ) \ No newline at end of file