Process dependencyManagement during stdlib-jre* deprecation check (KT-21745, KT-23161)
#KT-23161 Fixed #KT-21745 Fixed
This commit is contained in:
@@ -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<MavenId>, scope: MavenArtifactScope? = null): List<MavenDomDependency> {
|
||||
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<MavenId>, scope: MavenArtifactScope? = null): List<MavenDomDependency> {
|
||||
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,
|
||||
|
||||
+24
-16
@@ -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>(MavenDomProjectModel::class.java) {
|
||||
@@ -35,32 +36,39 @@ class DeprecatedMavenDependencyInspection : DomElementsInspection<MavenDomProjec
|
||||
val file = domFileElement.file
|
||||
val module = domFileElement.module ?: return
|
||||
val manager = MavenProjectsManager.getInstance(module.project) ?: return
|
||||
val project = manager.findProject(module) ?: return
|
||||
val mavenProject = manager.findProject(module) ?: return
|
||||
|
||||
val pomFile = PomFile.forFileOrNull(file) ?: return
|
||||
|
||||
for (libInfo in DEPRECATED_LIBRARIES_INFORMATION) {
|
||||
pomFile.findDependencies(MavenId(libInfo.old.groupId, libInfo.old.name, null))
|
||||
.filter { it.version?.stringValue != null }
|
||||
val libMavenId = MavenId(libInfo.old.groupId, libInfo.old.name, null)
|
||||
|
||||
val moduleDependencies = pomFile.findDependencies(libMavenId)
|
||||
.filter {
|
||||
val libVersion =
|
||||
project.findDependencies(libInfo.old.groupId, libInfo.old.name).map { it.version }.distinct().singleOrNull()
|
||||
mavenProject.findDependencies(libInfo.old.groupId, libInfo.old.name).map { it.version }.distinct().singleOrNull()
|
||||
libVersion != null && VersionComparatorUtil.COMPARATOR.compare(libVersion, libInfo.outdatedAfterVersion) >= 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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -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");
|
||||
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
<?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>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.2.0</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
<!-- inspection: org.jetbrains.kotlin.idea.maven.inspections.DeprecatedMavenDependencyInspection -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
<?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>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.2.0</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
<!-- inspection: org.jetbrains.kotlin.idea.maven.inspections.DeprecatedMavenDependencyInspection -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<?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>maventest</groupId>
|
||||
<artifactId>maventest</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<kotlin.version>1.2.0</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
<!-- inspection: org.jetbrains.kotlin.idea.maven.inspections.DeprecatedMavenDependencyInspection -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
<!-- problem: on kotlin-stdlib-jre7, title kotlin-stdlib-jre7 is deprecated since 1.2.0 and should be replaced with kotlin-stdlib-jdk7 -->
|
||||
Reference in New Issue
Block a user