From 09b21a91edbab6c3e5331685fe281473f56feeb0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 21 May 2021 18:08:07 +0100 Subject: [PATCH] Adopt compatibility testing plugin Closes gh-728 --- .../build/matrix/MatrixTestExtension.groovy | 105 ------------------ .../build/matrix/MatrixTestPlugin.groovy | 28 ----- .../gradle-plugins/matrixtest.properties | 1 - settings.gradle | 2 +- spring-restdocs-asciidoctor/build.gradle | 12 +- spring-restdocs-core/build.gradle | 10 +- spring-restdocs-mockmvc/build.gradle | 10 +- spring-restdocs-restassured/build.gradle | 10 +- spring-restdocs-webtestclient/build.gradle | 12 +- 9 files changed, 28 insertions(+), 162 deletions(-) delete mode 100644 buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestExtension.groovy delete mode 100644 buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestPlugin.groovy delete mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/matrixtest.properties diff --git a/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestExtension.groovy b/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestExtension.groovy deleted file mode 100644 index 543316fd..00000000 --- a/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestExtension.groovy +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * 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 - * - * https://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.springframework.restdocs.build.matrix - -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.plugins.JavaBasePlugin -import org.gradle.api.tasks.testing.Test - -class MatrixTestExtension { - - private List entries = [] - - MatrixTestExtension(Project project) { - project.afterEvaluate { - configureTestTasks(project) - } - } - - void methodMissing(String name, args) { - Entry entry = new Entry(); - Closure closure = args[0] - closure.delegate = entry - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure.call() - entries << entry - } - - void configureTestTasks(Project project) { - if (!entries.empty) { - cartesianProduct(entries.collect { entry -> - entry.versions.collect { ['group': entry.group, 'artifact': entry.artifact, 'version': it] } - }).forEach { configureTestTask(project, it) } - } - } - - void configureTestTask(Project project, List> versionSelectors) { - String identifier = ""; - versionSelectors.forEach { - identifier += "_${it.group}_${it.version}" - } - String description = "Runs the unit tests using " - description += versionSelectors.collect { "${it.group} ${it.version}" }.join(", ") - Test matrixTest = project.tasks.create("matrixTest" + identifier, Test) { test -> - test.setDescription(description); - test.setGroup(JavaBasePlugin.VERIFICATION_GROUP); - def testSourceSet = project.sourceSets.test - def configuration = project.configurations.create(testSourceSet.runtimeClasspathConfigurationName + identifier) { - extendsFrom(project.configurations.getByName(testSourceSet.runtimeClasspathConfigurationName)) - resolutionStrategy.eachDependency { dependency -> - versionSelectors - .findAll{ it.group == dependency.requested.group } - .findAll { !it.artifact || it.artifact == dependency.requested.name } - .each { dependency.useVersion it.version } - } - } - classpath = project.files(testSourceSet.output, project.sourceSets.main.output, configuration) - } - project.tasks.getByName('check').dependsOn(matrixTest) - } - - List>> cartesianProduct(List>> lists) { - return cartesianProduct(lists, 0) - } - - List>> cartesianProduct(List>> lists, int index) { - List>> result = []; - if (index == lists.size()) { - result.add([]); - } else { - lists.get(index).each { list -> - cartesianProduct(lists, index + 1).each { product -> - product.add(list) - result.add(product) - } - } - } - return result; - } - - class Entry { - - String group - - String artifact - - List versions - - } - -} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestPlugin.groovy b/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestPlugin.groovy deleted file mode 100644 index 65551d11..00000000 --- a/buildSrc/src/main/groovy/org/springframework/restdocs/build/matrix/MatrixTestPlugin.groovy +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * 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 - * - * https://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.springframework.restdocs.build.matrix - -import org.gradle.api.Plugin -import org.gradle.api.Project - -class MatrixTestPlugin implements Plugin { - - void apply(Project project) { - project.extensions.create('matrixTest', MatrixTestExtension, project) - } - -} diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/matrixtest.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/matrixtest.properties deleted file mode 100644 index 4af96aba..00000000 --- a/buildSrc/src/main/resources/META-INF/gradle-plugins/matrixtest.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class: org.springframework.restdocs.build.matrix.MatrixTestPlugin \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 91035a9c..6ed71662 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ pluginManagement { repositories { mavenCentral() - maven { url "https://repo.spring.io/plugins-release" } + maven { url "https://repo.spring.io/plugins-release-local" } gradlePluginPortal() } } diff --git a/spring-restdocs-asciidoctor/build.gradle b/spring-restdocs-asciidoctor/build.gradle index d9337562..1b4ad459 100644 --- a/spring-restdocs-asciidoctor/build.gradle +++ b/spring-restdocs-asciidoctor/build.gradle @@ -1,7 +1,7 @@ plugins { + id "io.spring.compatibility-test" version "0.0.1" id "java-library" id "maven-publish" - id "matrixtest" } description = "Spring REST Docs Asciidoctor Extension" @@ -34,11 +34,11 @@ jar { from configurations.merge.collect { file -> zipTree(file) } } -matrixTest { - asciidoctorj { - group = "org.asciidoctor" - artifact = "asciidoctorj" - versions = [ asciidoctorj16Version, +compatibilityTest { + dependency('AsciidoctorJ') { asciidoctorJ -> + asciidoctorJ.groupId = "org.asciidoctor" + asciidoctorJ.artifactId = "asciidoctorj" + asciidoctorJ.versions = [ asciidoctorj16Version, asciidoctorj20Version, asciidoctorj21Version, asciidoctorj22Version, diff --git a/spring-restdocs-core/build.gradle b/spring-restdocs-core/build.gradle index 9b010c8f..7faed656 100644 --- a/spring-restdocs-core/build.gradle +++ b/spring-restdocs-core/build.gradle @@ -1,6 +1,6 @@ plugins { + id "io.spring.compatibility-test" version "0.0.1" id "java-library" - id "matrixtest" id "maven-publish" id "optional-dependencies" } @@ -76,9 +76,9 @@ artifacts { testArtifacts testJar } -matrixTest { - springFramework { - group = "org.springframework" - versions = ["5.1.+", "5.2.+"] +compatibilityTest { + dependency("Spring Framework") { springFramework -> + springFramework.groupId = "org.springframework" + springFramework.versions = ["5.1.+", "5.2.+", "5.3.+"] } } diff --git a/spring-restdocs-mockmvc/build.gradle b/spring-restdocs-mockmvc/build.gradle index 9d6ca74e..c6412de5 100644 --- a/spring-restdocs-mockmvc/build.gradle +++ b/spring-restdocs-mockmvc/build.gradle @@ -1,6 +1,6 @@ plugins { + id "io.spring.compatibility-test" version "0.0.1" id "java-library" - id "matrixtest" id "maven-publish" id "optional-dependencies" } @@ -25,9 +25,9 @@ dependencies { testRuntimeOnly("commons-logging:commons-logging:1.2") } -matrixTest { - springFramework { - group = "org.springframework" - versions = ["5.1.+", "5.2.+", "5.3.+"] +compatibilityTest { + dependency("Spring Framework") { springFramework -> + springFramework.groupId = "org.springframework" + springFramework.versions = ["5.1.+", "5.2.+", "5.3.+"] } } diff --git a/spring-restdocs-restassured/build.gradle b/spring-restdocs-restassured/build.gradle index c4eddc8d..59de1baa 100644 --- a/spring-restdocs-restassured/build.gradle +++ b/spring-restdocs-restassured/build.gradle @@ -1,6 +1,6 @@ plugins { + id "io.spring.compatibility-test" version "0.0.1" id "java-library" - id "matrixtest" id "maven-publish" } @@ -22,9 +22,9 @@ dependencies { testImplementation("org.mockito:mockito-core") } -matrixTest { - restAssured { - group = "io.rest-assured" - versions = ["4.0.0", "4.1.2", "4.2.0", "4.3.1"] +compatibilityTest { + dependency("REST Assured") { restAssured -> + restAssured.groupId = "io.rest-assured" + restAssured.versions = ["4.0.0", "4.1.2", "4.2.0", "4.3.1"] } } diff --git a/spring-restdocs-webtestclient/build.gradle b/spring-restdocs-webtestclient/build.gradle index f13aa0df..5d60f633 100644 --- a/spring-restdocs-webtestclient/build.gradle +++ b/spring-restdocs-webtestclient/build.gradle @@ -1,6 +1,6 @@ plugins { + id "io.spring.compatibility-test" version "0.0.1" id "java-library" - id "matrixtest" id "maven-publish" } @@ -22,15 +22,15 @@ dependencies { testRuntimeOnly("org.synchronoss.cloud:nio-multipart-parser") } -matrixTest { - springFramework { - group = "org.springframework" - versions = ["5.1.+", "5.2.+", "5.3.+"] +compatibilityTest { + dependency("Spring Framework") { springFramework -> + springFramework.groupId = "org.springframework" + springFramework.versions = ["5.1.+", "5.2.+", "5.3.+"] } } project.afterEvaluate { - configurations.getByName("testRuntimeClasspath_org.springframework_5.3.+") { + configurations.getByName("testRuntimeClasspath_spring_framework_5.3.+") { exclude group: "org.synchronoss.cloud", module: "nio-multipart-parser" } }