Skip to content

Commit

Permalink
Replace BuildParams usages
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Oct 25, 2024
1 parent 10b70e4 commit 32f10b0
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@

package org.elasticsearch.gradle.internal

import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.fixtures.AbstractGitAwareGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.IgnoreIf
import spock.lang.Unroll

/*
* Test is ignored on ARM since this test case tests the ability to build certain older BWC branches that we don't support on ARM
*/
@IgnoreIf({ Architecture.current() == Architecture.AARCH64 })
class InternalDistributionBwcSetupPluginFuncTest extends AbstractGitAwareGradleFuncTest {

def setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.elasticsearch.gradle.Version;
import org.elasticsearch.gradle.internal.info.BuildParameterExtension;
import org.elasticsearch.gradle.internal.info.BuildParams;
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
import org.gradle.api.Action;
import org.gradle.api.InvalidUserDataException;
Expand Down Expand Up @@ -40,6 +39,7 @@

import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static org.elasticsearch.gradle.internal.util.ParamsUtils.loadBuildParams;

/**
* We want to be able to do BWC tests for unreleased versions without relying on and waiting for snapshots.
Expand All @@ -63,12 +63,14 @@ public InternalDistributionBwcSetupPlugin(ObjectFactory objectFactory, ProviderF
@Override
public void apply(Project project) {
project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
Boolean isCi = project.getRootProject().getExtensions().getByType(BuildParameterExtension.class).isCi();
project.getPlugins().apply(JvmToolchainsPlugin.class);
toolChainService = project.getExtensions().getByType(JavaToolchainService.class);
BuildParams.getBwcVersions().forPreviousUnreleased((BwcVersions.UnreleasedVersionInfo unreleasedVersion) -> {
BuildParameterExtension buildParams = loadBuildParams(project).get();
Boolean isCi = buildParams.isCi();
buildParams.getBwcVersions().forPreviousUnreleased((BwcVersions.UnreleasedVersionInfo unreleasedVersion) -> {
configureBwcProject(
project.project(unreleasedVersion.gradleProjectPath()),
buildParams,
unreleasedVersion,
providerFactory,
objectFactory,
Expand All @@ -80,6 +82,7 @@ public void apply(Project project) {

private static void configureBwcProject(
Project project,
BuildParameterExtension buildParams,
BwcVersions.UnreleasedVersionInfo versionInfo,
ProviderFactory providerFactory,
ObjectFactory objectFactory,
Expand Down Expand Up @@ -127,6 +130,7 @@ private static void configureBwcProject(
for (DistributionProject distributionProject : distributionProjects) {
createBuildBwcTask(
bwcSetupExtension,
buildParams,
project,
bwcVersion,
distributionProject.name,
Expand All @@ -149,6 +153,7 @@ private static void configureBwcProject(

createBuildBwcTask(
bwcSetupExtension,
buildParams,
project,
bwcVersion,
"jdbc",
Expand Down Expand Up @@ -177,6 +182,7 @@ private static void configureBwcProject(

createBuildBwcTask(
bwcSetupExtension,
buildParams,
project,
bwcVersion,
stableApiProject.getName(),
Expand Down Expand Up @@ -296,6 +302,7 @@ public static String buildBwcTaskName(String projectName) {

static void createBuildBwcTask(
BwcSetupExtension bwcSetupExtension,
BuildParameterExtension buildParams,
Project project,
Provider<Version> bwcVersion,
String projectName,
Expand All @@ -316,7 +323,7 @@ static void createBuildBwcTask(
} else {
c.getOutputs().files(expectedOutputFile);
}
c.getOutputs().doNotCacheIf("BWC distribution caching is disabled for local builds", task -> BuildParams.isCi() == false);
c.getOutputs().doNotCacheIf("BWC distribution caching is disabled for local builds", task -> buildParams.isCi() == false);
c.getArgs().add(projectPath.replace('/', ':') + ":" + assembleTaskName);
if (project.getGradle().getStartParameter().isBuildCacheEnabled()) {
c.getArgs().add("--build-cache");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

package org.elasticsearch.gradle.internal;

import org.elasticsearch.gradle.internal.info.BuildParams;
import org.elasticsearch.gradle.internal.info.BuildParameterExtension;
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.JavaVersion;
Expand Down Expand Up @@ -47,6 +48,7 @@
import javax.inject.Inject;

import static de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME;
import static org.elasticsearch.gradle.internal.util.ParamsUtils.loadBuildParams;
import static org.objectweb.asm.Opcodes.V_PREVIEW;

public class MrjarPlugin implements Plugin<Project> {
Expand All @@ -64,6 +66,8 @@ public class MrjarPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class);
project.getRootProject().getPlugins().apply(GlobalBuildInfoPlugin.class);
var buildParams = loadBuildParams(project).get();
var javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
var isIdeaSync = System.getProperty("idea.sync.active", "false").equals("true");
var ideaSourceSetsEnabled = project.hasProperty(MRJAR_IDEA_ENABLED) && project.property(MRJAR_IDEA_ENABLED).equals("true");
Expand All @@ -89,7 +93,7 @@ public void apply(Project project) {
String testSourceSetName = SourceSet.TEST_SOURCE_SET_NAME + javaVersion;
SourceSet testSourceSet = addSourceSet(project, javaExtension, testSourceSetName, testSourceSets, javaVersion);
testSourceSets.add(testSourceSetName);
createTestTask(project, testSourceSet, javaVersion, mainSourceSets);
createTestTask(project, buildParams, testSourceSet, javaVersion, mainSourceSets);
}
}

Expand Down Expand Up @@ -163,7 +167,13 @@ private void configureSourceSetInJar(Project project, SourceSet sourceSet, int j
jarTask.configure(task -> task.into("META-INF/versions/" + javaVersion, copySpec -> copySpec.from(sourceSet.getOutput())));
}

private void createTestTask(Project project, SourceSet sourceSet, int javaVersion, List<String> mainSourceSets) {
private void createTestTask(
Project project,
BuildParameterExtension buildParams,
SourceSet sourceSet,
int javaVersion,
List<String> mainSourceSets
) {
var jarTask = project.getTasks().withType(Jar.class).named(JavaPlugin.JAR_TASK_NAME);
var testTaskProvider = project.getTasks().register(JavaPlugin.TEST_TASK_NAME + javaVersion, Test.class);
testTaskProvider.configure(testTask -> {
Expand All @@ -180,9 +190,9 @@ private void createTestTask(Project project, SourceSet sourceSet, int javaVersio

// only set the jdk if runtime java isn't set because setting the toolchain is incompatible with
// runtime java setting the executable directly
if (BuildParams.getIsRuntimeJavaHomeSet()) {
if (buildParams.getIsRuntimeJavaHomeSet()) {
testTask.onlyIf("runtime java must support java " + javaVersion, t -> {
JavaVersion runtimeJavaVersion = BuildParams.getRuntimeJavaVersion();
JavaVersion runtimeJavaVersion = buildParams.getRuntimeJavaVersion().get();
return runtimeJavaVersion.isCompatibleWith(JavaVersion.toVersion(javaVersion));
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.elasticsearch.gradle.internal.docker;

import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand All @@ -17,6 +18,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.elasticsearch.gradle.internal.util.ParamsUtils.loadBuildParams;

/**
* Plugin providing {@link DockerSupportService} for detecting Docker installations and determining requirements for Docker-based
* Elasticsearch build tasks.
Expand All @@ -30,11 +33,14 @@ public void apply(Project project) {
if (project != project.getRootProject()) {
throw new IllegalStateException(this.getClass().getName() + " can only be applied to the root project.");
}
project.getPlugins().apply(GlobalBuildInfoPlugin.class);
var buildParams = loadBuildParams(project).get();

Provider<DockerSupportService> dockerSupportServiceProvider = project.getGradle()
.getSharedServices()
.registerIfAbsent(DOCKER_SUPPORT_SERVICE_NAME, DockerSupportService.class, spec -> spec.parameters(params -> {
params.setExclusionsFile(new File(project.getRootDir(), DOCKER_ON_LINUX_EXCLUSIONS_FILE));
params.getIsCI().set(buildParams.isCi());
}));

// Ensure that if we are trying to run any DockerBuildTask tasks, we assert an available Docker installation exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.elasticsearch.gradle.Architecture;
import org.elasticsearch.gradle.OS;
import org.elasticsearch.gradle.Version;
import org.elasticsearch.gradle.internal.info.BuildParams;
import org.gradle.api.GradleException;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;
Expand Down Expand Up @@ -59,7 +59,6 @@ public abstract class DockerSupportService implements BuildService<DockerSupport

private final ProviderFactory providerFactory;
private DockerAvailability dockerAvailability;
private Map<String, ServiceInfo> serviceInfos;
private Map<String, Map<Integer, Integer>> tcpPorts;
private Map<String, Map<Integer, Integer>> udpPorts;

Expand Down Expand Up @@ -228,7 +227,7 @@ private boolean isExcludedOs() {
// We don't attempt to check the current flavor and version of Linux unless we're
// running in CI, because we don't want to stop people running the Docker tests in
// their own environments if they really want to.
if (BuildParams.isCi() == false) {
if (getParameters().getIsCI().get().booleanValue() == false) {
return false;
}

Expand Down Expand Up @@ -356,10 +355,6 @@ public Map<String, Map<Integer, Integer>> getUdpPorts() {
return udpPorts;
}

public void setServiceInfos(Map<String, ServiceInfo> serviceInfos) {
this.serviceInfos = serviceInfos;
}

/**
* An immutable class that represents the results of a Docker search from {@link #getDockerAvailability()}}.
*/
Expand Down Expand Up @@ -402,5 +397,7 @@ interface Parameters extends BuildServiceParameters {
File getExclusionsFile();

void setExclusionsFile(File exclusionsFile);

Property<Boolean> getIsCI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,38 +152,38 @@ public void apply(Project project) {
spec.getParameters().getBuildParams().set(buildParams);
});

BuildParams.init(params -> {
params.reset();
params.setRuntimeJavaHome(actualRuntimeJavaHome);
params.setJavaToolChainSpec(resolveToolchainSpecFromEnv());
params.setRuntimeJavaVersion(
actualRuntimeJavaHome.map(
javaHome -> determineJavaVersion(
"runtime java.home",
javaHome,
isRuntimeJavaHomeExplicitlySet
? minimumRuntimeVersion
: JavaVersion.toVersion(VersionProperties.getBundledJdkMajorVersion())
)
)
);
params.setIsRuntimeJavaHomeSet(isRuntimeJavaHomeExplicitlySet);
params.setRuntimeJavaDetails(runtimeJdkMetaData.map(m -> formatJavaVendorDetails(m)));
params.setJavaVersions(getAvailableJavaVersions());
params.setMinimumCompilerVersion(minimumCompilerVersion);
params.setMinimumRuntimeVersion(minimumRuntimeVersion);
params.setGradleJavaVersion(Jvm.current().getJavaVersion());
params.setGitRevision(gitInfo.getRevision());
params.setGitOrigin(gitInfo.getOrigin());
params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC));
params.setTestSeed(getTestSeed());
params.setIsCi(
System.getenv("JENKINS_URL") != null || System.getenv("BUILDKITE_BUILD_URL") != null || System.getProperty("isCI") != null
);
params.setDefaultParallel(ParallelDetector.findDefaultParallel(project));
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
params.setBwcVersions(bwcVersionsProvider);
});
// BuildParams.init(params -> {
// params.reset();
// params.setRuntimeJavaHome(actualRuntimeJavaHome);
// params.setJavaToolChainSpec(resolveToolchainSpecFromEnv());
// params.setRuntimeJavaVersion(
// actualRuntimeJavaHome.map(
// javaHome -> determineJavaVersion(
// "runtime java.home",
// javaHome,
// isRuntimeJavaHomeExplicitlySet
// ? minimumRuntimeVersion
// : JavaVersion.toVersion(VersionProperties.getBundledJdkMajorVersion())
// )
// )
// );
// params.setIsRuntimeJavaHomeSet(isRuntimeJavaHomeExplicitlySet);
// params.setRuntimeJavaDetails(runtimeJdkMetaData.map(m -> formatJavaVendorDetails(m)));
// params.setJavaVersions(getAvailableJavaVersions());
// params.setMinimumCompilerVersion(minimumCompilerVersion);
// params.setMinimumRuntimeVersion(minimumRuntimeVersion);
// params.setGradleJavaVersion(Jvm.current().getJavaVersion());
// params.setGitRevision(gitInfo.getRevision());
// params.setGitOrigin(gitInfo.getOrigin());
// params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC));
// params.setTestSeed(getTestSeed());
// params.setIsCi(
// System.getenv("JENKINS_URL") != null || System.getenv("BUILDKITE_BUILD_URL") != null || System.getProperty("isCI") != null
// );
// params.setDefaultParallel(ParallelDetector.findDefaultParallel(project));
// params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
// params.setBwcVersions(bwcVersionsProvider);
// });

