Skip to content

Commit

Permalink
Fix inter plugin dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Oct 19, 2024
1 parent 73981a9 commit 7da8662
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ElasticsearchJavaBasePlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GlobalBuildInfoPlugin.class);
// make sure the global build info plugin is applied to the root project
project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
buildParams = project.getRootProject().getExtensions().getByType(BuildParameterExtension.class);
Expand Down Expand Up @@ -131,8 +132,8 @@ private static void disableTransitiveDependenciesForSourceSet(Project project, S
public void configureCompile(Project project) {
project.getExtensions().getExtraProperties().set("compactProfile", "full");
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
if (buildParams.getJavaToolChainSpec() != null) {
java.toolchain(buildParams.getJavaToolChainSpec());
if (buildParams.getJavaToolChainSpec().isPresent()) {
java.toolchain(buildParams.getJavaToolChainSpec().get());
}
java.setSourceCompatibility(buildParams.getMinimumRuntimeVersion());
java.setTargetCompatibility(buildParams.getMinimumRuntimeVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.gradle.VersionProperties;
import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.elasticsearch.gradle.internal.info.BuildParameterExtension;
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
import org.gradle.api.Action;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
Expand Down Expand Up @@ -45,6 +46,7 @@
public class ElasticsearchJavaPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GlobalBuildInfoPlugin.class);
Property<BuildParameterExtension> buildParams = loadBuildParams(project);
project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class);
project.getPluginManager().apply(JavaLibraryPlugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract class ElasticsearchTestBasePlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GlobalBuildInfoPlugin.class);
Property<BuildParameterExtension> buildParams = loadBuildParams(project);

project.getPluginManager().apply(GradleTestPolicySetupPlugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,44 @@
import org.gradle.api.Action;
import org.gradle.api.JavaVersion;
import org.gradle.api.Task;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.jvm.toolchain.JavaToolchainSpec;

import java.io.File;
import java.io.Serializable;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;

public class BuildParameterExtension implements Serializable {
private final boolean inFipsJvm;
private final File runtimeJavaHome;
public class BuildParameterExtension {
private final Provider<Boolean> inFipsJvm;
private final Provider<File> runtimeJavaHome;
private final Boolean isRuntimeJavaHomeSet;
private final List<JavaHome> javaVersions;
private final JavaVersion minimumCompilerVersion;
private final JavaVersion minimumRuntimeVersion;
private final JavaVersion gradleJavaVersion;
private final JavaVersion runtimeJavaVersion;
private final Action<JavaToolchainSpec> javaToolChainSpec;
private final String runtimeJavaDetails;
private final Provider<JavaVersion> runtimeJavaVersion;
private final Provider<? extends Action<JavaToolchainSpec>> javaToolChainSpec;
private final Provider<String> runtimeJavaDetails;
private final String gitRevision;
private final String gitOrigin;
private transient AtomicReference<ZonedDateTime> buildDate = new AtomicReference<>();
private final String testSeed;
private final Boolean isCi;
private final Integer defaultParallel;
private final Boolean isSnapshotBuild;
private final BwcVersions bwcVersions;
private final Provider<BwcVersions> bwcVersions;

public BuildParameterExtension(
ProviderFactory providers,
File runtimeJavaHome,
Action<JavaToolchainSpec> javaToolChainSpec,
JavaVersion runtimeJavaVersion,
Provider<File> runtimeJavaHome,
Provider<? extends Action<JavaToolchainSpec>> javaToolChainSpec,
Provider<JavaVersion> runtimeJavaVersion,
boolean isRuntimeJavaHomeSet,
String runtimeJavaDetails,
Provider<String> runtimeJavaDetails,
List<JavaHome> javaVersions,
JavaVersion minimumCompilerVersion,
JavaVersion minimumRuntimeVersion,
Expand All @@ -62,9 +62,9 @@ public BuildParameterExtension(
boolean isCi,
int defaultParallel,
final boolean isSnapshotBuild,
BwcVersions bwcVersions
Provider<BwcVersions> bwcVersions
) {
this.inFipsJvm = providers.systemProperty("tests.fips.enabled").map(BuildParameterExtension::parseBoolean).getOrElse(false);
this.inFipsJvm = providers.systemProperty("tests.fips.enabled").map(BuildParameterExtension::parseBoolean);
this.runtimeJavaHome = runtimeJavaHome;
this.javaToolChainSpec = javaToolChainSpec;
this.runtimeJavaVersion = runtimeJavaVersion;
Expand All @@ -91,11 +91,11 @@ private static boolean parseBoolean(String s) {
}

public boolean getInFipsJvm() {
return inFipsJvm;
return inFipsJvm.getOrElse(false);
}

public File getRuntimeJavaHome() {
return runtimeJavaHome;
return runtimeJavaHome.get();
}

public void withFipsEnabledOnly(Task task) {
Expand All @@ -122,15 +122,15 @@ public JavaVersion getGradleJavaVersion() {
return gradleJavaVersion;
}

public JavaVersion getRuntimeJavaVersion() {
public Provider<JavaVersion> getRuntimeJavaVersion() {
return runtimeJavaVersion;
}

public Action<JavaToolchainSpec> getJavaToolChainSpec() {
public Provider<? extends Action<JavaToolchainSpec>> getJavaToolChainSpec() {
return javaToolChainSpec;
}

public String getRuntimeJavaDetails() {
public Provider<String> getRuntimeJavaDetails() {
return runtimeJavaDetails;
}

Expand Down Expand Up @@ -171,14 +171,14 @@ public Boolean isSnapshotBuild() {
}

public BwcVersions getBwcVersions() {
return bwcVersions;
return bwcVersions.get();
}

public Random getRandom() {
return new Random(Long.parseUnsignedLong(testSeed.split(":")[0], 16));
}

public Boolean isGraalVmRuntime() {
return runtimeJavaDetails.toLowerCase().contains("graalvm");
return runtimeJavaDetails.get().toLowerCase().contains("graalvm");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public void apply(Project project) {
.create(
"buildParams",
BuildParameterExtension.class,
actualRuntimeJavaHome.get(),
resolveToolchainSpecFromEnv().getOrNull(),
actualRuntimeJavaHome,
resolveToolchainSpecFromEnv(),
actualRuntimeJavaHome.map(
javaHome -> determineJavaVersion(
"runtime java.home",
Expand All @@ -126,9 +126,9 @@ public void apply(Project project) {
? minimumRuntimeVersion
: JavaVersion.toVersion(VersionProperties.getBundledJdkMajorVersion())
)
).get(),
),
isRuntimeJavaHomeExplicitlySet,
runtimeJdkMetaData.map(m -> formatJavaVendorDetails(m)).get(),
runtimeJdkMetaData.map(m -> formatJavaVendorDetails(m)),

getAvailableJavaVersions(),
minimumCompilerVersion,
Expand All @@ -141,7 +141,7 @@ public void apply(Project project) {
System.getenv("JENKINS_URL") != null || System.getenv("BUILDKITE_BUILD_URL") != null || System.getProperty("isCI") != null,
ParallelDetector.findDefaultParallel(project),
Util.getBooleanProperty("build.snapshot", true),
bwcVersionsProvider.get()
bwcVersionsProvider
);

project.getGradle().getSharedServices().registerIfAbsent("buildParams", BuildParameterService.class, spec -> {
Expand Down

0 comments on commit 7da8662

Please sign in to comment.