diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/configuration/SameVersionIDEPluginInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/configuration/SameVersionIDEPluginInspection.kt new file mode 100644 index 00000000000..f8dda1e9474 --- /dev/null +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/configuration/SameVersionIDEPluginInspection.kt @@ -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::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?, 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") + } +} \ No newline at end of file diff --git a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenInspectionTestGenerated.java b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenInspectionTestGenerated.java index 1aee60e619d..f9777f380ea 100644 --- a/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenInspectionTestGenerated.java +++ b/idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenInspectionTestGenerated.java @@ -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"); diff --git a/idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml b/idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml new file mode 100644 index 00000000000..abd2f7d7e68 --- /dev/null +++ b/idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + org.jetbrains.kotlin.test + configure-maven-test + 1.0-SNAPSHOT + + + 1.0.0 + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + + + + + \ No newline at end of file diff --git a/idea/src/META-INF/maven.xml b/idea/src/META-INF/maven.xml index 333174fa1d7..339ab36a67c 100644 --- a/idea/src/META-INF/maven.xml +++ b/idea/src/META-INF/maven.xml @@ -34,7 +34,15 @@ level="WARNING" /> + +