From c8a4bf8252feb2f45a1ef83c26071b2af870849e Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 8 Oct 2019 17:31:17 -0700 Subject: [PATCH] Move test seed setup to global build info The global build info plugin prints high level information about the build, including the test seed. However, BuildPlugin sets up the test seed, which creates an odd implicit dependency on it. This commit moves the intialization of the testSeed property into the global build info. --- .../elasticsearch/gradle/BuildPlugin.groovy | 27 ------------------- .../gradle/info/GlobalBuildInfoPlugin.java | 13 ++++++++- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index c5335648e65af..d958cb8a69bb8 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -131,7 +131,6 @@ class BuildPlugin implements Plugin { project.getTasks().register("buildResources", ExportElasticsearchBuildResourcesTask) - setupSeed(project) configureRepositories(project) project.extensions.getByType(ExtraPropertiesExtension).set('versions', VersionProperties.versions) configureInputNormalization(project) @@ -950,32 +949,6 @@ class BuildPlugin implements Plugin { } } - /** - * Pins the test seed at configuration time so it isn't different on every - * {@link Test} execution. This is useful if random - * decisions in one run of {@linkplain Test} influence the - * outcome of subsequent runs. Pinning the seed up front like this makes - * the reproduction line from one run be useful on another run. - */ - static String setupSeed(Project project) { - ExtraPropertiesExtension ext = project.rootProject.extensions.getByType(ExtraPropertiesExtension) - if (ext.has('testSeed')) { - /* Skip this if we've already pinned the testSeed. It is important - * that this checks the rootProject so that we know we've only ever - * initialized one time. */ - return ext.get('testSeed') - } - - String testSeed = System.getProperty('tests.seed') - if (testSeed == null) { - long seed = new Random(System.currentTimeMillis()).nextLong() - testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT) - } - - ext.set('testSeed', testSeed) - return testSeed - } - private static class TestFailureReportingPlugin implements Plugin { @Override void apply(Project project) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java index b59d9806a0bf4..871d7703c3a40 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -25,7 +25,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Random; import java.util.stream.Collectors; public class GlobalBuildInfoPlugin implements Plugin { @@ -46,6 +48,15 @@ public void apply(Project project) { File compilerJavaHome = findCompilerJavaHome(); File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome); + String testSeedProperty = System.getProperty("tests.seed"); + final String testSeed; + if (testSeedProperty == null) { + long seed = new Random(System.currentTimeMillis()).nextLong(); + testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT); + } else { + testSeed = testSeedProperty; + } + final List javaVersions = new ArrayList<>(); for (int version = 8; version <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); version++) { if (System.getenv(getJavaHomeEnvVarName(Integer.toString(version))) != null) { @@ -95,6 +106,7 @@ public void apply(Project project) { ext.set("gradleJavaVersion", Jvm.current().getJavaVersion()); ext.set("gitRevision", gitRevision(project.getRootProject().getRootDir())); ext.set("buildDate", ZonedDateTime.now(ZoneOffset.UTC)); + ext.set("testSeed", testSeed); ext.set("isCi", System.getenv("JENKINS_URL") != null); }); } @@ -265,5 +277,4 @@ private static String readFirstLine(final Path path) throws IOException { .findFirst() .orElseThrow(() -> new IOException("file [" + path + "] is empty")); } - }