KT-11743 Intention to replace kotlin-test with kotlin-test-junit

This commit is contained in:
Sergey Mashkov
2016-04-01 19:52:21 +03:00
parent b8327f19b8
commit d097c3e9f1
5 changed files with 195 additions and 0 deletions
@@ -0,0 +1,67 @@
/*
* 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.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.project.Project
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.MavenDomDependency
import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel
import org.jetbrains.idea.maven.project.MavenProjectsManager
class KotlinTestJUnitInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
if (domFileElement == null || holder == null) {
return
}
val module = domFileElement.module ?: return
val manager = MavenProjectsManager.getInstance(module.project) ?: return
val mavenProject = manager.findProject(module) ?: return
val hasJunit = mavenProject.dependencies.any { it.groupId == "junit" && it.artifactId == "junit" }
if (!hasJunit) {
return
}
val kotlinTestDependencies = domFileElement.rootElement.dependencies
.dependencies.filter { it.groupId.rawText == KotlinMavenConfigurator.GROUP_ID && it.artifactId.rawText == KotlinJavaMavenConfigurator.TEST_LIB_ID }
kotlinTestDependencies.forEach {
holder.createProblem(it.artifactId,
HighlightSeverity.WEAK_WARNING,
"kotlin-test-junit is better with junit",
ReplaceToKotlinTest(it)
)
}
}
private class ReplaceToKotlinTest(val dependency: MavenDomDependency) : LocalQuickFix {
override fun getName() = "Replace with kotlin-test-junit"
override fun getFamilyName() = "Kotlin"
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
if (dependency.isValid) {
dependency.artifactId.stringValue = "kotlin-test-junit"
}
}
}
}
@@ -47,6 +47,12 @@ public class KotlinMavenInspectionTestGenerated extends AbstractKotlinMavenInspe
doTest(fileName);
}
@TestMetadata("kotlinTestWithJunit.xml")
public void testKotlinTestWithJunit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/kotlinTestWithJunit.xml");
doTest(fileName);
}
@TestMetadata("missingDependencies.xml")
public void testMissingDependencies() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-maven/testData/maven-inspections/missingDependencies.xml");
@@ -0,0 +1,57 @@
<?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.1</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</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>js</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<!-- inspection: org.jetbrains.kotlin.idea.configuration.KotlinTestJUnitInspection -->
<!-- problem: on kotlin-test, title kotlin-test-junit is better with junit -->
@@ -0,0 +1,57 @@
<?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.1</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</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>js</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<!-- inspection: org.jetbrains.kotlin.idea.configuration.KotlinTestJUnitInspection -->
<!-- problem: on kotlin-test, title kotlin-test-junit is better with junit -->
+8
View File
@@ -16,6 +16,14 @@
hasStaticDescription="true"
level="WARNING" />
<localInspection implementationClass="org.jetbrains.kotlin.idea.configuration.KotlinTestJUnitInspection"
displayName="Kotlin Maven: kotlin-test-junit inspection"
groupName="Kotlin"
enabledByDefault="true"
language="XML"
hasStaticDescription="true"
level="WARNING" />
<intentionAction>
<className>org.jetbrains.kotlin.idea.configuration.MavenPluginSourcesMoveToBuild</className>
<category>Kotlin</category>