// Enforce the minimum compiler version
assertMinimumCompilerVersion(minimumCompilerVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import org.elasticsearch.gradle.ElasticsearchDistributionType;
import org.elasticsearch.gradle.Version;
import org.elasticsearch.gradle.VersionProperties;
import org.elasticsearch.gradle.internal.BwcVersions;
import org.elasticsearch.gradle.internal.InternalDistributionDownloadPlugin;
import org.elasticsearch.gradle.internal.JdkDownloadPlugin;
import org.elasticsearch.gradle.internal.docker.DockerSupportPlugin;
import org.elasticsearch.gradle.internal.docker.DockerSupportService;
import org.elasticsearch.gradle.internal.info.BuildParams;
import org.elasticsearch.gradle.test.SystemPropertyCommandLineArgumentProvider;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.Action;
Expand Down Expand Up @@ -55,6 +55,7 @@
import static org.elasticsearch.gradle.internal.distribution.InternalElasticsearchDistributionTypes.DOCKER_UBI;
import static org.elasticsearch.gradle.internal.distribution.InternalElasticsearchDistributionTypes.DOCKER_WOLFI;
import static org.elasticsearch.gradle.internal.distribution.InternalElasticsearchDistributionTypes.RPM;
import static org.elasticsearch.gradle.internal.util.ParamsUtils.loadBuildParams;

/**
* This class defines gradle tasks for testing our various distribution artifacts.
Expand All @@ -73,6 +74,7 @@ public void apply(Project project) {
project.getPlugins().apply(InternalDistributionDownloadPlugin.class);
project.getPlugins().apply(JdkDownloadPlugin.class);
project.getPluginManager().apply("elasticsearch.java");
var buildParams = loadBuildParams(project).get();

Provider<DockerSupportService> dockerSupport = GradleUtils.getBuildService(
project.getGradle().getSharedServices(),
Expand All @@ -85,7 +87,7 @@ public void apply(Project project) {
List<ElasticsearchDistribution> testDistributions = configureDistributions(project);

Map<ElasticsearchDistributionType, TaskProvider<?>> lifecycleTasks = lifecycleTasks(project, "destructiveDistroTest");
Map<String, TaskProvider<?>> versionTasks = versionTasks(project, "destructiveDistroUpgradeTest");
Map<String, TaskProvider<?>> versionTasks = versionTasks(project, "destructiveDistroUpgradeTest", buildParams.getBwcVersions());
TaskProvider<Task> destructiveDistroTest = project.getTasks().register("destructiveDistroTest");

Configuration examplePlugin = configureExamplePlugin(project);
Expand Down Expand Up @@ -116,7 +118,7 @@ public void apply(Project project) {
lifecycleTask.configure(t -> t.dependsOn(destructiveTask));

if ((type == DEB || type == RPM) && distribution.getBundledJdk()) {
for (Version version : BuildParams.getBwcVersions().getIndexCompatible()) {
for (Version version : buildParams.getBwcVersions().getIndexCompatible()) {
final ElasticsearchDistribution bwcDistro;
if (version.equals(Version.fromString(distribution.getVersion()))) {
// this is the same as the distribution we are testing
Expand Down Expand Up @@ -158,10 +160,10 @@ private static Map<ElasticsearchDistributionType, TaskProvider<?>> lifecycleTask
return lifecyleTasks;
}

private static Map<String, TaskProvider<?>> versionTasks(Project project, String taskPrefix) {
private static Map<String, TaskProvider<?>> versionTasks(Project project, String taskPrefix, BwcVersions bwcVersions) {
Map<String, TaskProvider<?>> versionTasks = new HashMap<>();

for (Version version : BuildParams.getBwcVersions().getIndexCompatible()) {
for (Version version : bwcVersions.getIndexCompatible()) {
versionTasks.put(version.toString(), project.getTasks().register(taskPrefix + ".v" + version));
}

Expand Down
Loading

0 comments on commit 32f10b0

Please sign in to comment.