Maven: versions inspection: kotlin plugin and library should have the same version
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.lang.annotation.HighlightSeverity
|
||||
import com.intellij.util.xml.DomFileElement
|
||||
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder
|
||||
import com.intellij.util.xml.highlighting.DomElementsInspection
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
|
||||
import org.jetbrains.idea.maven.model.MavenId
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||
|
||||
class SameVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
|
||||
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
|
||||
if (domFileElement == null || holder == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val file = domFileElement.file
|
||||
val module = domFileElement.module ?: return
|
||||
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 pluginVersion = project.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)?.version
|
||||
|
||||
if (pluginVersion == null || stdlibVersion.isEmpty() || stdlibVersion.singleOrNull() == pluginVersion) {
|
||||
return
|
||||
}
|
||||
|
||||
val pomFile = PomFile(file)
|
||||
pomFile.findKotlinPlugins().filter { it.version.stringValue != stdlibVersion.singleOrNull() }.forEach { plugin ->
|
||||
holder.createProblem(plugin.version, HighlightSeverity.WARNING,
|
||||
"Plugin version (${plugin.version}) is not the same as library version (${stdlibVersion.joinToString(",", "", "")})")
|
||||
}
|
||||
|
||||
pomFile.findDependencies(MavenId(KotlinJavaMavenConfigurator.GROUP_ID, KotlinJavaMavenConfigurator.STD_LIB_ID, null))
|
||||
.filter { it.version.stringValue != pluginVersion }
|
||||
.forEach { dependency ->
|
||||
holder.createProblem(dependency.version, HighlightSeverity.WARNING, "Plugin version ($pluginVersion) is not the same as library version (${dependency.version})")
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -65,6 +65,12 @@ public class KotlinMavenInspectionTestGenerated extends AbstractKotlinMavenInspe
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sameVersionPluginLibrary.xml")
|
||||
public void testSameVersionPluginLibrary() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/sameVersionPluginLibrary.xml");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongJsExecution.xml")
|
||||
public void testWrongJsExecution() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/wrongJsExecution.xml");
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.jetbrains.kotlin.test</groupId>
|
||||
<artifactId>configure-maven-test</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version.1>1.0.1</kotlin.version.1>
|
||||
<kotlin.version.2>1.0.1-2</kotlin.version.2>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version.2}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version.1}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
<!-- inspection: org.jetbrains.kotlin.idea.configuration.SameVersionInspection -->
|
||||
<!-- problem: on ${kotlin.version.1}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
|
||||
<!-- problem: on ${kotlin.version.2}, title Plugin version (1.0.1) is not the same as library version (1.0.1-2) -->
|
||||
@@ -33,6 +33,14 @@
|
||||
hasStaticDescription="true"
|
||||
level="WARNING" />
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.SameVersionInspection"
|
||||
displayName="Kotlin Maven: kotlin-test-junit inspection"
|
||||
groupName="Kotlin"
|
||||
enabledByDefault="true"
|
||||
language="XML"
|
||||
hasStaticDescription="true"
|
||||
level="WARNING" />
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.configuration.MavenPluginSourcesMoveToBuild</className>
|
||||
<category>Kotlin</category>
|
||||
|
||||
Reference in New Issue
Block a user