Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gradle to 8.11 #16386

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,20 @@ Map<String, String> buildMetadataMap = buildMetadataValue.tokenize(';').collectE
return [key, value]
}

/**
* Using 'git' command line (if available), tries to fetch the commit date of the current revision
* @return commit date of the current revision or 0 if it is not available
*/
// See please https://docs.gradle.org/8.11/userguide/service_injection.html#execoperations
interface InjectedExecOps {
@Inject ExecOperations getExecOps()
}

/**
* Using 'git' command line (if available), tries to fetch the commit date of the current revision
* @return commit date of the current revision or 0 if it is not available
*/
long gitRevisionDate = {
def execOps = project.objects.newInstance(InjectedExecOps)
// Try to get last commit date as Unix timestamp
try (ByteArrayOutputStream stdout = new ByteArrayOutputStream()) {
ExecResult result = project.exec(spec -> {
ExecResult result = execOps.execOps.exec(spec -> {
spec.setIgnoreExitValue(true);
spec.setStandardOutput(stdout);
spec.commandLine("git", "log", "-1", "--format=%ct");
Expand Down Expand Up @@ -362,7 +368,7 @@ allprojects {
if ((dep instanceof ProjectDependency) == false) {
return
}
Project upstreamProject = dep.dependencyProject
Project upstreamProject = project.project(dep.path)
if (upstreamProject == null) {
return
}
Expand Down Expand Up @@ -438,7 +444,7 @@ gradle.projectsEvaluated {

configurations.matching { it.canBeResolved }.all { Configuration configuration ->
dependencies.matching { it instanceof ProjectDependency }.all { ProjectDependency dep ->
Project upstreamProject = dep.dependencyProject
Project upstreamProject = project.project(dep.path)
if (upstreamProject != null) {
if (project.path == upstreamProject.path) {
// TODO: distribution integ tests depend on themselves (!), fix that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@

project.configurations.testImplementation.dependencies.all { Dependency dep ->
// this closure is run every time a compile dependency is added
if (dep instanceof ProjectDependency && dep.dependencyProject.plugins.hasPlugin(PluginBuildPlugin)) {
project.gradle.projectsEvaluated {
addPluginResources(project, dep.dependencyProject)
if (dep instanceof ProjectDependency) {
Project dependencyProject = project.project(((ProjectDependency)dep).path)

Check warning on line 60 in buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithDependenciesPlugin.groovy

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithDependenciesPlugin.groovy#L60

Added line #L60 was not covered by tests
if (dependencyProject.plugins.hasPlugin(PluginBuildPlugin)) {
project.gradle.projectsEvaluated {
addPluginResources(project, dependencyProject)

Check warning on line 63 in buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithDependenciesPlugin.groovy

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithDependenciesPlugin.groovy#L62-L63

Added lines #L62 - L63 were not covered by tests
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
private Consumer<Logger> outputLogger;
private FileSystemOperations fileSystemOperations;

interface InjectedExecOps {
@Inject
ExecOperations getExecOps();
}

@Inject
public LoggedExec(FileSystemOperations fileSystemOperations) {
this.fileSystemOperations = fileSystemOperations;
Expand Down Expand Up @@ -133,15 +138,17 @@
}

public static ExecResult exec(Project project, Action<ExecSpec> action) {
return genericExec(project::exec, action);
final InjectedExecOps execOps = project.getObjects().newInstance(InjectedExecOps.class);
return exec(execOps.getExecOps(), action);

Check warning on line 142 in buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java#L141-L142

Added lines #L141 - L142 were not covered by tests
}

public static ExecResult exec(ExecOperations execOperations, Action<ExecSpec> action) {
return genericExec(execOperations::exec, action);
}

public static ExecResult javaexec(Project project, Action<JavaExecSpec> action) {
return genericExec(project::javaexec, action);
final InjectedExecOps execOps = project.getObjects().newInstance(InjectedExecOps.class);
return genericExec(execOps.getExecOps()::javaexec, action);

Check warning on line 151 in buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/LoggedExec.java#L150-L151

Added lines #L150 - L151 were not covered by tests
}

/** Returns JVM arguments suitable for a short-lived forked task */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
Node dependencyNode = dependenciesNode.appendNode("dependency");
dependencyNode.appendNode("groupId", dependency.getGroup());
ProjectDependency projectDependency = (ProjectDependency) dependency;
String artifactId = getArchivesBaseName(projectDependency.getDependencyProject());
String artifactId = getArchivesBaseName(project.project(projectDependency.getPath()));

Check warning on line 124 in buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java#L124

Added line #L124 was not covered by tests
dependencyNode.appendNode("artifactId", artifactId);
dependencyNode.appendNode("version", dependency.getVersion());
dependencyNode.appendNode("scope", "compile");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.process.ExecOperations;
import org.gradle.process.ExecResult;

import javax.inject.Inject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -108,6 +111,11 @@

public boolean jarHellEnabled = true;

interface InjectedExecOps {
@Inject
ExecOperations getExecOps();
}

@Input
public Property<JavaVersion> getTargetCompatibility() {
return targetCompatibility;
Expand Down Expand Up @@ -357,7 +365,8 @@

private String runForbiddenAPIsCli() throws IOException {
ByteArrayOutputStream errorOut = new ByteArrayOutputStream();
ExecResult result = getProject().javaexec(spec -> {
InjectedExecOps execOps = getProject().getObjects().newInstance(InjectedExecOps.class);
ExecResult result = execOps.getExecOps().javaexec(spec -> {

Check warning on line 369 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L368-L369

Added lines #L368 - L369 were not covered by tests
if (javaHome != null) {
spec.setExecutable(javaHome + "/bin/java");
}
Expand Down Expand Up @@ -391,7 +400,8 @@

private Set<String> runJdkJarHellCheck() throws IOException {
ByteArrayOutputStream standardOut = new ByteArrayOutputStream();
ExecResult execResult = getProject().javaexec(spec -> {
InjectedExecOps execOps = getProject().getObjects().newInstance(InjectedExecOps.class);
ExecResult execResult = execOps.getExecOps().javaexec(spec -> {

Check warning on line 404 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L403-L404

Added lines #L403 - L404 were not covered by tests
spec.classpath(
jdkJarHellClasspath,
getRuntimeConfiguration(),
Expand Down
9 changes: 8 additions & 1 deletion gradle/missing-javadoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


import javax.annotation.Nullable
import javax.inject.Inject
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.internal.jvm.Jvm
Expand Down Expand Up @@ -227,6 +228,11 @@ class MissingJavadocTask extends DefaultTask {
@PathSensitive(PathSensitivity.RELATIVE)
def taskResources

// See please https://docs.gradle.org/8.11/userguide/service_injection.html#execoperations
interface InjectedExecOps {
@Inject ExecOperations getExecOps()
}

/** Utility method to recursively collect all tasks with same name like this one that we depend on */
private Set findRenderTasksInDependencies() {
Set found = []
Expand Down Expand Up @@ -317,11 +323,12 @@ class MissingJavadocTask extends DefaultTask {
}
}()

def execOps = project.objects.newInstance(InjectedExecOps)
def outputFile = project.file("${getTemporaryDir()}/javadoc-output.txt")
def result

outputFile.withOutputStream { output ->
result = project.exec {
result = execOps.execOps.exec {
executable javadocCmd

// we want to capture both stdout and stderr to the same
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=2ab88d6de2c23e6adae7363ae6e29cbdd2a709e992929b48b6530fd0c7133bd6
distributionSha256Sum=73d2d553933194d8eefed0a291acbe45392ca3572ba13834cbbf373da375276d
2 changes: 1 addition & 1 deletion libs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ subprojects {
project.afterEvaluate {
configurations.all { Configuration conf ->
dependencies.matching { it instanceof ProjectDependency }.all { ProjectDependency dep ->
Project depProject = dep.dependencyProject
Project depProject = project.project(dep.path)
if (depProject != null
&& (false == depProject.path.equals(':libs:opensearch-core') &&
false == depProject.path.equals(':libs:opensearch-common'))
Expand Down
8 changes: 7 additions & 1 deletion modules/lang-painless/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ testClusters {
}
}

interface InjectedExecOps {
@Inject ExecOperations getExecOps()
}


tasks.register("generateContextDoc", DefaultTestClustersTask) {
dependsOn sourceSets.doc.runtimeClasspath
useCluster testClusters.generateContextCluster
doFirst {
project.javaexec {
def execOps = project.objects.newInstance(InjectedExecOps)
execOps.execOps.javaexec {
mainClass = 'org.opensearch.painless.ContextDocGenerator'
classpath = sourceSets.doc.runtimeClasspath
systemProperty "cluster.uri", "${-> testClusters.generateContextCluster.singleNode().getAllHttpSocketURI().get(0)}"
Expand Down
Loading