Remove cyclic dependency between idea-maven and idea modules: move constants for stdlib IDs to shared code
This commit is contained in:
@@ -29,8 +29,8 @@ import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
|
||||
import org.jetbrains.idea.maven.model.MavenId
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
|
||||
class GenerateMavenCompileExecutionAction : PomFileActionBase(KotlinMavenExecutionProvider(PomFile.KotlinGoals.Compile, PomFile.DefaultPhases.Compile))
|
||||
@@ -136,4 +136,4 @@ private fun MavenDomPlugin.isKotlinMavenPlugin() = groupId.stringValue == Kotlin
|
||||
&& artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID
|
||||
|
||||
private fun MavenDomDependency.isKotlinStdlib() = groupId.stringValue == KotlinMavenConfigurator.GROUP_ID
|
||||
&& artifactId.stringValue == KotlinJavaMavenConfigurator.STD_LIB_ID
|
||||
&& artifactId.stringValue == MAVEN_STDLIB_ID
|
||||
|
||||
+3
-3
@@ -18,12 +18,13 @@ package org.jetbrains.kotlin.idea.maven.configuration
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||
import org.jetbrains.kotlin.idea.configuration.*
|
||||
import org.jetbrains.kotlin.idea.configuration.hasKotlinJvmRuntimeInScope
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
|
||||
class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfigurator.STD_LIB_ID, KotlinJavaMavenConfigurator.TEST_LIB_ID, false, KotlinJavaMavenConfigurator.NAME, KotlinJavaMavenConfigurator.PRESENTABLE_TEXT) {
|
||||
class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(MAVEN_STDLIB_ID, KotlinJavaMavenConfigurator.TEST_LIB_ID, false, KotlinJavaMavenConfigurator.NAME, KotlinJavaMavenConfigurator.PRESENTABLE_TEXT) {
|
||||
|
||||
override fun isKotlinModule(module: Module): Boolean {
|
||||
return hasKotlinJvmRuntimeInScope(module)
|
||||
@@ -43,7 +44,6 @@ class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfi
|
||||
|
||||
companion object {
|
||||
private val NAME = "maven"
|
||||
val STD_LIB_ID = "kotlin-stdlib"
|
||||
val TEST_LIB_ID = "kotlin-test"
|
||||
private val PRESENTABLE_TEXT = "Maven"
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,10 +20,11 @@ import com.intellij.openapi.module.Module
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||
import org.jetbrains.kotlin.idea.configuration.hasKotlinJsRuntimeInScope
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
|
||||
class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(KotlinJavascriptMavenConfigurator.STD_LIB_ID, null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) {
|
||||
class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(MAVEN_JS_STDLIB_ID, null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) {
|
||||
|
||||
override fun isKotlinModule(module: Module): Boolean {
|
||||
return hasKotlinJsRuntimeInScope(module)
|
||||
@@ -43,7 +44,6 @@ class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(KotlinJavascri
|
||||
|
||||
companion object {
|
||||
private val NAME = "js maven"
|
||||
val STD_LIB_ID = "kotlin-js-library"
|
||||
private val PRESENTABLE_TEXT = "JavaScript Maven - experimental"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -32,6 +32,7 @@ import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
|
||||
class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
|
||||
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
|
||||
@@ -44,7 +45,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
|
||||
val manager = MavenProjectsManager.getInstance(module.project) ?: return
|
||||
val project = manager.findProject(module) ?: return
|
||||
|
||||
val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID).map { it.version }.distinct()
|
||||
val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID).map { it.version }.distinct()
|
||||
val pluginVersion = project.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)?.version
|
||||
|
||||
if (pluginVersion == null || stdlibVersion.isEmpty() || stdlibVersion.singleOrNull() == pluginVersion) {
|
||||
@@ -64,7 +65,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
|
||||
)
|
||||
}
|
||||
|
||||
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID, null))
|
||||
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null))
|
||||
.filter { it.version.stringValue != pluginVersion }
|
||||
.forEach { dependency ->
|
||||
val fixes = dependency.version.stringValue?.let { version ->
|
||||
|
||||
+10
-11
@@ -21,7 +21,6 @@ import com.intellij.codeInspection.ProblemDescriptor
|
||||
import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.lang.annotation.HighlightSeverity
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.FileTypeIndex
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
@@ -38,9 +37,9 @@ import org.jetbrains.idea.maven.model.MavenPlugin
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||
import org.jetbrains.idea.maven.utils.MavenArtifactScope
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavascriptMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
import java.util.*
|
||||
|
||||
class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
|
||||
@@ -114,25 +113,25 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
}
|
||||
}
|
||||
|
||||
val stdlibDependencies = mavenProject.findDependencies(KotlinMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID)
|
||||
val jsDependencies = mavenProject.findDependencies(KotlinMavenConfigurator.GROUP_ID, KotlinJavascriptMavenConfigurator.STD_LIB_ID)
|
||||
val stdlibDependencies = mavenProject.findDependencies(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID)
|
||||
val jsDependencies = mavenProject.findDependencies(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID)
|
||||
|
||||
if (hasJvmExecution && stdlibDependencies.isEmpty()) {
|
||||
holder.createProblem(kotlinPlugin.artifactId.createStableCopy(),
|
||||
HighlightSeverity.WARNING,
|
||||
"Kotlin JVM compiler configured but no ${KotlinJavaMavenConfigurator.STD_LIB_ID} dependency",
|
||||
FixAddStdlibLocalFix(domFileElement.file, KotlinJavaMavenConfigurator.STD_LIB_ID, kotlinPlugin.version.rawText))
|
||||
"Kotlin JVM compiler configured but no $MAVEN_STDLIB_ID dependency",
|
||||
FixAddStdlibLocalFix(domFileElement.file, MAVEN_STDLIB_ID, kotlinPlugin.version.rawText))
|
||||
}
|
||||
if (hasJsExecution && jsDependencies.isEmpty()) {
|
||||
holder.createProblem(kotlinPlugin.artifactId.createStableCopy(),
|
||||
HighlightSeverity.WARNING,
|
||||
"Kotlin JavaScript compiler configured but no ${KotlinJavascriptMavenConfigurator.STD_LIB_ID} dependency",
|
||||
FixAddStdlibLocalFix(domFileElement.file, KotlinJavascriptMavenConfigurator.STD_LIB_ID, kotlinPlugin.version.rawText))
|
||||
"Kotlin JavaScript compiler configured but no ${MAVEN_JS_STDLIB_ID} dependency",
|
||||
FixAddStdlibLocalFix(domFileElement.file, MAVEN_JS_STDLIB_ID, kotlinPlugin.version.rawText))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val stdlibDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID, null))
|
||||
val stdlibDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null))
|
||||
if (!hasJvmExecution && stdlibDependencies.isNotEmpty()) {
|
||||
stdlibDependencies.forEach { dep ->
|
||||
holder.createProblem(dep.artifactId.createStableCopy(),
|
||||
@@ -142,7 +141,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
}
|
||||
}
|
||||
|
||||
val stdlibJsDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinJavascriptMavenConfigurator.STD_LIB_ID, null))
|
||||
val stdlibJsDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID, null))
|
||||
if (!hasJsExecution && stdlibJsDependencies.isNotEmpty()) {
|
||||
stdlibJsDependencies.forEach { dep ->
|
||||
holder.createProblem(dep.artifactId.createStableCopy(),
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
<orderEntry type="module" module-name="lint-idea" scope="PROVIDED" />
|
||||
<orderEntry type="library" name="java-decompiler-plugin" level="project" />
|
||||
<orderEntry type="module" module-name="formatter" />
|
||||
<orderEntry type="module" module-name="idea-maven" />
|
||||
<orderEntry type="library" scope="TEST" name="native-platform-uberjar" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -34,9 +34,7 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCompilerSettings
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider
|
||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider
|
||||
import org.jetbrains.kotlin.idea.framework.getLibraryProperties
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavaMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinJavascriptMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
||||
import org.jetbrains.kotlin.idea.versions.*
|
||||
|
||||
private fun getRuntimeLibraryVersions(
|
||||
module: Module,
|
||||
@@ -134,6 +132,6 @@ internal fun KotlinFacetSettings.initializeIfNeeded(module: Module, rootModel: M
|
||||
|
||||
val TargetPlatformKind<*>.mavenLibraryId: String
|
||||
get() = when (this) {
|
||||
is TargetPlatformKind.Jvm -> KotlinJavaMavenConfigurator.STD_LIB_ID
|
||||
is TargetPlatformKind.JavaScript -> KotlinJavascriptMavenConfigurator.STD_LIB_ID
|
||||
is TargetPlatformKind.Jvm -> MAVEN_STDLIB_ID
|
||||
is TargetPlatformKind.JavaScript -> MAVEN_JS_STDLIB_ID
|
||||
}
|
||||
|
||||
@@ -286,3 +286,6 @@ fun getKotlinJsRuntimeMarkerClass(project: Project, scope: GlobalSearchScope): V
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val MAVEN_STDLIB_ID = "kotlin-stdlib"
|
||||
val MAVEN_JS_STDLIB_ID = "kotlin-js-library"
|
||||
|
||||
Reference in New Issue
Block a user