Maven: inspection maven plugin and ide plugin should have the same version

This commit is contained in:
Sergey Mashkov
2016-04-04 14:20:23 +03:00
parent aa156c08c6
commit eb789304b6
4 changed files with 100 additions and 1 deletions
@@ -0,0 +1,50 @@
/*
* 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.MavenDomPlugin
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
class SameVersionIDEPluginInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
private val idePluginVersion by lazy {
SameVersionIDEPluginInspection::class.java.classLoader?.getResourceAsStream("META-INF/build.txt")?.bufferedReader()?.use { it.readText() }
}
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
if (domFileElement == null || holder == null) {
return
}
domFileElement.rootElement.build.plugins.plugins.filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
createProblem(holder, plugin)
}
domFileElement.rootElement.build.pluginManagement.plugins.plugins.filter { it.version.exists() && it.version.stringValue != idePluginVersion }.forEach { plugin ->
createProblem(holder, plugin)
}
}
private fun createProblem(holder: DomElementAnnotationHolder, plugin: MavenDomPlugin) {
holder.createProblem(plugin.version,
HighlightSeverity.WARNING,
"You use different IDE and Maven plugins' versions so you code's behaviour may be different")
}
}
@@ -47,6 +47,12 @@ public class KotlinMavenInspectionTestGenerated extends AbstractKotlinMavenInspe
doTest(fileName);
}
@TestMetadata("ideAndMavenVersions.xml")
public void testIdeAndMavenVersions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml");
doTest(fileName);
}
@TestMetadata("kotlinTestWithJunit.xml")
public void testKotlinTestWithJunit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/kotlinTestWithJunit.xml");
@@ -0,0 +1,35 @@
<?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.0.0</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
</plugin>
</plugins>
</build>
</project>
<!-- inspection: org.jetbrains.kotlin.idea.configuration.SameVersionIDEPluginInspection -->
<!-- problem: on ${kotlin.version}, title You use different IDE and Maven plugins' versions so you code's behaviour may be different -->
+9 -1
View File
@@ -34,7 +34,15 @@
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.SameVersionInspection"
displayName="Kotlin Maven: kotlin-test-junit inspection"
displayName="Kotlin Maven: library and plugin inspection"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
hasStaticDescription="true"
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.SameVersionIDEPluginInspection"
displayName="Kotlin Maven: Maven and IDE plugins versions inspection"
groupName="Kotlin"
enabledByDefault="true"
language="XML"