use DOM instead of MavenProjectsManager to detect whether Kotlin is configured (KT-9275)
This commit is contained in:
@@ -41,6 +41,9 @@ import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
fun kotlinPluginId(version: String?) = MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version)
|
||||||
|
|
||||||
|
|
||||||
class PomFile(val xmlFile: XmlFile) {
|
class PomFile(val xmlFile: XmlFile) {
|
||||||
val domModel = MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}")
|
val domModel = MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}")
|
||||||
private val nodesByName = HashMap<String, XmlTag>()
|
private val nodesByName = HashMap<String, XmlTag>()
|
||||||
@@ -117,13 +120,13 @@ class PomFile(val xmlFile: XmlFile) {
|
|||||||
return dependency
|
return dependency
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addKotlinPlugin(version: String?) = addPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version))
|
fun addKotlinPlugin(version: String?) = addPlugin(kotlinPluginId(version))
|
||||||
|
|
||||||
fun addPlugin(artifact: MavenId): MavenDomPlugin {
|
fun addPlugin(artifact: MavenId): MavenDomPlugin {
|
||||||
ensureBuild()
|
ensureBuild()
|
||||||
|
|
||||||
val groupArtifact = artifact.withNoVersion()
|
val groupArtifact = artifact.withNoVersion()
|
||||||
val plugin = domModel.build.plugins.plugins.firstOrNull { it.matches(groupArtifact) } ?: domModel.build.plugins.addPlugin()
|
val plugin = findPlugin(groupArtifact) ?: domModel.build.plugins.addPlugin()
|
||||||
plugin.groupId.stringValue = artifact.groupId
|
plugin.groupId.stringValue = artifact.groupId
|
||||||
plugin.artifactId.stringValue = artifact.artifactId
|
plugin.artifactId.stringValue = artifact.artifactId
|
||||||
if (artifact.version != null) {
|
if (artifact.version != null) {
|
||||||
@@ -134,6 +137,8 @@ class PomFile(val xmlFile: XmlFile) {
|
|||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findPlugin(groupArtifact: MavenId) = domModel.build.plugins.plugins.firstOrNull { it.matches(groupArtifact) }
|
||||||
|
|
||||||
fun isPluginAfter(plugin: MavenDomPlugin, referencePlugin: MavenDomPlugin): Boolean {
|
fun isPluginAfter(plugin: MavenDomPlugin, referencePlugin: MavenDomPlugin): Boolean {
|
||||||
require(plugin.parent === referencePlugin.parent) { "Plugins should be siblings" }
|
require(plugin.parent === referencePlugin.parent) { "Plugins should be siblings" }
|
||||||
require(plugin !== referencePlugin)
|
require(plugin !== referencePlugin)
|
||||||
|
|||||||
+9
-8
@@ -33,7 +33,6 @@ import com.intellij.psi.xml.XmlFile
|
|||||||
import org.jetbrains.idea.maven.dom.MavenDomUtil
|
import org.jetbrains.idea.maven.dom.MavenDomUtil
|
||||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||||
import org.jetbrains.idea.maven.model.MavenId
|
import org.jetbrains.idea.maven.model.MavenId
|
||||||
import org.jetbrains.idea.maven.project.MavenProject
|
|
||||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||||
import org.jetbrains.idea.maven.utils.MavenArtifactScope
|
import org.jetbrains.idea.maven.utils.MavenArtifactScope
|
||||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||||
@@ -41,6 +40,7 @@ import org.jetbrains.kotlin.idea.configuration.*
|
|||||||
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
|
||||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||||
import org.jetbrains.kotlin.idea.maven.excludeMavenChildrenModules
|
import org.jetbrains.kotlin.idea.maven.excludeMavenChildrenModules
|
||||||
|
import org.jetbrains.kotlin.idea.maven.kotlinPluginId
|
||||||
|
|
||||||
abstract class KotlinMavenConfigurator
|
abstract class KotlinMavenConfigurator
|
||||||
protected constructor(private val stdlibArtifactId: String,
|
protected constructor(private val stdlibArtifactId: String,
|
||||||
@@ -57,23 +57,24 @@ abstract class KotlinMavenConfigurator
|
|||||||
if (psi == null
|
if (psi == null
|
||||||
|| !psi.isValid
|
|| !psi.isValid
|
||||||
|| psi !is XmlFile
|
|| psi !is XmlFile
|
||||||
|| psi.virtualFile == null
|
|| psi.virtualFile == null) {
|
||||||
|| MavenDomUtil.getMavenDomProjectModel(module.project, psi.virtualFile) == null) {
|
|
||||||
return ConfigureKotlinStatus.BROKEN
|
return ConfigureKotlinStatus.BROKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
val mavenProject = MavenProjectsManager.getInstance(module.project).findProject(module) ?: return ConfigureKotlinStatus.BROKEN
|
val pom = PomFile(psi)
|
||||||
|
|
||||||
if (isKotlinModule(module) && hasKotlinPlugin(mavenProject)) {
|
if (isKotlinModule(module) && hasKotlinPlugin(pom)) {
|
||||||
return ConfigureKotlinStatus.CONFIGURED
|
return ConfigureKotlinStatus.CONFIGURED
|
||||||
}
|
}
|
||||||
return ConfigureKotlinStatus.CAN_BE_CONFIGURED
|
return ConfigureKotlinStatus.CAN_BE_CONFIGURED
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasKotlinPlugin(mavenProject: MavenProject): Boolean {
|
private fun hasKotlinPlugin(pom: PomFile): Boolean {
|
||||||
val plugin = mavenProject.findPlugin(GROUP_ID, MAVEN_PLUGIN_ID) ?: return false
|
val plugin = pom.findPlugin(kotlinPluginId(null)) ?: return false
|
||||||
|
|
||||||
return plugin.executions?.any { it.goals?.any { it != null && isRelevantGoal(it) } ?: false } ?: false
|
return plugin.executions.executions.any {
|
||||||
|
it.goals.goals.any { isRelevantGoal(it.stringValue ?: "") }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configure(project: Project, excludeModules: Collection<Module>) {
|
override fun configure(project: Project, excludeModules: Collection<Module>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user