From 7ad303f0ce5f8d0ca36599f41bfb5618708fcb17 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 4 Mar 2020 15:14:21 -0600 Subject: [PATCH] Replace VersionsResourceTasks with WriteProperties VersionsResourceTasks wrote a date comment which prevented this from producing the same result and caused misses in the cache. Closes gh-8114 --- .../java/versions/VersionsResourceTasks.java | 49 ------------------- core/spring-security-core.gradle | 16 +++--- 2 files changed, 9 insertions(+), 56 deletions(-) delete mode 100644 buildSrc/src/main/java/versions/VersionsResourceTasks.java diff --git a/buildSrc/src/main/java/versions/VersionsResourceTasks.java b/buildSrc/src/main/java/versions/VersionsResourceTasks.java deleted file mode 100644 index 75e19ef0a5..0000000000 --- a/buildSrc/src/main/java/versions/VersionsResourceTasks.java +++ /dev/null @@ -1,49 +0,0 @@ -package versions; - -import org.codehaus.groovy.runtime.ResourceGroovyMethods; -import org.gradle.api.DefaultTask; -import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.provider.MapProperty; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.OutputFile; -import org.gradle.api.tasks.TaskAction; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.Properties; - -public class VersionsResourceTasks extends DefaultTask { - - private final RegularFileProperty versionsFile = getProject().getObjects().fileProperty(); - - private final MapProperty versions = getProject().getObjects().mapProperty(String.class, String.class); - - @OutputFile - public RegularFileProperty getVersionsFile() { - return versionsFile; - } - - @Input - public MapProperty getVersions() { - return versions; - } - - @TaskAction - void generateVersions() throws IOException { - - File file = versionsFile.getAsFile().get(); - File parentFile = versionsFile.getAsFile().get().getParentFile(); - - if (parentFile.isDirectory() || parentFile.mkdirs()) { - Properties properties = new Properties(); - properties.putAll(getVersions().get()); - try (Writer writer = ResourceGroovyMethods.newWriter(file)) { - properties.store(writer, null); - } - } - else { - throw new IOException(parentFile + " does not exist and cannot be created"); - } - } -} diff --git a/core/spring-security-core.gradle b/core/spring-security-core.gradle index d4f6b9b6c2..19a2b42aec 100644 --- a/core/spring-security-core.gradle +++ b/core/spring-security-core.gradle @@ -1,3 +1,5 @@ +import java.util.concurrent.Callable + apply plugin: 'io.spring.convention.spring-module' def includeProject = project(':spring-security-crypto') @@ -34,9 +36,9 @@ dependencies { testRuntime 'org.hsqldb:hsqldb' } -task springVersion(type: versions.VersionsResourceTasks) { - versionsFile = file("${buildDir}/versions/spring-security.versions") - versions = provider { ["org.springframework:spring-core":"${springVersion()}"] } +task springVersion(type: org.gradle.api.tasks.WriteProperties) { + outputFile = file("${buildDir}/versions/spring-security.versions") + property("org.springframework:spring-core", springVersion()) } tasks.processResources { @@ -52,11 +54,11 @@ tasks.sourcesJar.from {includeProject.sourceSets.main.java} configure(project.tasks.withType(Test)) { doFirst { systemProperties['springSecurityVersion'] = version - systemProperties['springVersion'] = springVersion() + systemProperties['springVersion'] = springVersion().call() } } -String springVersion() { - return project.configurations.compile.resolvedConfiguration.resolvedArtifacts - .find { it.name == 'spring-core' }.moduleVersion.id.version +Callable springVersion() { + return (Callable) { project.configurations.compile.resolvedConfiguration.resolvedArtifacts + .find { it.name == 'spring-core' }.moduleVersion.id.version } }