Skip to content

Commit

Permalink
Move bwcVersions extension property to BuildParams (back port) (#56383)
Browse files Browse the repository at this point in the history
* Move bwcVersions extension property to BuildParams (#56206)
* Fix :qa Task Using Broken BwC Versions Resolution (#56332)

Co-authored-by: Armin Braun <me@obrown.io>
  • Loading branch information
breskeby and original-brownbear committed May 11, 2020
1 parent 81a1e9e commit 2daf9bf
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 40 deletions.
16 changes: 2 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,14 +154,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")
Expand Down Expand Up @@ -193,9 +184,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
}
}
Expand All @@ -209,15 +197,15 @@ 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+/ }
.collect { Version.fromString(it) }
)
}
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;
Expand Down Expand Up @@ -93,8 +92,7 @@ public void apply(Project project) {
setupDownloadServiceRepo(project);

if (BuildParams.isInternal()) {
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
this.bwcVersions = (BwcVersions) extraProperties.get("bwcVersions");
this.bwcVersions = BuildParams.getBwcVersions();
}

project.afterEvaluate(this::setupDistributions);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +22,7 @@
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;
Expand All @@ -44,6 +47,7 @@

public class GlobalBuildInfoPlugin implements Plugin<Project> {
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;
Expand All @@ -69,10 +73,13 @@ public void apply(Project project) {
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);
Expand All @@ -88,16 +95,32 @@ public void apply(Project project) {
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<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private static Version getUpgradeVersion(Project project) {

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<Version> indexCompatVersions = bwcVersions.getIndexCompatible();
return indexCompatVersions.get(new Random(seed).nextInt(indexCompatVersions.size()));
}
Expand Down Expand Up @@ -286,8 +286,7 @@ private static TaskProvider<Copy> configureCopyUpgradeTask(Project project, Vers
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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.elasticsearch.gradle.info;

import org.elasticsearch.gradle.BwcVersions;
import org.gradle.api.JavaVersion;

import java.io.File;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -95,6 +97,10 @@ public static ZonedDateTime getBuildDate() {
return value(buildDate);
}

public static BwcVersions getBwcVersions() {
return value(bwcVersions);
}

public static String getTestSeed() {
return value(testSeed);
}
Expand Down Expand Up @@ -228,5 +234,8 @@ public void setIsSnapshotBuild(final boolean isSnapshotBuild) {
BuildParams.isSnapshotBuild = isSnapshotBuild;
}

public void setBwcVersions(BwcVersions bwcVersions) {
BuildParams.bwcVersions = requireNonNull(bwcVersions);
}
}
}
4 changes: 1 addition & 3 deletions buildSrc/src/testKit/distribution-download/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
2 changes: 1 addition & 1 deletion distribution/bwc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion gradle/bwc-test.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.info.BuildParams

ext.bwcTaskName = { Version version ->
return "v${version}#bwcTest"
}

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 } }
}
}

Expand Down
2 changes: 1 addition & 1 deletion qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion qa/mixed-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion qa/repository-multi-version/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <ul>
Expand Down
2 changes: 1 addition & 1 deletion qa/verify-version-constants/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions test/framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import org.elasticsearch.gradle.info.BuildParams;

dependencies {
compile project(":client:rest")
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/qa/rolling-upgrade-basic/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/qa/rolling-upgrade-multi-cluster/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2daf9bf

Please sign in to comment.