Maven inspection for incompatible coroutines libraries (KT-25251)
#KT-25251 In Progress
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.maven.inspections
|
||||
|
||||
import com.intellij.codeInspection.CleanupLocalInspectionTool
|
||||
import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.openapi.module.Module
|
||||
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.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.idea.configuration.getWholeModuleGroup
|
||||
import org.jetbrains.kotlin.idea.inspections.migration.DEPRECATED_COROUTINES_LIBRARIES_INFORMATION
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.maven.findDependencies
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
|
||||
class MavenCoroutinesDeprecationInspection :
|
||||
DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java), CleanupLocalInspectionTool {
|
||||
|
||||
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
|
||||
if (domFileElement == null || holder == null) return
|
||||
|
||||
val file = domFileElement.file
|
||||
val module = domFileElement.module ?: return
|
||||
|
||||
val pomFile = PomFile.forFileOrNull(file) ?: return
|
||||
|
||||
for (libInfo in DEPRECATED_COROUTINES_LIBRARIES_INFORMATION) {
|
||||
if (!checkKotlinVersion(module, libInfo.sinceKotlinLanguageVersion)) {
|
||||
// Same result will be for all invocations in this file, so exit
|
||||
return
|
||||
}
|
||||
|
||||
val libMavenId = MavenId(libInfo.lib.groupId, libInfo.lib.name, null)
|
||||
|
||||
val moduleDependencies = pomFile.findDependencies(libMavenId)
|
||||
val dependencyManagementDependencies = pomFile.domModel.dependencyManagement.dependencies.findDependencies(libMavenId)
|
||||
|
||||
for (dependency in moduleDependencies + dependencyManagementDependencies) {
|
||||
val xmlElement = dependency.version.xmlElement
|
||||
if (xmlElement != null) {
|
||||
holder.createProblem(
|
||||
dependency.version,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
libInfo.message,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun checkKotlinVersion(module: Module, languageVersion: LanguageVersion): Boolean {
|
||||
val moduleGroup = module.getWholeModuleGroup()
|
||||
return moduleGroup.sourceRootModules.any { moduleInGroup ->
|
||||
moduleInGroup.languageVersionSettings.languageVersion >= languageVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+5
@@ -49,6 +49,11 @@ public class KotlinMavenInspectionTestGenerated extends AbstractKotlinMavenInspe
|
||||
runTest("idea/idea-maven/testData/maven-inspections/deprecatedJreWithDependencyManagement.xml");
|
||||
}
|
||||
|
||||
@TestMetadata("deprecatedKotlinxCoroutines.xml")
|
||||
public void testDeprecatedKotlinxCoroutines() throws Exception {
|
||||
runTest("idea/idea-maven/testData/maven-inspections/deprecatedKotlinxCoroutines.xml");
|
||||
}
|
||||
|
||||
@TestMetadata("ideAndMavenVersions.xml")
|
||||
public void testIdeAndMavenVersions() throws Exception {
|
||||
runTest("idea/idea-maven/testData/maven-inspections/ideAndMavenVersions.xml");
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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>
|
||||
<kotlin.compiler.languageVersion>1.3</kotlin.compiler.languageVersion>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk7</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-android</artifactId>
|
||||
<version>0.23.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-kotlin-kotlin-eap</id>
|
||||
<name>bintray</name>
|
||||
<url>https://dl.bintray.com/kotlin/kotlin-eap</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-kotlin-kotlinx</id>
|
||||
<name>bintray</name>
|
||||
<url>https://kotlin.bintray.com/kotlinx</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-kotlin-kotlin-eap</id>
|
||||
<name>bintray-plugins</name>
|
||||
<url>https://dl.bintray.com/kotlin/kotlin-eap</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<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.MavenCoroutinesDeprecationInspection -->
|
||||
<!-- problem: on 0.23.4, title Library should be updated to be compatible with Kotlin 1.3 -->
|
||||
Reference in New Issue
Block a user