From 7756247c3a284da8395bd6aca4fff69bde90b449 Mon Sep 17 00:00:00 2001 From: Marcus Da Coregio Date: Wed, 14 Sep 2022 10:40:08 -0300 Subject: [PATCH] Simplify checkSamples task Closes gh-11814 --- .../continuous-integration-workflow.yml | 6 +- build.gradle | 19 +- .../io/spring/gradle/IncludeRepoTask.groovy | 2 +- .../IncludeCheckRemotePlugin.groovy | 86 --------- ...convention.include-check-remote.properties | 1 - .../IncludeCheckRemotePluginTest.java | 179 ------------------ 6 files changed, 13 insertions(+), 280 deletions(-) delete mode 100644 buildSrc/src/main/groovy/io/spring/gradle/convention/IncludeCheckRemotePlugin.groovy delete mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.include-check-remote.properties delete mode 100644 buildSrc/src/test/java/io/spring/gradle/convention/IncludeCheckRemotePluginTest.java diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 8653fd71a8..3ec3439ff2 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -98,13 +98,15 @@ jobs: - name: Check samples project env: LOCAL_REPOSITORY_PATH: ${{ github.workspace }}/build/publications/repos - SAMPLES_INIT_SCRIPT: ${{ github.workspace }}/build/includeRepo/spring-security-ci.gradle + SAMPLES_DIR: ../spring-security-samples + VERSION: ${{ needs.prerequisites.outputs.project_version }} run: | export GRADLE_ENTERPRISE_CACHE_USERNAME="$GRADLE_ENTERPRISE_CACHE_USER" export GRADLE_ENTERPRISE_CACHE_PASSWORD="$GRADLE_ENTERPRISE_CACHE_PASSWORD" export GRADLE_ENTERPRISE_ACCESS_KEY="$GRADLE_ENTERPRISE_SECRET_ACCESS_KEY" ./gradlew publishMavenJavaPublicationToLocalRepository - ./gradlew checkSamples -PsamplesInitScript="$SAMPLES_INIT_SCRIPT" -PlocalRepositoryPath="$LOCAL_REPOSITORY_PATH" --stacktrace + ./gradlew cloneSamples -PcloneOutputDirectory="$SAMPLES_DIR" + ./gradlew --project-dir "$SAMPLES_DIR" --init-script spring-security-ci.gradle -PlocalRepositoryPath="$LOCAL_REPOSITORY_PATH" -PspringSecurityVersion="$VERSION" :runAllTests check_tangles: name: Check for Package Tangles needs: [ prerequisites ] diff --git a/build.gradle b/build.gradle index d843618455..a43f7ec591 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import io.spring.gradle.IncludeRepoTask + buildscript { dependencies { classpath "io.spring.javaformat:spring-javaformat-gradle-plugin:$springJavaformatVersion" @@ -16,7 +18,6 @@ apply plugin: 'io.spring.nohttp' apply plugin: 'locks' apply plugin: 's101' apply plugin: 'io.spring.convention.root' -apply plugin: 'io.spring.convention.include-check-remote' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.springframework.security.update-dependencies' apply plugin: 'org.springframework.security.update-version' @@ -201,17 +202,13 @@ nohttp { } -tasks.register('checkSamples') { - includeCheckRemote { - repository = 'spring-projects/spring-security-samples' - ref = samplesBranch - buildScan = true - if (project.hasProperty("samplesInitScript")) { - initScripts = [samplesInitScript] - projectProperties = ["localRepositoryPath": localRepositoryPath, "springSecurityVersion": project.version] - } +tasks.register('cloneSamples', IncludeRepoTask) { + if (!project.hasProperty("cloneOutputDirectory")) { + throw new GradleException("Required parameter 'cloneOutputDirectory' not found") } - dependsOn checkRemote + repository = 'spring-projects/spring-security-samples' + ref = samplesBranch + outputDirectory = project.file("$cloneOutputDirectory") } s101 { diff --git a/buildSrc/src/main/groovy/io/spring/gradle/IncludeRepoTask.groovy b/buildSrc/src/main/groovy/io/spring/gradle/IncludeRepoTask.groovy index b549ff7309..b7d8235a24 100644 --- a/buildSrc/src/main/groovy/io/spring/gradle/IncludeRepoTask.groovy +++ b/buildSrc/src/main/groovy/io/spring/gradle/IncludeRepoTask.groovy @@ -54,7 +54,7 @@ abstract class IncludeRepoTask extends DefaultTask { * Directory where the project template should be copied. */ @OutputDirectory - final File outputDirectory = project.file("$project.buildDir/$name") + File outputDirectory = project.file("$project.buildDir/$name") @TaskAction void checkoutAndCopy() { diff --git a/buildSrc/src/main/groovy/io/spring/gradle/convention/IncludeCheckRemotePlugin.groovy b/buildSrc/src/main/groovy/io/spring/gradle/convention/IncludeCheckRemotePlugin.groovy deleted file mode 100644 index d145955b5e..0000000000 --- a/buildSrc/src/main/groovy/io/spring/gradle/convention/IncludeCheckRemotePlugin.groovy +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2002-2022 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 io.spring.gradle.convention - -import io.spring.gradle.IncludeRepoTask -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.tasks.GradleBuild -import org.gradle.api.tasks.TaskProvider - -/** - * Adds a set of tasks that make easy to clone a remote repository and perform some task - * - * @author Marcus Da Coregio - */ -class IncludeCheckRemotePlugin implements Plugin { - @Override - void apply(Project project) { - IncludeCheckRemoteExtension extension = project.extensions.create('includeCheckRemote', IncludeCheckRemoteExtension) - TaskProvider includeRepoTask = project.tasks.register('includeRepo', IncludeRepoTask) { IncludeRepoTask it -> - it.repository = extension.repository - it.ref = extension.ref - } - project.tasks.register('checkRemote', GradleBuild) { - it.dependsOn 'includeRepo' - it.dir = includeRepoTask.get().outputDirectory - it.tasks = extension.getTasks() - it.startParameter.buildScan = extension.getBuildScan() - extension.getInitScripts().forEach {script -> - it.startParameter.addInitScript(new File(script)) - } - extension.getProjectProperties().entrySet().forEach { entry -> - it.startParameter.projectProperties.put(entry.getKey(), entry.getValue()) - } - } - } - - abstract static class IncludeCheckRemoteExtension { - - /** - * Git repository to clone - */ - String repository; - - /** - * Git ref to checkout - */ - String ref - - /** - * Task to run in the repository - */ - List tasks = ['check'] - - /** - * Init scripts for the build - */ - List initScripts = [] - - /** - * Map of properties for the build - */ - Map projectProperties = [:] - - /** - * Whether the Build Scan should be published - */ - boolean buildScan = false - - } - -} diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.include-check-remote.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.include-check-remote.properties deleted file mode 100644 index 298e1bbad2..0000000000 --- a/buildSrc/src/main/resources/META-INF/gradle-plugins/io.spring.convention.include-check-remote.properties +++ /dev/null @@ -1 +0,0 @@ -implementation-class=io.spring.gradle.convention.IncludeCheckRemotePlugin diff --git a/buildSrc/src/test/java/io/spring/gradle/convention/IncludeCheckRemotePluginTest.java b/buildSrc/src/test/java/io/spring/gradle/convention/IncludeCheckRemotePluginTest.java deleted file mode 100644 index 9b0ae298b1..0000000000 --- a/buildSrc/src/test/java/io/spring/gradle/convention/IncludeCheckRemotePluginTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2002-2022 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 io.spring.gradle.convention; - -import java.io.File; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import io.spring.gradle.IncludeRepoTask; -import org.apache.commons.io.FileUtils; -import org.gradle.api.Project; -import org.gradle.api.tasks.GradleBuild; -import org.gradle.testfixtures.ProjectBuilder; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class IncludeCheckRemotePluginTest { - - Project rootProject; - - @AfterEach - public void cleanup() throws Exception { - if (rootProject != null) { - FileUtils.deleteDirectory(rootProject.getProjectDir()); - } - } - - @Test - void applyWhenExtensionPropertiesNoTasksThenCreateCheckRemoteTaskWithDefaultTask() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote.getTasks()).containsExactly("check"); - } - - @Test - void applyWhenExtensionPropertiesTasksThenCreateCheckRemoteWithProvidedTasks() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - includeCheckRemoteExtension.setProperty("tasks", Arrays.asList("clean", "build", "test")); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote.getTasks()).containsExactly("clean", "build", "test"); - } - - @Test - void applyWhenExtensionPropertiesInitScriptsThenCreateCheckRemoteWithProvidedTasks() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - includeCheckRemoteExtension.setProperty("initScripts", Arrays.asList("spring-security-ci.gradle")); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote.getStartParameter().getAllInitScripts()).extracting(File::getName).containsExactly("spring-security-ci.gradle"); - } - - @Test - void applyWhenExtensionPropertiesBuildPropertiesThenCreateCheckRemoteWithProvidedTasks() { - Map projectProperties = new HashMap<>(); - projectProperties.put("localRepositoryPath", "~/local/repository"); - projectProperties.put("anotherProperty", "some_value"); - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - includeCheckRemoteExtension.setProperty("projectProperties", projectProperties); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote.getStartParameter().getProjectProperties()).containsEntry("localRepositoryPath", "~/local/repository") - .containsEntry("anotherProperty", "some_value"); - } - - @Test - void applyWhenExtensionPropertiesThenRegisterIncludeRepoTaskWithExtensionProperties() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - }); - - IncludeRepoTask includeRepo = (IncludeRepoTask) this.rootProject.getTasks().named("includeRepo").get(); - assertThat(includeRepo).isNotNull(); - assertThat(includeRepo.getRepository().get()).isEqualTo("my-project/my-repository"); - assertThat(includeRepo.getRef().get()).isEqualTo("main"); - } - - @Test - void applyWhenRegisterTasksThenCheckRemoteDirSameAsIncludeRepoOutputDir() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - }); - IncludeRepoTask includeRepo = (IncludeRepoTask) this.rootProject.getTasks().named("includeRepo").get(); - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote.getDir()).isEqualTo(includeRepo.getOutputDirectory()); - } - - @Test - void applyWhenNoExtensionPropertiesThenRegisterTasks() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - IncludeRepoTask includeRepo = (IncludeRepoTask) this.rootProject.getTasks().named("includeRepo").get(); - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(includeRepo).isNotNull(); - assertThat(checkRemote).isNotNull(); - } - - @Test - void applyWhenNoBuildScanSpecifiedThenRegisterCheckRemoteTaskWithBuildScanFalse() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote).isNotNull(); - assertThat(checkRemote.getStartParameter().isBuildScan()).isFalse(); - } - - @Test - void applyWhenBuildScanTrueThenRegisterCheckRemoteTaskWithBuildScanTrue() { - this.rootProject = ProjectBuilder.builder().build(); - this.rootProject.getPluginManager().apply(IncludeCheckRemotePlugin.class); - this.rootProject.getExtensions().configure(IncludeCheckRemotePlugin.IncludeCheckRemoteExtension.class, - (includeCheckRemoteExtension) -> { - includeCheckRemoteExtension.setProperty("repository", "my-project/my-repository"); - includeCheckRemoteExtension.setProperty("ref", "main"); - includeCheckRemoteExtension.setProperty("buildScan", true); - }); - - GradleBuild checkRemote = (GradleBuild) this.rootProject.getTasks().named("checkRemote").get(); - assertThat(checkRemote).isNotNull(); - assertThat(checkRemote.getStartParameter().isBuildScan()).isTrue(); - } - -}