diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt index 8f8ff7972ae..7f2aacd98cb 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/PomFile.kt @@ -416,14 +416,10 @@ class PomFile private constructor(private val xmlFile: XmlFile, val domModel: Ma } fun findDependencies(artifact: MavenId, scope: MavenArtifactScope? = null) = - findDependencies(SmartList(artifact), scope) + domModel.dependencies.findDependencies(artifact, scope) fun findDependencies(artifacts: List, scope: MavenArtifactScope? = null): List { - return domModel.dependencies.dependencies.filter { dependency -> - artifacts.any { artifact -> - dependency.matches(artifact, scope) - } - } + return domModel.dependencies.findDependencies(artifacts, scope) } private fun ensureBuild(): XmlTag = ensureElement(projectElement, "build") @@ -435,14 +431,6 @@ class PomFile private constructor(private val xmlFile: XmlFile, val domModel: Ma private fun MavenDomPlugin.isKotlinMavenPlugin() = groupId.stringValue == KotlinMavenConfigurator.GROUP_ID && artifactId.stringValue == KotlinMavenConfigurator.MAVEN_PLUGIN_ID - private fun MavenDomDependency.matches(artifact: MavenId, scope: MavenArtifactScope?) = - this.matches(artifact) && (this.scope.stringValue == scope?.name?.toLowerCase() || scope == null && this.scope.stringValue == "compile") - - private fun MavenDomArtifactCoordinates.matches(artifact: MavenId) = - (artifact.groupId == null || groupId.stringValue == artifact.groupId) - && (artifact.artifactId == null || artifactId.stringValue == artifact.artifactId) - && (artifact.version == null || version.stringValue == artifact.version) - private fun MavenId.withNoVersion() = MavenId(groupId, artifactId, null) private fun MavenId.withoutJDKSpecificSuffix() = MavenId( groupId, @@ -651,6 +639,25 @@ fun PomFile.changeLanguageVersion(languageVersion: String?, apiVersion: String?) return languageElement ?: apiElement } +internal fun MavenDomDependencies.findDependencies(artifact: MavenId, scope: MavenArtifactScope? = null) = + findDependencies(SmartList(artifact), scope) + +internal fun MavenDomDependencies.findDependencies(artifacts: List, scope: MavenArtifactScope? = null): List { + return dependencies.filter { dependency -> + artifacts.any { artifact -> + dependency.matches(artifact, scope) + } + } +} + +private fun MavenDomDependency.matches(artifact: MavenId, scope: MavenArtifactScope?) = + this.matches(artifact) && (this.scope.stringValue == scope?.name?.toLowerCase() || scope == null && this.scope.stringValue == "compile") + +private fun MavenDomArtifactCoordinates.matches(artifact: MavenId) = + (artifact.groupId == null || groupId.stringValue == artifact.groupId) + && (artifact.artifactId == null || artifactId.stringValue == artifact.artifactId) + && (artifact.version == null || version.stringValue == artifact.version) + private fun PomFile.changeConfigurationOrProperty( kotlinPlugin: MavenDomPlugin, configurationTagName: String, diff --git a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt index 69e42805cb2..49f58cd906c 100644 --- a/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt +++ b/idea/idea-maven/src/org/jetbrains/kotlin/idea/maven/inspections/DeprecatedMavenDependencyInspection.kt @@ -26,6 +26,7 @@ import org.jetbrains.idea.maven.model.MavenId import org.jetbrains.idea.maven.project.MavenProjectsManager import org.jetbrains.kotlin.idea.inspections.ReplaceStringInDocumentFix import org.jetbrains.kotlin.idea.maven.PomFile +import org.jetbrains.kotlin.idea.maven.findDependencies import org.jetbrains.kotlin.idea.versions.DEPRECATED_LIBRARIES_INFORMATION class DeprecatedMavenDependencyInspection : DomElementsInspection(MavenDomProjectModel::class.java) { @@ -35,32 +36,39 @@ class DeprecatedMavenDependencyInspection : DomElementsInspection= 0 } - .forEach { dependency -> - val xmlElement = dependency.artifactId.xmlElement - if (xmlElement != null) { - val fix = ReplaceStringInDocumentFix(xmlElement, libInfo.old.name, libInfo.new.name) - holder.createProblem( - dependency.artifactId, - ProblemHighlightType.LIKE_DEPRECATED, - libInfo.message, - null, - fix - ) - } + val dependencyManagementDependencies = pomFile.domModel.dependencyManagement.dependencies.findDependencies(libMavenId).filter { + val version = it.version?.value + version != null && VersionComparatorUtil.COMPARATOR.compare(version, libInfo.outdatedAfterVersion) >= 0 + } + + for (dependency in moduleDependencies + dependencyManagementDependencies) { + val xmlElement = dependency.artifactId.xmlElement + if (xmlElement != null) { + val fix = ReplaceStringInDocumentFix(xmlElement, libInfo.old.name, libInfo.new.name) + + holder.createProblem( + dependency.artifactId, + ProblemHighlightType.LIKE_DEPRECATED, + libInfo.message, + null, + fix + ) } + } } } } \ 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 34c4290c045..768f82d4088 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 @@ -43,6 +43,12 @@ public class KotlinMavenInspectionTestGenerated extends AbstractKotlinMavenInspe doTest(fileName); } + @TestMetadata("deprecatedJreWithDependencyManagement.xml") + public void testDeprecatedJreWithDependencyManagement() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.xml"); + doTest(fileName); + } + @TestMetadata("ideAndMavenVersions.xml") public void testIdeAndMavenVersions() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml"); diff --git a/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.1.xml b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.1.xml new file mode 100644 index 00000000000..0c8f4542bb4 --- /dev/null +++ b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.1.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + maventest + maventest + 1.0-SNAPSHOT + + + 1.2.0 + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jre7 + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + + + + + + + \ No newline at end of file diff --git a/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.2.xml b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.2.xml new file mode 100644 index 00000000000..b0a621c6456 --- /dev/null +++ b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.fixed.2.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + maventest + maventest + 1.0-SNAPSHOT + + + 1.2.0 + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jre7 + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + + + + + + + \ No newline at end of file diff --git a/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.xml b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.xml new file mode 100644 index 00000000000..fccec24e9d8 --- /dev/null +++ b/idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + maventest + maventest + 1.0-SNAPSHOT + + + 1.2.0 + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jre7 + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jre7 + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + + + + + + +