diff --git a/build.gradle b/build.gradle index 76d10f55c7a..ed3f4c437f8 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,6 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin import org.apache.tools.ant.taskdefs.condition.Os import org.elasticsearch.gradle.BuildPlugin -import org.elasticsearch.gradle.BwcVersions import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionProperties import org.elasticsearch.gradle.info.BuildParams @@ -117,14 +116,6 @@ subprojects { } } -/* Introspect all versions of ES that may be tested against for backwards - * compatibility. It is *super* important that this logic is the same as the - * logic in VersionUtils.java, throwing out alphas because they don't have any - * backwards compatibility guarantees and only keeping the latest beta or rc - * in a branch if there are only betas and rcs in the branch so we have - * *something* to test against. */ -BwcVersions versions = new BwcVersions(file('server/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8')) - task updateCIBwcVersions() { doLast { File yml = file(".ci/bwcVersions") @@ -155,9 +146,6 @@ allprojects { gradle.startParameter.taskNames.contains('eclipse') || // Detects gradle launched from the command line to do eclipse stuff gradle.startParameter.taskNames.contains('cleanEclipse') - // for BWC testing - bwcVersions = versions - buildMetadata = buildMetadataMap } } @@ -171,7 +159,7 @@ task verifyVersions { // Fetch the metadata and parse the xml into Version instances because it's more straight forward here // rather than bwcVersion ( VersionCollection ). new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s -> - bwcVersions.compareToAuthoritative( + BuildParams.bwcVersions.compareToAuthoritative( new XmlParser().parse(s) .versioning.versions.version .collect { it.text() }.findAll { it ==~ /\d+\.\d+\.\d+/ } @@ -179,7 +167,7 @@ task verifyVersions { ) } String ciYml = file(".ci/bwcVersions").text - bwcVersions.indexCompatible.each { + BuildParams.bwcVersions.indexCompatible.each { if (ciYml.contains("\"$it\"\n") == false) { throw new Exception(".ci/bwcVersions is outdated, run `./gradlew updateCIBwcVersions` and check in the results"); } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java index a7d85549404..b746f03c537 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java @@ -40,7 +40,6 @@ import org.gradle.api.artifacts.repositories.IvyArtifactRepository; import org.gradle.api.credentials.HttpHeaderCredentials; import org.gradle.api.file.FileTree; import org.gradle.api.file.RelativePath; -import org.gradle.api.plugins.ExtraPropertiesExtension; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.Sync; import org.gradle.api.tasks.TaskProvider; @@ -93,8 +92,7 @@ public class DistributionDownloadPlugin implements Plugin { setupDownloadServiceRepo(project); if (BuildParams.isInternal()) { - ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties(); - this.bwcVersions = (BwcVersions) extraProperties.get("bwcVersions"); + this.bwcVersions = BuildParams.getBwcVersions(); } project.afterEvaluate(this::setupDistributions); 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 42babbaf077..2387c9b72ba 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -1,5 +1,7 @@ package org.elasticsearch.gradle.info; +import org.apache.commons.io.IOUtils; +import org.elasticsearch.gradle.BwcVersions; import org.elasticsearch.gradle.OS; import org.elasticsearch.gradle.util.Util; import org.gradle.api.GradleException; @@ -20,6 +22,7 @@ import javax.inject.Inject; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.UncheckedIOException; @@ -44,6 +47,7 @@ import java.util.stream.Stream; public class GlobalBuildInfoPlugin implements Plugin { private static final Logger LOGGER = Logging.getLogger(GlobalBuildInfoPlugin.class); + private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java"; private static Integer _defaultParallel = null; private final JavaInstallationRegistry javaInstallationRegistry; @@ -69,10 +73,13 @@ public class GlobalBuildInfoPlugin implements Plugin { File compilerJavaHome = findCompilerJavaHome(); File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome); - GitInfo gitInfo = gitInfo(project.getRootProject().getRootDir()); + File rootDir = project.getRootDir(); + GitInfo gitInfo = gitInfo(rootDir); - // Initialize global build parameters BuildParams.init(params -> { + // Initialize global build parameters + boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null; + params.reset(); params.setCompilerJavaHome(compilerJavaHome); params.setRuntimeJavaHome(runtimeJavaHome); @@ -88,16 +95,32 @@ public class GlobalBuildInfoPlugin implements Plugin { params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC)); params.setTestSeed(getTestSeed()); params.setIsCi(System.getenv("JENKINS_URL") != null); - params.setIsInternal(GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null); + params.setIsInternal(isInternal); params.setDefaultParallel(findDefaultParallel(project)); params.setInFipsJvm(Util.getBooleanProperty("tests.fips.enabled", false)); params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true)); + if (isInternal) { + params.setBwcVersions(resolveBwcVersions(rootDir)); + } }); // Print global build info header just before task execution project.getGradle().getTaskGraph().whenReady(graph -> logGlobalBuildInfo()); } + /* Introspect all versions of ES that may be tested against for backwards + * compatibility. It is *super* important that this logic is the same as the + * logic in VersionUtils.java. */ + private static BwcVersions resolveBwcVersions(File root) { + File versionsFile = new File(root, DEFAULT_VERSION_JAVA_FILE_PATH); + try { + List versionLines = IOUtils.readLines(new FileInputStream(versionsFile), "UTF-8"); + return new BwcVersions(versionLines); + } catch (IOException e) { + throw new IllegalStateException("Unable to resolve to resolve bwc versions from versionsFile.", e); + } + } + private void logGlobalBuildInfo() { final String osName = System.getProperty("os.name"); final String osVersion = System.getProperty("os.version"); diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java index 1598df105ea..75fe8157c0f 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/DistroTestPlugin.java @@ -219,7 +219,7 @@ public class DistroTestPlugin implements Plugin { String firstPartOfSeed = BuildParams.getTestSeed().split(":")[0]; final long seed = Long.parseUnsignedLong(firstPartOfSeed, 16); - BwcVersions bwcVersions = (BwcVersions) extraProperties.get("bwcVersions"); + BwcVersions bwcVersions = BuildParams.getBwcVersions(); final List indexCompatVersions = bwcVersions.getIndexCompatible(); return indexCompatVersions.get(new Random(seed).nextInt(indexCompatVersions.size())); } @@ -287,8 +287,7 @@ public class DistroTestPlugin implements Plugin { Path upgradePath = upgradeDir.get().getAsFile().toPath(); // write bwc version, and append -SNAPSHOT if it is an unreleased version - ExtraPropertiesExtension extraProperties = project.getExtensions().getByType(ExtraPropertiesExtension.class); - BwcVersions bwcVersions = (BwcVersions) extraProperties.get("bwcVersions"); + BwcVersions bwcVersions = BuildParams.getBwcVersions(); final String upgradeFromVersion; if (bwcVersions.unreleasedInfo(upgradeVersion) != null) { upgradeFromVersion = upgradeVersion.toString() + "-SNAPSHOT"; diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/BwcVersions.java b/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/BwcVersions.java similarity index 100% rename from buildSrc/src/main/java/org/elasticsearch/gradle/BwcVersions.java rename to buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/BwcVersions.java diff --git a/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java b/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java index 407b7e11d58..58cb0591426 100644 --- a/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java +++ b/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java @@ -1,5 +1,6 @@ package org.elasticsearch.gradle.info; +import org.elasticsearch.gradle.BwcVersions; import org.gradle.api.JavaVersion; import java.io.File; @@ -30,6 +31,7 @@ public class BuildParams { private static Boolean isInternal; private static Integer defaultParallel; private static Boolean isSnapshotBuild; + private static BwcVersions bwcVersions; /** * Initialize global build parameters. This method accepts and a initialization function which in turn accepts a @@ -95,6 +97,10 @@ public class BuildParams { return value(buildDate); } + public static BwcVersions getBwcVersions() { + return value(bwcVersions); + } + public static String getTestSeed() { return value(testSeed); } @@ -228,5 +234,8 @@ public class BuildParams { BuildParams.isSnapshotBuild = isSnapshotBuild; } + public void setBwcVersions(BwcVersions bwcVersions) { + BuildParams.bwcVersions = requireNonNull(bwcVersions); + } } } diff --git a/buildSrc/src/testKit/distribution-download/build.gradle b/buildSrc/src/testKit/distribution-download/build.gradle index ba6d06e9b70..d408184be67 100644 --- a/buildSrc/src/testKit/distribution-download/build.gradle +++ b/buildSrc/src/testKit/distribution-download/build.gradle @@ -49,7 +49,5 @@ if (internal) { BwcVersions versions = new BwcVersions(new TreeSet<>( Arrays.asList(Version.fromString("8.0.0"), Version.fromString("8.0.1"), Version.fromString("8.1.0"), currentVersion)), currentVersion) - allprojects { - ext.bwcVersions = versions - } + BuildParams.init { it.setBwcVersions(versions) } } diff --git a/distribution/bwc/build.gradle b/distribution/bwc/build.gradle index eb5d9bfa87c..b42eedfcce1 100644 --- a/distribution/bwc/build.gradle +++ b/distribution/bwc/build.gradle @@ -36,7 +36,7 @@ import static org.elasticsearch.gradle.util.JavaUtil.getJavaHome * unreleased versions are when Gradle projects are set up, so we use "build-unreleased-version-*" as placeholders * and configure them to build various versions here. */ -bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleasedVersion -> +BuildParams.bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleasedVersion -> project("${unreleasedVersion.gradleProjectPath}") { Version bwcVersion = unreleasedVersion.version String bwcBranch = unreleasedVersion.branch diff --git a/gradle/bwc-test.gradle b/gradle/bwc-test.gradle index 7a240ce0b3d..a6de8906ce3 100644 --- a/gradle/bwc-test.gradle +++ b/gradle/bwc-test.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams ext.bwcTaskName = { Version version -> return "v${version}#bwcTest" @@ -6,7 +7,7 @@ ext.bwcTaskName = { Version version -> def bwcTestSnapshots = tasks.register("bwcTestSnapshots") { if (project.bwc_tests_enabled) { - dependsOn tasks.matching { task -> bwcVersions.unreleased.any { version -> bwcTaskName(version) == task.name } } + dependsOn tasks.matching { task -> BuildParams.bwcVersions.unreleased.any { version -> bwcTaskName(version) == task.name } } } } diff --git a/qa/full-cluster-restart/build.gradle b/qa/full-cluster-restart/build.gradle index 1eb8ffeec26..02e71077580 100644 --- a/qa/full-cluster-restart/build.gradle +++ b/qa/full-cluster-restart/build.gradle @@ -27,7 +27,7 @@ apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-test' apply from : "$rootDir/gradle/bwc-test.gradle" -for (Version bwcVersion : bwcVersions.indexCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) { String baseName = "v${bwcVersion}" testClusters { diff --git a/qa/mixed-cluster/build.gradle b/qa/mixed-cluster/build.gradle index a6296c04d4d..73027b01eca 100644 --- a/qa/mixed-cluster/build.gradle +++ b/qa/mixed-cluster/build.gradle @@ -32,7 +32,7 @@ restResources { } } -for (Version bwcVersion : bwcVersions.wireCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) { if (bwcVersion == VersionProperties.getElasticsearchVersion()) { // Not really a mixed cluster continue; diff --git a/qa/repository-multi-version/build.gradle b/qa/repository-multi-version/build.gradle index c7e780eb42b..40edc49169a 100644 --- a/qa/repository-multi-version/build.gradle +++ b/qa/repository-multi-version/build.gradle @@ -29,7 +29,7 @@ dependencies { testCompile project(':client:rest-high-level') } -for (Version bwcVersion : bwcVersions.indexCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) { String baseName = "v${bwcVersion}" String oldClusterName = "${baseName}-old" String newClusterName = "${baseName}-new" diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index 8705f9e4087..f25df2b29d0 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-test' apply from : "$rootDir/gradle/bwc-test.gradle" -for (Version bwcVersion : bwcVersions.wireCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) { /* * The goal here is to: *
    diff --git a/qa/verify-version-constants/build.gradle b/qa/verify-version-constants/build.gradle index bd302a7e329..3fa14911e8d 100644 --- a/qa/verify-version-constants/build.gradle +++ b/qa/verify-version-constants/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-test' apply from : "$rootDir/gradle/bwc-test.gradle" -for (Version bwcVersion : bwcVersions.indexCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) { String baseName = "v${bwcVersion}" testClusters { diff --git a/test/framework/build.gradle b/test/framework/build.gradle index 74a3d51964c..c5d4c383fe3 100644 --- a/test/framework/build.gradle +++ b/test/framework/build.gradle @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import org.elasticsearch.gradle.info.BuildParams; dependencies { compile project(":client:rest") @@ -60,9 +61,9 @@ thirdPartyAudit.ignoreMissingClasses( ) test { - systemProperty 'tests.gradle_index_compat_versions', bwcVersions.indexCompatible.join(',') - systemProperty 'tests.gradle_wire_compat_versions', bwcVersions.wireCompatible.join(',') - systemProperty 'tests.gradle_unreleased_versions', bwcVersions.unreleased.join(',') + systemProperty 'tests.gradle_index_compat_versions', BuildParams.bwcVersions.indexCompatible.join(',') + systemProperty 'tests.gradle_wire_compat_versions', BuildParams.bwcVersions.wireCompatible.join(',') + systemProperty 'tests.gradle_unreleased_versions', BuildParams.bwcVersions.unreleased.join(',') } task integTest(type: Test) { diff --git a/x-pack/qa/full-cluster-restart/build.gradle b/x-pack/qa/full-cluster-restart/build.gradle index c2429cbd55d..fa2cf4dc332 100644 --- a/x-pack/qa/full-cluster-restart/build.gradle +++ b/x-pack/qa/full-cluster-restart/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -33,7 +34,7 @@ tasks.register("copyTestNodeKeyMaterial", Copy) { into outputDir } -for (Version bwcVersion : bwcVersions.indexCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) { String baseName = "v${bwcVersion}" testClusters { diff --git a/x-pack/qa/rolling-upgrade-basic/build.gradle b/x-pack/qa/rolling-upgrade-basic/build.gradle index 2bfcabbbeda..f90d16acacb 100644 --- a/x-pack/qa/rolling-upgrade-basic/build.gradle +++ b/x-pack/qa/rolling-upgrade-basic/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -9,7 +10,7 @@ dependencies { testCompile project(':x-pack:qa') } -for (Version bwcVersion : bwcVersions.wireCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) { String baseName = "v${bwcVersion}" testClusters { diff --git a/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle b/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle index 5f4fdcc98c5..71a027c7073 100644 --- a/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle +++ b/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -9,7 +10,7 @@ dependencies { testCompile project(':x-pack:qa') } -for (Version bwcVersion : bwcVersions.wireCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) { String baseName = "v${bwcVersion}" testClusters { diff --git a/x-pack/qa/rolling-upgrade/build.gradle b/x-pack/qa/rolling-upgrade/build.gradle index 3d9cb03614a..4eaf0fae506 100644 --- a/x-pack/qa/rolling-upgrade/build.gradle +++ b/x-pack/qa/rolling-upgrade/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -29,7 +30,7 @@ task copyTestNodeKeyMaterial(type: Copy) { into outputDir } -for (Version bwcVersion : bwcVersions.wireCompatible) { +for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) { String baseName = "v${bwcVersion}" testClusters {