EA-86479 - ISE: PomFile.<init>
don't apply any inspections for inappropriate pom files
This commit is contained in:
@@ -44,8 +44,9 @@ import java.util.*
|
||||
fun kotlinPluginId(version: String?) = MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version)
|
||||
|
||||
|
||||
class PomFile(val xmlFile: XmlFile) {
|
||||
val domModel = MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}")
|
||||
class PomFile private constructor(val xmlFile: XmlFile, val domModel: MavenDomProjectModel) {
|
||||
constructor(xmlFile: XmlFile) : this(xmlFile, MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile) ?: throw IllegalStateException("No DOM model found for pom ${xmlFile.name}"))
|
||||
|
||||
private val nodesByName = HashMap<String, XmlTag>()
|
||||
private val projectElement: XmlTag
|
||||
|
||||
@@ -483,6 +484,8 @@ class PomFile(val xmlFile: XmlFile) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun forFileOrNull(xmlFile: XmlFile): PomFile? = MavenDomUtil.getMavenDomProjectModel(xmlFile.project, xmlFile.virtualFile)?.let { PomFile(xmlFile, it) }
|
||||
|
||||
@Deprecated("We shouldn't use phase but additional compiler configuration in most cases")
|
||||
fun getPhase(hasJavaFiles: Boolean, isTest: Boolean) = when {
|
||||
hasJavaFiles -> when {
|
||||
|
||||
+3
-3
@@ -54,7 +54,7 @@ class MavenPluginSourcesMoveToExecutionIntention : PsiElementBaseIntentionAction
|
||||
return false
|
||||
}
|
||||
|
||||
val pom = PomFile(file as XmlFile)
|
||||
val pom = PomFile.forFileOrNull(file as XmlFile) ?: return false
|
||||
if (domElement.getParentOfType(MavenDomBuild::class.java, false)?.sourceDirectory === domElement) {
|
||||
return pom.findKotlinExecutions(PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.Js).isNotEmpty()
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class MavenPluginSourcesMoveToExecutionIntention : PsiElementBaseIntentionAction
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
val xmlFile = element.containingFile as? XmlFile ?: return
|
||||
val pomFile = PomFile(xmlFile)
|
||||
val pomFile = PomFile.forFileOrNull(xmlFile) ?: return
|
||||
|
||||
val tag = element.getParentOfType<XmlTag>(false) ?: return
|
||||
val domElement = DomManager.getDomManager(project).getDomElement(tag) as? GenericDomValue<*> ?: return
|
||||
@@ -126,7 +126,7 @@ class MavenPluginSourcesMoveToBuild : PsiElementBaseIntentionAction() {
|
||||
.filterIsInstance<XmlTag>()
|
||||
.firstOrNull { it.localName == "sourceDirs" } ?: return false
|
||||
|
||||
val pom = PomFile(element.containingFile as XmlFile)
|
||||
val pom = PomFile.forFileOrNull(element.containingFile as XmlFile) ?: return false
|
||||
val sourceDirsToMove = pom.executionSourceDirs(execution)
|
||||
|
||||
if (sourceDirsToMove.size != 1) {
|
||||
|
||||
@@ -61,7 +61,7 @@ private class KotlinMavenPluginProvider : AbstractDomGenerateProvider<MavenDomPl
|
||||
else -> knownVersion
|
||||
}
|
||||
|
||||
val pom = PomFile(DomUtil.getFile(parent))
|
||||
val pom = PomFile.forFileOrNull(DomUtil.getFile(parent)) ?: return null
|
||||
return pom.addPlugin(MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version))
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ private class KotlinMavenPluginProvider : AbstractDomGenerateProvider<MavenDomPl
|
||||
override fun isAvailableForElement(contextElement: DomElement): Boolean {
|
||||
val parent = contextElement.findProject() ?: return false
|
||||
|
||||
return parent.build.plugins.plugins.none { plugin -> plugin.isKotlinMavenPlugin() }
|
||||
return parent.build.plugins.plugins.none(MavenDomPlugin::isKotlinMavenPlugin)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ private class KotlinMavenExecutionProvider(val goal: String, val phase: String)
|
||||
return null
|
||||
}
|
||||
|
||||
val file = PomFile(DomUtil.getFile(parent))
|
||||
val file = PomFile.forFileOrNull(DomUtil.getFile(parent)) ?: return null
|
||||
val execution = file.addExecution(parent, goal, phase, listOf(goal))
|
||||
|
||||
if (editor != null) {
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ abstract class KotlinMavenConfigurator
|
||||
|
||||
private fun checkKotlinPlugin(module: Module): ConfigureKotlinStatus {
|
||||
val psi = findModulePomFile(module) as? XmlFile ?: return ConfigureKotlinStatus.BROKEN
|
||||
val pom = PomFile(psi)
|
||||
val pom = PomFile.forFileOrNull(psi) ?: return ConfigureKotlinStatus.NON_APPLICABLE
|
||||
|
||||
if (hasKotlinPlugin(pom)) {
|
||||
return ConfigureKotlinStatus.CONFIGURED
|
||||
@@ -137,7 +137,7 @@ abstract class KotlinMavenConfigurator
|
||||
return
|
||||
}
|
||||
|
||||
val pom = PomFile(file as XmlFile)
|
||||
val pom = PomFile.forFileOrNull(file as XmlFile) ?: return
|
||||
pom.addProperty(KOTLIN_VERSION_PROPERTY, version)
|
||||
|
||||
pom.addDependency(MavenId(GROUP_ID, getStdlibArtifactId(module), "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null)
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class DifferentKotlinMavenVersionInspection : DomElementsInspection<MavenDomProj
|
||||
return
|
||||
}
|
||||
|
||||
val pomFile = PomFile(domFileElement.file)
|
||||
val pomFile = PomFile.forFileOrNull(domFileElement.file) ?: return
|
||||
pomFile.findKotlinPlugins().filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
|
||||
createProblem(holder, plugin)
|
||||
}
|
||||
|
||||
+1
-2
@@ -30,7 +30,6 @@ import org.jetbrains.idea.maven.model.MavenId
|
||||
import org.jetbrains.idea.maven.project.MavenProject
|
||||
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
|
||||
|
||||
@@ -52,7 +51,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
|
||||
return
|
||||
}
|
||||
|
||||
val pomFile = PomFile(file)
|
||||
val pomFile = PomFile.forFileOrNull(file) ?: return
|
||||
pomFile.findKotlinPlugins().filter { it.version.stringValue != stdlibVersion.singleOrNull() }.forEach { plugin ->
|
||||
val fixes = plugin.version.stringValue?.let { version ->
|
||||
createFixes(project, plugin.version, stdlibVersion + version)
|
||||
|
||||
+8
-10
@@ -54,7 +54,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
val manager = MavenProjectsManager.getInstance(module.project)
|
||||
val mavenProject = manager.findProject(module) ?: return
|
||||
|
||||
val pom = PomFile(domFileElement.file)
|
||||
val pom = PomFile.forFileOrNull(domFileElement.file) ?: return
|
||||
val hasJavaFiles = module.hasJavaFiles()
|
||||
|
||||
// all executions including inherited
|
||||
@@ -167,9 +167,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
override fun getFamilyName() = "Create kotlin execution"
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val pom = PomFile(file)
|
||||
|
||||
pom.addKotlinExecution(module, kotlinPlugin, goal, PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal))
|
||||
PomFile.forFileOrNull(file)?.addKotlinExecution(module, kotlinPlugin, goal, PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +186,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
override fun getFamilyName() = getName()
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
PomFile(file).addJavacExecutions(module, kotlinPlugin)
|
||||
PomFile.forFileOrNull(file)?.addJavacExecutions(module, kotlinPlugin)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +195,7 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
override fun getFamilyName() = "Add dependency"
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val file = PomFile(pomFile)
|
||||
file.addDependency(MavenId(KotlinMavenConfigurator.GROUP_ID, id, version), MavenArtifactScope.COMPILE)
|
||||
PomFile.forFileOrNull(pomFile)?.addDependency(MavenId(KotlinMavenConfigurator.GROUP_ID, id, version), MavenArtifactScope.COMPILE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +204,10 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
override fun getFamilyName() = "Create kotlin execution"
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val pom = PomFile(xmlFile)
|
||||
val plugin = pom.addKotlinPlugin(version)
|
||||
pom.addKotlinExecution(module, plugin, "compile", PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal))
|
||||
PomFile.forFileOrNull(xmlFile)?.let { pom ->
|
||||
val plugin = pom.addKotlinPlugin(version)
|
||||
pom.addKotlinExecution(module, plugin, "compile", PomFile.getPhase(module.hasJavaFiles(), false), false, listOf(goal))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -100,10 +100,10 @@ class AddMavenDependencyQuickFix(val className: String, val smartPsiElementPoint
|
||||
val isTestSource = ProjectRootManager.getInstance(project).fileIndex.isInTestSourceContent(virtualFile)
|
||||
val scope = if (isTestSource) MavenArtifactScope.TEST else null
|
||||
|
||||
val pom = PomFile(xmlFile)
|
||||
|
||||
ids.forEach {
|
||||
pom.addDependency(it, scope)
|
||||
PomFile.forFileOrNull(xmlFile)?.let { pom ->
|
||||
ids.forEach {
|
||||
pom.addDependency(it, scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user