Move bwcVersions extension property to BuildParams (back port) (#56381)

* Move bwcVersions extension property to BuildParams (#56206)
* Fix :qa Task Using Broken BwC Versions Resolution (#56332)

Co-authored-by: Armin Braun <me@obrown.io>
This commit is contained in:
Rene Groeschke 2020-05-11 09:39:13 +02:00 committed by GitHub
parent ebe1e4c4c4
commit c29bc87040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 61 additions and 40 deletions

View File

@ -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");
}

View File

@ -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<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);

View File

@ -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<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;
@ -69,10 +73,13 @@ public class GlobalBuildInfoPlugin implements Plugin<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);
@ -88,16 +95,32 @@ public class GlobalBuildInfoPlugin implements Plugin<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");

View File

@ -219,7 +219,7 @@ public class DistroTestPlugin implements Plugin<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()));
}
@ -287,8 +287,7 @@ public class DistroTestPlugin implements Plugin<Project> {
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";

View File

@ -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);
}
}
}

View File

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

View File

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

View File

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

View File

@ -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 {

View File

@ -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;

View File

@ -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"

View File

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

View File

@ -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 {

View File

@ -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) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {