mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-14 08:31:29 +00:00
Configuration: Detect platform of libraries added via maven artifact ids
#KT-20511 Fixed
This commit is contained in:
@@ -288,7 +288,7 @@ class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo,
|
||||
}
|
||||
|
||||
override val platform: TargetPlatform
|
||||
get() = getLibraryPlatform(library)
|
||||
get() = getLibraryPlatform(project, library)
|
||||
|
||||
override val sourcesModuleInfo: SourceForBinaryModuleInfo
|
||||
get() = LibrarySourceInfo(project, library)
|
||||
|
||||
@@ -61,7 +61,7 @@ class LibraryDependenciesCacheImpl(private val project: Project) : LibraryDepend
|
||||
val libraries = LinkedHashSet<Library>()
|
||||
val sdks = LinkedHashSet<Sdk>()
|
||||
|
||||
val platform = getLibraryPlatform(library)
|
||||
val platform = getLibraryPlatform(project, library)
|
||||
|
||||
for (module in getLibraryUsageIndex().modulesLibraryIsUsedIn[library]) {
|
||||
if (!processedModules.add(module)) continue
|
||||
@@ -73,7 +73,7 @@ class LibraryDependenciesCacheImpl(private val project: Project) : LibraryDepend
|
||||
|
||||
override fun visitLibraryOrderEntry(libraryOrderEntry: LibraryOrderEntry, value: Unit) {
|
||||
val otherLibrary = libraryOrderEntry.library
|
||||
if (otherLibrary != null && compatiblePlatforms(platform, getLibraryPlatform(otherLibrary))) {
|
||||
if (otherLibrary != null && compatiblePlatforms(platform, getLibraryPlatform(project, otherLibrary))) {
|
||||
libraries.add(otherLibrary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.framework
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
@@ -33,16 +34,16 @@ import java.util.jar.Attributes
|
||||
object JsLibraryStdDetectionUtil {
|
||||
private val IS_JS_LIBRARY_STD_LIB = Key.create<Boolean>("IS_JS_LIBRARY_STD_LIB")
|
||||
|
||||
fun hasJsStdlibJar(library: Library, ignoreKind: Boolean = false): Boolean {
|
||||
fun hasJsStdlibJar(library: Library, project: Project, ignoreKind: Boolean = false): Boolean {
|
||||
if (library !is LibraryEx || library.isDisposed) return false
|
||||
if (!ignoreKind && library.kind !is JSLibraryKind) return false
|
||||
if (!ignoreKind && library.effectiveKind(project) !is JSLibraryKind) return false
|
||||
|
||||
val classes = Arrays.asList(*library.getFiles(OrderRootType.CLASSES))
|
||||
return getJsStdLibJar(classes) != null
|
||||
}
|
||||
|
||||
fun getJsLibraryStdVersion(library: Library): String? {
|
||||
if ((library as LibraryEx).kind !is JSLibraryKind) return null
|
||||
fun getJsLibraryStdVersion(library: Library, project: Project): String? {
|
||||
if ((library as LibraryEx).effectiveKind(project) !is JSLibraryKind) return null
|
||||
val jar = getJsStdLibJar(library.getFiles(OrderRootType.CLASSES).toList()) ?: return null
|
||||
|
||||
return JarUtil.getJarAttribute(VfsUtilCore.virtualToIoFile(jar), Attributes.Name.IMPLEMENTATION_VERSION)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.framework
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
|
||||
interface LibraryEffectiveKindProvider {
|
||||
fun getEffectiveKind(library: LibraryEx): PersistentLibraryKind<*>?
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, LibraryEffectiveKindProvider::class.java)!!
|
||||
}
|
||||
}
|
||||
|
||||
fun LibraryEx.effectiveKind(project: Project) = LibraryEffectiveKindProvider.getInstance(project).getEffectiveKind(this)
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.framework
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.DummyLibraryProperties
|
||||
@@ -31,19 +32,21 @@ import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.util.jar.Attributes
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object JSLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js") {
|
||||
interface KotlinLibraryKind
|
||||
|
||||
object JSLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js"), KotlinLibraryKind {
|
||||
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
|
||||
}
|
||||
|
||||
object CommonLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.common") {
|
||||
object CommonLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.common"), KotlinLibraryKind {
|
||||
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
|
||||
}
|
||||
|
||||
fun getLibraryPlatform(library: Library): TargetPlatform {
|
||||
fun getLibraryPlatform(project: Project, library: Library): TargetPlatform {
|
||||
library as? LibraryEx ?: return JvmPlatform
|
||||
if (library.isDisposed) return JvmPlatform
|
||||
|
||||
return when (library.kind) {
|
||||
return when (library.effectiveKind(project)) {
|
||||
JSLibraryKind -> JsPlatform
|
||||
CommonLibraryKind -> TargetPlatform.Common
|
||||
else -> JvmPlatform
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
|
||||
import org.jetbrains.kotlin.idea.framework.effectiveKind
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinAddRequiredModuleFix
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.findFirstPsiJavaModule
|
||||
@@ -278,7 +279,7 @@ private class LibraryKindSearchScope(val module: Module,
|
||||
if (!super.contains(file)) return false
|
||||
val orderEntry = ModuleRootManager.getInstance(module).fileIndex.getOrderEntryForFile(file)
|
||||
if (orderEntry is LibraryOrderEntry) {
|
||||
return (orderEntry.library as LibraryEx).kind == libraryKind
|
||||
return (orderEntry.library as LibraryEx).effectiveKind(module.project) == libraryKind
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.configuration
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
@@ -92,8 +93,8 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr
|
||||
return result
|
||||
}
|
||||
|
||||
override val libraryMatcher: (Library) -> Boolean =
|
||||
{ library -> JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null }
|
||||
override val libraryMatcher: (Library, Project) -> Boolean =
|
||||
{ library, _ -> JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null }
|
||||
|
||||
override fun configureKotlinSettings(modules: List<Module>) {
|
||||
val project = modules.firstOrNull()?.project ?: return
|
||||
@@ -140,7 +141,7 @@ open class KotlinJavaModuleConfigurator protected constructor() : KotlinWithLibr
|
||||
private fun hasBrokenJsRuntime(module: Module): Boolean {
|
||||
for (orderEntry in ModuleRootManager.getInstance(module).orderEntries) {
|
||||
val library = (orderEntry as? LibraryOrderEntry)?.library as? LibraryEx ?: continue
|
||||
if (JsLibraryStdDetectionUtil.hasJsStdlibJar(library, ignoreKind = true)) return true
|
||||
if (JsLibraryStdDetectionUtil.hasJsStdlibJar(library, module.project, ignoreKind = true)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
@@ -64,7 +65,9 @@ open class KotlinJsModuleConfigurator : KotlinWithLibraryConfigurator() {
|
||||
LibraryJarDescriptor.JS_STDLIB_SRC_JAR
|
||||
)
|
||||
|
||||
override val libraryMatcher: (Library) -> Boolean = { library -> JsLibraryStdDetectionUtil.hasJsStdlibJar(library) }
|
||||
override val libraryMatcher: (Library, Project) -> Boolean = { library, project ->
|
||||
JsLibraryStdDetectionUtil.hasJsStdlibJar(library, project)
|
||||
}
|
||||
|
||||
override val libraryType: LibraryType<DummyLibraryProperties>?
|
||||
get() = JSLibraryType.getInstance()
|
||||
@@ -82,7 +85,7 @@ open class KotlinJsModuleConfigurator : KotlinWithLibraryConfigurator() {
|
||||
for (orderEntry in ModuleRootManager.getInstance(module).orderEntries) {
|
||||
val library = (orderEntry as? LibraryOrderEntry)?.library as? LibraryEx ?: continue
|
||||
allLibraries.add(library)
|
||||
if (JsLibraryStdDetectionUtil.hasJsStdlibJar(library, ignoreKind = true) && library.kind == null) {
|
||||
if (JsLibraryStdDetectionUtil.hasJsStdlibJar(library, module.project, ignoreKind = true) && library.kind == null) {
|
||||
brokenStdlib = library
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ abstract class KotlinWithLibraryConfigurator internal constructor() : KotlinProj
|
||||
}
|
||||
|
||||
fun getKotlinLibrary(project: Project): Library? {
|
||||
return LibraryTablesRegistrar.getInstance().getLibraryTable(project).libraries.firstOrNull(this::isKotlinLibrary) ?:
|
||||
LibraryTablesRegistrar.getInstance().libraryTable.libraries.firstOrNull(this::isKotlinLibrary)
|
||||
return LibraryTablesRegistrar.getInstance().getLibraryTable(project).libraries.firstOrNull { isKotlinLibrary(it, project) } ?:
|
||||
LibraryTablesRegistrar.getInstance().libraryTable.libraries.firstOrNull { isKotlinLibrary(it, project) }
|
||||
}
|
||||
|
||||
@Contract("!null, _, _ -> !null")
|
||||
@@ -272,13 +272,13 @@ abstract class KotlinWithLibraryConfigurator internal constructor() : KotlinProj
|
||||
return library != null && library.getUrls(OrderRootType.CLASSES).size > 0
|
||||
}
|
||||
|
||||
protected abstract val libraryMatcher: (Library) -> Boolean
|
||||
protected abstract val libraryMatcher: (Library, Project) -> Boolean
|
||||
|
||||
fun getKotlinLibrary(module: Module): Library? {
|
||||
return findKotlinRuntimeLibrary(module, this::isKotlinLibrary)
|
||||
}
|
||||
|
||||
private fun isKotlinLibrary(library: Library) = library.name == libraryName || libraryMatcher(library)
|
||||
private fun isKotlinLibrary(library: Library, project: Project) = library.name == libraryName || libraryMatcher(library, project)
|
||||
|
||||
protected fun needToChooseJarPath(project: Project): Boolean {
|
||||
val defaultPath = getDefaultPathToJarFile(project)
|
||||
|
||||
@@ -50,7 +50,7 @@ fun findOutdatedKotlinLibraries(project: Project): List<VersionedLibrary> {
|
||||
val outdatedLibraries = arrayListOf<VersionedLibrary>()
|
||||
|
||||
for ((library, modules) in findAllUsedLibraries(project).entrySet()) {
|
||||
getOutdatedRuntimeLibraryVersion(library)?.let { version ->
|
||||
getOutdatedRuntimeLibraryVersion(library, project)?.let { version ->
|
||||
outdatedLibraries.add(VersionedLibrary(library, version, modules))
|
||||
}
|
||||
}
|
||||
@@ -58,30 +58,30 @@ fun findOutdatedKotlinLibraries(project: Project): List<VersionedLibrary> {
|
||||
return outdatedLibraries
|
||||
}
|
||||
|
||||
private fun getOutdatedRuntimeLibraryVersion(library: Library): String? {
|
||||
val libraryVersion = getKotlinLibraryVersion(library) ?: return null
|
||||
private fun getOutdatedRuntimeLibraryVersion(library: Library, project: Project): String? {
|
||||
val libraryVersion = getKotlinLibraryVersion(library, project) ?: return null
|
||||
val runtimeVersion = bundledRuntimeVersion()
|
||||
|
||||
return if (isRuntimeOutdated(libraryVersion, runtimeVersion)) libraryVersion else null
|
||||
}
|
||||
|
||||
private fun getKotlinLibraryVersion(library: Library): String? =
|
||||
JavaRuntimeDetectionUtil.getJavaRuntimeVersion(library) ?: JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library)
|
||||
private fun getKotlinLibraryVersion(library: Library, project: Project): String? =
|
||||
JavaRuntimeDetectionUtil.getJavaRuntimeVersion(library) ?: JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library, project)
|
||||
|
||||
fun findKotlinRuntimeLibrary(module: Module, predicate: (Library) -> Boolean = ::isKotlinRuntime): Library? {
|
||||
fun findKotlinRuntimeLibrary(module: Module, predicate: (Library, Project) -> Boolean = ::isKotlinRuntime): Library? {
|
||||
val orderEntries = ModuleRootManager.getInstance(module).orderEntries.filterIsInstance<LibraryOrderEntry>()
|
||||
return orderEntries.asSequence()
|
||||
.mapNotNull { it.library }
|
||||
.firstOrNull(predicate)
|
||||
.firstOrNull { predicate(it, module.project) }
|
||||
}
|
||||
|
||||
private fun isKotlinRuntime(library: Library) = isKotlinJavaRuntime(library) || isKotlinJsRuntime(library)
|
||||
private fun isKotlinRuntime(library: Library, project: Project) = isKotlinJavaRuntime(library) || isKotlinJsRuntime(library, project)
|
||||
|
||||
private fun isKotlinJavaRuntime(library: Library) =
|
||||
JavaRuntimeDetectionUtil.getRuntimeJar(library.getFiles(OrderRootType.CLASSES).asList()) != null
|
||||
|
||||
private fun isKotlinJsRuntime(library: Library) =
|
||||
JsLibraryStdDetectionUtil.hasJsStdlibJar(library)
|
||||
private fun isKotlinJsRuntime(library: Library, project: Project) =
|
||||
JsLibraryStdDetectionUtil.hasJsStdlibJar(library, project)
|
||||
|
||||
fun collectModulesWithOutdatedRuntime(libraries: List<VersionedLibrary>): List<Module> =
|
||||
libraries.flatMap { it.usedInModules }
|
||||
|
||||
@@ -320,6 +320,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -320,6 +320,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -320,6 +320,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -321,6 +321,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -320,6 +320,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -320,6 +320,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.config.KotlinFacetSettingsProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.facet.KotlinFacetSettingsProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProvider"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.NotPropertiesService"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.intentions.NotPropertiesServiceImpl"/>
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class KotlinVersionInfoProviderByModuleDependencies : KotlinVersionInfoProvider
|
||||
|
||||
override fun getLibraryVersions(module: Module, targetPlatform: TargetPlatformKind<*>, rootModel: ModuleRootModel?): Collection<String> {
|
||||
val versionProvider: (Library) -> String? = when (targetPlatform) {
|
||||
is TargetPlatformKind.JavaScript -> JsLibraryStdDetectionUtil::getJsLibraryStdVersion
|
||||
is TargetPlatformKind.JavaScript -> fun(library: Library) = JsLibraryStdDetectionUtil.getJsLibraryStdVersion(library, module.project)
|
||||
is TargetPlatformKind.Jvm -> JavaRuntimeDetectionUtil::getJavaRuntimeVersion
|
||||
is TargetPlatformKind.Common -> ::getCommonRuntimeLibraryVersion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.framework
|
||||
|
||||
import com.intellij.ProjectTopics
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ModuleRootEvent
|
||||
import com.intellij.openapi.roots.ModuleRootListener
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import java.util.*
|
||||
|
||||
class LibraryEffectiveKindProviderImpl(project: Project) : LibraryEffectiveKindProvider {
|
||||
companion object {
|
||||
private val effectiveKindMap = HashMap<LibraryEx, PersistentLibraryKind<*>?>()
|
||||
}
|
||||
|
||||
init {
|
||||
project.messageBus.connect(project).subscribe(
|
||||
ProjectTopics.PROJECT_ROOTS,
|
||||
object : ModuleRootListener {
|
||||
override fun rootsChanged(event: ModuleRootEvent?) {
|
||||
synchronized(effectiveKindMap) {
|
||||
effectiveKindMap.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun getEffectiveKind(library: LibraryEx): PersistentLibraryKind<*>? {
|
||||
val kind = library.kind
|
||||
return when (kind) {
|
||||
is KotlinLibraryKind -> kind
|
||||
else -> {
|
||||
synchronized(effectiveKindMap) {
|
||||
effectiveKindMap.getOrPut(library) { detectLibraryKind(library.getFiles(OrderRootType.CLASSES)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
idea/testData/configuration/jsTest12Maven/kotlin-test-js-1.2.31.jar
vendored
Normal file
BIN
idea/testData/configuration/jsTest12Maven/kotlin-test-js-1.2.31.jar
vendored
Normal file
Binary file not shown.
13
idea/testData/configuration/mavenProvidedTestJsKind/module.iml
vendored
Normal file
13
idea/testData/configuration/mavenProvidedTestJsKind/module.iml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
||||
<orderEntry type="library" name="org.jetbrains.kotlin:kotlin-test-js:1.2.31" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
49
idea/testData/configuration/mavenProvidedTestJsKind/projectFile.ipr
vendored
Normal file
49
idea/testData/configuration/mavenProvidedTestJsKind/projectFile.ipr
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="CopyrightManager" default="" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime (2)" type="kotlin.js">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../jsRuntime11Maven/kotlin-stdlib-js-1.1.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
</SOURCES>
|
||||
</library>
|
||||
<library name="org.jetbrains.kotlin:kotlin-test-js:1.2.31" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-test-js:1.2.31" />
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../jsTest12Maven/kotlin-test-js-1.2.31.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
</project>
|
||||
0
idea/testData/configuration/mavenProvidedTestJsKind/src/foo.kt
vendored
Normal file
0
idea/testData/configuration/mavenProvidedTestJsKind/src/foo.kt
vendored
Normal file
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration;
|
||||
|
||||
import com.intellij.jarRepository.RepositoryLibraryType;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -24,6 +25,7 @@ import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.RootPolicy;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -35,7 +37,10 @@ import org.jetbrains.kotlin.config.*;
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder;
|
||||
import org.jetbrains.kotlin.idea.facet.FacetUtilsKt;
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet;
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind;
|
||||
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil;
|
||||
import org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderKt;
|
||||
import org.jetbrains.kotlin.idea.framework.LibraryKindsKt;
|
||||
import org.jetbrains.kotlin.idea.project.PlatformKt;
|
||||
import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt;
|
||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
|
||||
@@ -152,7 +157,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
||||
}
|
||||
|
||||
public void testJsLibraryWrongKind() {
|
||||
doTestOneJsModule(KotlinWithLibraryConfigurator.FileState.EXISTS);
|
||||
AbstractConfigureKotlinTest.Companion.assertProperlyConfigured(getModule(), AbstractConfigureKotlinTest.Companion.getJS_CONFIGURATOR());
|
||||
assertEquals(1, ModuleRootManager.getInstance(getModule()).orderEntries().process(new LibraryCountingRootPolicy(), 0).intValue());
|
||||
}
|
||||
|
||||
@@ -178,16 +183,22 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
||||
|
||||
public void testJsLibraryVersion11() {
|
||||
Library jsRuntime = KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().iterator().next();
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime);
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject);
|
||||
assertEquals("1.1.0", version);
|
||||
}
|
||||
|
||||
public void testJsLibraryVersion106() {
|
||||
Library jsRuntime = KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().iterator().next();
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime);
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject);
|
||||
assertEquals("1.0.6", version);
|
||||
}
|
||||
|
||||
public void testMavenProvidedTestJsKind() {
|
||||
LibraryEx jsTest = (LibraryEx) KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().toArray()[1];
|
||||
assertEquals(RepositoryLibraryType.REPOSITORY_LIBRARY_KIND, jsTest.getKind());
|
||||
assertEquals(JSLibraryKind.INSTANCE, LibraryEffectiveKindProviderKt.effectiveKind(jsTest, myProject));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testJvmProjectWithV1FacetConfig() {
|
||||
KotlinFacetSettings settings = KotlinFacetSettingsProvider.Companion.getInstance(myProject).getInitializedSettings(getModule());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration;
|
||||
|
||||
import com.intellij.jarRepository.RepositoryLibraryType;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -24,6 +25,7 @@ import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.RootPolicy;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -35,7 +37,10 @@ import org.jetbrains.kotlin.config.*;
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder;
|
||||
import org.jetbrains.kotlin.idea.facet.FacetUtilsKt;
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet;
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind;
|
||||
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil;
|
||||
import org.jetbrains.kotlin.idea.framework.LibraryEffectiveKindProviderKt;
|
||||
import org.jetbrains.kotlin.idea.framework.LibraryKindsKt;
|
||||
import org.jetbrains.kotlin.idea.project.PlatformKt;
|
||||
import org.jetbrains.kotlin.idea.util.Java9StructureUtilKt;
|
||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryUtilKt;
|
||||
@@ -178,16 +183,22 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
||||
|
||||
public void testJsLibraryVersion11() {
|
||||
Library jsRuntime = KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().iterator().next();
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime);
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject);
|
||||
assertEquals("1.1.0", version);
|
||||
}
|
||||
|
||||
public void testJsLibraryVersion106() {
|
||||
Library jsRuntime = KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().iterator().next();
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime);
|
||||
String version = JsLibraryStdDetectionUtil.INSTANCE.getJsLibraryStdVersion(jsRuntime, myProject);
|
||||
assertEquals("1.0.6", version);
|
||||
}
|
||||
|
||||
public void testMavenProvidedTestJsKind() {
|
||||
LibraryEx jsTest = (LibraryEx) KotlinRuntimeLibraryUtilKt.findAllUsedLibraries(myProject).keySet().toArray()[1];
|
||||
assertEquals(RepositoryLibraryType.REPOSITORY_LIBRARY_KIND, jsTest.getKind());
|
||||
assertEquals(JSLibraryKind.INSTANCE, LibraryEffectiveKindProviderKt.effectiveKind(jsTest, myProject));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testJvmProjectWithV1FacetConfig() {
|
||||
KotlinFacetSettings settings = KotlinFacetSettingsProvider.Companion.getInstance(myProject).getInitializedSettings(getModule());
|
||||
|
||||
Reference in New Issue
Block a user