Support annotation-based declaration of target plugin and gradle version
in gradle importing tests
This commit is contained in:
+30
-12
@@ -11,36 +11,54 @@ package org.jetbrains.kotlin.idea.codeInsight.gradle
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.runners.Parameterized
|
import org.junit.runners.Parameterized
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class MultiplePluginVersionGradleImportingTestCase : GradleImportingTestCase() {
|
abstract class MultiplePluginVersionGradleImportingTestCase : GradleImportingTestCase() {
|
||||||
|
@Rule
|
||||||
|
@JvmField
|
||||||
|
var pluginVersionMatchingRule = PluginTargetVersionsRule()
|
||||||
|
|
||||||
val project: Project
|
val project: Project
|
||||||
get() = myProject
|
get() = myProject
|
||||||
|
|
||||||
|
|
||||||
|
override fun isApplicableTest(): Boolean {
|
||||||
|
return pluginVersionMatchingRule.matches(
|
||||||
|
gradleVersion, gradleKotlinPluginVersion,
|
||||||
|
gradleKotlinPluginVersionType == LATEST_SUPPORTED_VERSION
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Parameterized.Parameter(1)
|
@Parameterized.Parameter(1)
|
||||||
var gradleKotlinPluginVersion: String = MINIMAL_SUPPORTED_VERSION
|
var gradleKotlinPluginVersionType: String = MINIMAL_SUPPORTED_VERSION
|
||||||
|
|
||||||
|
val gradleKotlinPluginVersion: String
|
||||||
|
get() = KOTLIN_GRADLE_PLUGIN_VERSION_DESCRIPTION_TO_VERSION[gradleKotlinPluginVersionType] ?: gradleKotlinPluginVersion
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MINIMAL_SUPPORTED_VERSION = "minimal"// minimal supported version
|
const val MINIMAL_SUPPORTED_VERSION = "minimal"// minimal supported version
|
||||||
private val KOTLIN_GRADLE_PLUGIN_VERSIONS = listOf(MINIMAL_SUPPORTED_VERSION, "1.3.50")
|
const val LATEST_STABLE_VERSUON = "latest stable"
|
||||||
|
const val LATEST_SUPPORTED_VERSION = "master"// gradle plugin from current build
|
||||||
|
private val KOTLIN_GRADLE_PLUGIN_VERSIONS = listOf(MINIMAL_SUPPORTED_VERSION, LATEST_STABLE_VERSUON, LATEST_SUPPORTED_VERSION)
|
||||||
|
private val KOTLIN_GRADLE_PLUGIN_VERSION_DESCRIPTION_TO_VERSION = mapOf(
|
||||||
|
MINIMAL_SUPPORTED_VERSION to MINIMAL_SUPPORTED_GRADLE_PLUGIN_VERSION,
|
||||||
|
LATEST_STABLE_VERSUON to LATEST_STABLE_GRADLE_PLUGIN_VERSION,
|
||||||
|
LATEST_SUPPORTED_VERSION to "master"
|
||||||
|
)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Parameterized.Parameters(name = "{index}: Gradle-{0}, KotlinGradlePlugin-{1}")
|
@Parameterized.Parameters(name = "{index}: Gradle-{0}, KotlinGradlePlugin-{1}")
|
||||||
fun data(): Collection<Array<Any>> {
|
fun data(): Collection<Array<Any>> {
|
||||||
return AbstractModelBuilderTest.SUPPORTED_GRADLE_VERSIONS.flatMap { gradleVersion ->
|
return AbstractModelBuilderTest.SUPPORTED_GRADLE_VERSIONS.flatMap { gradleVersion ->
|
||||||
if ((gradleVersion[0] as String).startsWith("3.")) {
|
KOTLIN_GRADLE_PLUGIN_VERSIONS.map { kotlinVersion ->
|
||||||
listOf(arrayOf<Any>(gradleVersion[0], MINIMAL_SUPPORTED_VERSION))
|
arrayOf<Any>(
|
||||||
} else {
|
gradleVersion[0],
|
||||||
KOTLIN_GRADLE_PLUGIN_VERSIONS.map { kotlinVersion ->
|
kotlinVersion
|
||||||
arrayOf<Any>(
|
)
|
||||||
gradleVersion[0],
|
|
||||||
kotlinVersion
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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.codeInsight.gradle;
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion;
|
||||||
|
import org.hamcrest.CustomMatcher;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.plugins.gradle.tooling.annotation.PluginTargetVersions;
|
||||||
|
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions;
|
||||||
|
import org.jetbrains.plugins.gradle.tooling.util.VersionMatcher;
|
||||||
|
import org.junit.rules.TestWatcher;
|
||||||
|
import org.junit.runner.Description;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
// modified copy of org.jetbrains.plugins.gradle.tooling.VersionMatcherRule
|
||||||
|
public class PluginTargetVersionsRule extends TestWatcher {
|
||||||
|
|
||||||
|
private class TargetVersionsImpl implements TargetVersions {
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
TargetVersionsImpl(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkBaseVersions() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> annotationType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private CustomMatcher gradleVersionMatcher;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private CustomMatcher pluginVersionMatcher;
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public boolean matches(String gradleVersion, String pluginVersion, boolean isLatestPluginVersion) {
|
||||||
|
boolean matchGradleVersion = gradleVersionMatcher == null || gradleVersionMatcher.matches(gradleVersion);
|
||||||
|
if (isLatestPluginVersion) {
|
||||||
|
return matchGradleVersion;
|
||||||
|
}
|
||||||
|
boolean pluginVersionMatches = pluginVersionMatcher == null || pluginVersionMatcher.matches(pluginVersion);
|
||||||
|
return matchGradleVersion && pluginVersionMatches;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void starting(Description d) {
|
||||||
|
final PluginTargetVersions pluginTargetVersions = d.getAnnotation(PluginTargetVersions.class);
|
||||||
|
if (d.getAnnotation(TargetVersions.class) != null && pluginTargetVersions != null) {
|
||||||
|
throw new IllegalArgumentException(String.format("Annotations %s and %s could not be used together. ",
|
||||||
|
TargetVersions.class.getName(), PluginTargetVersions.class.getName()));
|
||||||
|
}
|
||||||
|
if (pluginTargetVersions == null) return;
|
||||||
|
|
||||||
|
gradleVersionMatcher = VersionMatcherRule.produceMatcher("Gradle", new TargetVersionsImpl(pluginTargetVersions.gradleVersion()));
|
||||||
|
pluginVersionMatcher = VersionMatcherRule.produceMatcher("Plugin", new TargetVersionsImpl(pluginTargetVersions.pluginVersion()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -42,7 +42,11 @@ public class VersionMatcherRule extends TestWatcher {
|
|||||||
final TargetVersions targetVersions = d.getAnnotation(TargetVersions.class);
|
final TargetVersions targetVersions = d.getAnnotation(TargetVersions.class);
|
||||||
if (targetVersions == null) return;
|
if (targetVersions == null) return;
|
||||||
|
|
||||||
myMatcher = new CustomMatcher<String>("Gradle version '" + targetVersions.value() + "'") {
|
myMatcher = produceMatcher("Gradle", targetVersions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CustomMatcher<String> produceMatcher(String caption, TargetVersions targetVersions) {
|
||||||
|
return new CustomMatcher<String>(caption + " version '" + targetVersions.value() + "'") {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Object item) {
|
public boolean matches(Object item) {
|
||||||
return item instanceof String && new VersionMatcher(GradleVersion.version(item.toString())).isVersionMatch(targetVersions);
|
return item instanceof String && new VersionMatcher(GradleVersion.version(item.toString())).isVersionMatch(targetVersions);
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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.plugins.gradle.tooling.annotation;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||||
|
public @interface PluginTargetVersions {
|
||||||
|
|
||||||
|
String gradleVersion();
|
||||||
|
|
||||||
|
String pluginVersion();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user