Inspection doesn't suggest Maven Plugin for kotlin-stdlib-jre8 (KT-18007)
#KT-18007 Fixed
This commit is contained in:
@@ -42,6 +42,7 @@ import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.kotlin.idea.configuration.RepositoryDescription
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import java.util.*
|
||||
|
||||
fun kotlinPluginId(version: String?) = MavenId(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID, version)
|
||||
@@ -415,7 +416,15 @@ class PomFile private constructor(private val xmlFile: XmlFile, val domModel: Ma
|
||||
}
|
||||
|
||||
fun findDependencies(artifact: MavenId, scope: MavenArtifactScope? = null) =
|
||||
domModel.dependencies.dependencies.filter { it.matches(artifact, scope) }
|
||||
findDependencies(SmartList(artifact), scope)
|
||||
|
||||
fun findDependencies(artifacts: List<MavenId>, scope: MavenArtifactScope? = null): List<MavenDomDependency> {
|
||||
return domModel.dependencies.dependencies.filter { dependency ->
|
||||
artifacts.any { artifact ->
|
||||
dependency.matches(artifact, scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ensureBuild(): XmlTag = ensureElement(projectElement, "build")
|
||||
|
||||
|
||||
+14
-5
@@ -38,11 +38,20 @@ 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.KotlinMavenConfigurator
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
import org.jetbrains.kotlin.idea.versions.*
|
||||
import java.util.*
|
||||
|
||||
class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
|
||||
companion object {
|
||||
private val STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null)
|
||||
private val STDLIB_JRE7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE7, null)
|
||||
private val STDLIB_JDK7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK7, null)
|
||||
private val STDLIB_JRE8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE8, null)
|
||||
private val STDLIB_JDK8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK8, null)
|
||||
|
||||
private val JVM_STDLIB_IDS = listOf(STDLIB_MAVEN_ID, STDLIB_JRE7_MAVEN_ID, STDLIB_JDK7_MAVEN_ID, STDLIB_JRE8_MAVEN_ID, STDLIB_JDK8_MAVEN_ID)
|
||||
}
|
||||
|
||||
override fun getStaticDescription() = "Reports kotlin-maven-plugin configuration issues"
|
||||
|
||||
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
|
||||
@@ -142,9 +151,9 @@ class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectMo
|
||||
}
|
||||
}
|
||||
|
||||
val stdlibDependencies = pom.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null))
|
||||
if (!hasJvmExecution && stdlibDependencies.isNotEmpty()) {
|
||||
stdlibDependencies.forEach { dep ->
|
||||
val jvmStdlibDependencies = pom.findDependencies(JVM_STDLIB_IDS)
|
||||
if (!hasJvmExecution && jvmStdlibDependencies.isNotEmpty()) {
|
||||
jvmStdlibDependencies.forEach { dep ->
|
||||
holder.createProblem(
|
||||
dep.artifactId.createStableCopy(),
|
||||
HighlightSeverity.WARNING,
|
||||
|
||||
+38
-7
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.idea.maven.inspections.KotlinMavenPluginPhaseInspect
|
||||
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() {
|
||||
@@ -64,8 +65,10 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() {
|
||||
val inspectionClass = Class.forName(inspectionClassName)
|
||||
|
||||
val matcher = "<!--\\s*problem:\\s*on\\s*([^,]+),\\s*title\\s*(.+)\\s*-->".toRegex()
|
||||
val expected = pomText.lines().mapNotNull { matcher.find(it) }
|
||||
.map { SimplifiedProblemDescription(it.groups[2]!!.value.trim(), it.groups[1]!!.value.trim()) }
|
||||
val expectedProblemsText = pomText.lines()
|
||||
.filter { matcher.matches(it) }
|
||||
.joinToString("\n")
|
||||
|
||||
val problemElements = runInspection(inspectionClass, myProject).problemElements
|
||||
val actualProblems = problemElements
|
||||
.keys()
|
||||
@@ -78,7 +81,11 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() {
|
||||
.map { SimplifiedProblemDescription(it.descriptionTemplate, it.psiElement.text.replace("\\s+".toRegex(), "")) to it }
|
||||
.sortedBy { it.first.text }
|
||||
|
||||
assertEquals(expected.sortedBy { it.text }, actual.map { it.first })
|
||||
val actualProblemsText = actual
|
||||
.map { it.first }
|
||||
.joinToString("\n") { "<!-- problem: on ${it.elementText}, title ${it.text} -->"}
|
||||
|
||||
assertEquals(expectedProblemsText, actualProblemsText)
|
||||
|
||||
val suggestedFixes = actual.flatMap { p -> p.second.fixes?.sortedBy { it.familyName }?.map { p.second to it } ?: emptyList() }
|
||||
|
||||
@@ -86,10 +93,33 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() {
|
||||
val fixFiles =
|
||||
pomFile.parentFile.listFiles { _, name -> name.startsWith(filenamePrefix) && name.endsWith(".xml") }.sortedBy { it.name }
|
||||
|
||||
if (fixFiles.size > suggestedFixes.size) {
|
||||
val rangesToFixFiles: Map<File, IntRange> = fixFiles.keysToMap {
|
||||
val fixFileName = it.name
|
||||
val fixRangeStr = fixFileName.substringBeforeLast('.').substringAfterLast('.')
|
||||
val numbers = fixRangeStr.split('-').map { it.toInt() }
|
||||
when (numbers.size) {
|
||||
0 -> error("No number in fix file $fixFileName")
|
||||
1 -> IntRange(numbers[0], numbers[0])
|
||||
2 -> IntRange(numbers[0], numbers[1])
|
||||
else -> error("Bad range `$fixRangeStr` in fix file $fixFileName")
|
||||
}
|
||||
}
|
||||
|
||||
val sortedFixRanges = rangesToFixFiles.values.sortedBy { it.start }
|
||||
sortedFixRanges.forEachIndexed { i, range ->
|
||||
if (i > 0) {
|
||||
val previous = sortedFixRanges[i - 1]
|
||||
if (previous.endInclusive + 1 != range.start) {
|
||||
error("Bad ranges in fix files: $previous and $range")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val numberOfFixDataFiles = sortedFixRanges.lastOrNull()?.endInclusive ?: 0
|
||||
if (numberOfFixDataFiles > suggestedFixes.size) {
|
||||
fail("Not all fixes were suggested by the inspection: expected count: ${fixFiles.size}, actual fixes count: ${suggestedFixes.size}")
|
||||
}
|
||||
if (fixFiles.size < suggestedFixes.size) {
|
||||
if (numberOfFixDataFiles < suggestedFixes.size) {
|
||||
fail("Not all fixes covered by *.fixed.N.xml files")
|
||||
}
|
||||
|
||||
@@ -97,8 +127,9 @@ abstract class AbstractKotlinMavenInspectionTest : MavenImportingTestCase() {
|
||||
val document = documentManager.getDocument(PsiManager.getInstance(myProject).findFile(myProjectPom)!!)!!
|
||||
val originalText = document.text
|
||||
|
||||
fixFiles.forEachIndexed { index, file ->
|
||||
val (problem, quickfix) = suggestedFixes[index]
|
||||
suggestedFixes.forEachIndexed { index, suggestedFix ->
|
||||
val (problem, quickfix) = suggestedFix
|
||||
val file = rangesToFixFiles.entries.first { (_, range) -> index + 1 in range }.key
|
||||
|
||||
quickfix.applyFix(problem)
|
||||
|
||||
|
||||
+24
@@ -18,6 +18,26 @@
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-js</artifactId>
|
||||
@@ -48,4 +68,8 @@
|
||||
</project>
|
||||
|
||||
<!-- problem: on kotlin-stdlib, title You have kotlin-stdlib configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk7, title You have kotlin-stdlib-jdk7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk8, title You have kotlin-stdlib-jdk8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title You have kotlin-stdlib-jre7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre8, title You have kotlin-stdlib-jre8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-js, title You have kotlin-stdlib-js configured but no corresponding plugin execution -->
|
||||
+24
@@ -18,6 +18,26 @@
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-js</artifactId>
|
||||
@@ -48,4 +68,8 @@
|
||||
</project>
|
||||
|
||||
<!-- problem: on kotlin-stdlib, title You have kotlin-stdlib configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk7, title You have kotlin-stdlib-jdk7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk8, title You have kotlin-stdlib-jdk8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title You have kotlin-stdlib-jre7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre8, title You have kotlin-stdlib-jre8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-js, title You have kotlin-stdlib-js configured but no corresponding plugin execution -->
|
||||
@@ -18,6 +18,26 @@
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-js</artifactId>
|
||||
@@ -27,4 +47,8 @@
|
||||
</project>
|
||||
|
||||
<!-- problem: on kotlin-stdlib, title You have kotlin-stdlib configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk7, title You have kotlin-stdlib-jdk7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jdk8, title You have kotlin-stdlib-jdk8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title You have kotlin-stdlib-jre7 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-jre8, title You have kotlin-stdlib-jre8 configured but no corresponding plugin execution -->
|
||||
<!-- problem: on kotlin-stdlib-js, title You have kotlin-stdlib-js configured but no corresponding plugin execution -->
|
||||
|
||||
Reference in New Issue
Block a user