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 to Gradle 8.1 #6792

Merged
merged 1 commit into from
Apr 20, 2023
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
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('ver
version = props.getProperty("opensearch")

def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) {
outputFile = "${buildDir}/version.properties"
destinationFile = file("${buildDir}/version.properties")
comment = 'Generated version properties'
properties(props)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin;
import org.opensearch.gradle.info.BuildParams;
import org.opensearch.gradle.info.GlobalBuildInfoPlugin;
import org.opensearch.gradle.jvm.JvmTestSuiteHelper;
import org.opensearch.gradle.test.ErrorReportingTestListener;
import org.opensearch.gradle.util.Util;
import org.gradle.api.Action;
Expand Down Expand Up @@ -223,7 +224,15 @@ public void execute(Task t) {
// Add the shadow JAR artifact itself
FileCollection shadowJar = project.files(project.getTasks().named("shadowJar"));

test.setClasspath(test.getClasspath().minus(mainRuntime).plus(shadowConfig).plus(shadowJar));
// See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath
test.setClasspath(
JvmTestSuiteHelper.getDefaultTestSuite(project)
.map(suite -> suite.getSources().getRuntimeClasspath())
.orElseGet(() -> test.getClasspath())
.minus(mainRuntime)
.plus(shadowConfig)
.plus(shadowJar)
);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle.jvm;

import org.gradle.api.Project;
import org.gradle.api.plugins.JvmTestSuitePlugin;
import org.gradle.api.plugins.jvm.JvmTestSuite;
import org.gradle.testing.base.TestSuite;
import org.gradle.testing.base.TestingExtension;

import java.util.Optional;

public final class JvmTestSuiteHelper {
private JvmTestSuiteHelper() {}

/**
* Gets the default test suite. This method assumes the Java plugin is applied,
* adapted from {@link org.gradle.api.plugins.internal.JavaPluginHelper} since it is not
* available in Gradle releases predated 8.1.
*/
public static Optional<JvmTestSuite> getDefaultTestSuite(Project project) {
TestingExtension testing = project.getExtensions().findByType(TestingExtension.class);
if (testing == null) {
return Optional.empty();
}

TestSuite defaultTestSuite = testing.getSuites().findByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);
if (!(defaultTestSuite instanceof JvmTestSuite)) {
return Optional.empty();
}

return Optional.of((JvmTestSuite) defaultTestSuite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@
package org.opensearch.gradle.precommit;

import groovy.lang.Closure;

import org.opensearch.gradle.jvm.JvmTestSuiteHelper;
import org.opensearch.gradle.util.GradleUtils;
import org.opensearch.gradle.util.Util;
import org.gradle.api.DefaultTask;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.jvm.JvmTestSuite;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.testing.Test;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.internal.Factory;

import java.io.File;
import java.io.IOException;
Expand All @@ -70,6 +76,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;

public class TestingConventionsTasks extends DefaultTask {

private static final String TEST_METHOD_PREFIX = "test";
Expand All @@ -85,13 +93,39 @@ public TestingConventionsTasks() {
naming = getProject().container(TestingConventionRule.class);
}

@Inject
protected Factory<PatternSet> getPatternSetFactory() {
throw new UnsupportedOperationException();
}

@Input
public Map<String, Set<File>> getClassFilesPerEnabledTask() {
return getProject().getTasks()
.withType(Test.class)
.stream()
.filter(Task::getEnabled)
.collect(Collectors.toMap(Task::getPath, task -> task.getCandidateClassFiles().getFiles()));
.collect(Collectors.toMap(Task::getPath, task -> {
// See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath
final JvmTestSuite jvmTestSuite = JvmTestSuiteHelper.getDefaultTestSuite(getProject()).orElse(null);
if (jvmTestSuite != null) {
final PatternFilterable patternSet = getPatternSetFactory().create()
.include(task.getIncludes())
.exclude(task.getExcludes());

final Set<File> files = jvmTestSuite.getSources()
.getOutput()
.getClassesDirs()
.getAsFileTree()
.matching(patternSet)
.getFiles();

if (!files.isEmpty()) {
return files;
}
}

return task.getCandidateClassFiles().getFiles();
}));
}

@Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
package org.opensearch.gradle.test;

import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask;

import groovy.lang.Closure;

import org.gradle.api.Task;
import org.gradle.api.tasks.CacheableTask;

/**
Expand All @@ -41,4 +45,12 @@
* conventional configured tasks of {@link RestIntegTestTask}
*/
@CacheableTask
public class RestIntegTestTask extends StandaloneRestIntegTestTask {}
public class RestIntegTestTask extends StandaloneRestIntegTestTask implements TestSuiteConventionMappings {
@SuppressWarnings("rawtypes")
@Override
public Task configure(Closure closure) {
final Task t = super.configure(closure);
applyConventionMapping(getProject(), getConventionMapping());
return t;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle.test;

import org.gradle.api.Project;
import org.gradle.api.internal.ConventionMapping;
import org.opensearch.gradle.jvm.JvmTestSuiteHelper;

// Temporary workaround for https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath
interface TestSuiteConventionMappings {
default void applyConventionMapping(Project project, ConventionMapping conventionMapping) {
JvmTestSuiteHelper.getDefaultTestSuite(project).ifPresent(defaultTestSuite -> {
conventionMapping.map("testClassesDirs", () -> { return defaultTestSuite.getSources().getOutput().getClassesDirs(); });

conventionMapping.map("classpath", () -> { return defaultTestSuite.getSources().getRuntimeClasspath(); });
});
}
}
26 changes: 26 additions & 0 deletions buildSrc/src/main/java/org/opensearch/gradle/test/TestTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle.test;

import groovy.lang.Closure;

import org.gradle.api.Task;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.testing.Test;

@CacheableTask
public class TestTask extends Test implements TestSuiteConventionMappings {
@SuppressWarnings("rawtypes")
@Override
public Task configure(Closure closure) {
final Task t = super.configure(closure);
applyConventionMapping(getProject(), getConventionMapping());
return t;
}
}
2 changes: 1 addition & 1 deletion gradle/code-coverage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {

allprojects {
plugins.withId('jacoco') {
jacoco.toolVersion = '0.8.8'
jacoco.toolVersion = '0.8.9'
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=47a5bfed9ef814f90f8debcbbb315e8e7c654109acd224595ea39fca95c5d4da
distributionSha256Sum=2cbafcd2c47a101cb2165f636b4677fac0b954949c9429c1c988da399defe6a9
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
5 changes: 3 additions & 2 deletions modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.opensearch.gradle.info.BuildParams
import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.test.TestTask
import org.opensearch.gradle.test.rest.JavaRestTestPlugin
import org.opensearch.gradle.test.InternalClusterTestPlugin

Expand Down Expand Up @@ -92,13 +93,13 @@ javaRestTest {
systemProperty 'opensearch.set.netty.runtime.available.processors', 'false'
}

TaskProvider<Test> pooledTest = tasks.register("pooledTest", Test) {
TaskProvider<Test> pooledTest = tasks.register("pooledTest", TestTask) {
include '**/*Tests.class'
systemProperty 'opensearch.set.netty.runtime.available.processors', 'false'
systemProperty 'opensearch.use_unpooled_allocator', 'false'
}

TaskProvider<Test> pooledInternalClusterTest = tasks.register("pooledInternalClusterTest", Test) {
TaskProvider<Test> pooledInternalClusterTest = tasks.register("pooledInternalClusterTest", TestTask) {
include '**/*IT.class'
systemProperty 'opensearch.set.netty.runtime.available.processors', 'false'
systemProperty 'opensearch.use_unpooled_allocator', 'false'
Expand Down
3 changes: 2 additions & 1 deletion plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSec
.resolve("ports")
}
nonInputProperties.systemProperty "test.hdfs-fixture.ports", file("$portsFileDir/ports")
classpath += files(portsFileDir)
// See please https://docs.gradle.org/8.1/userguide/upgrading_version_8.html#test_task_default_classpath
classpath = testing.suites.test.sources.runtimeClasspath + files(portsFileDir)
// Copy ports file to separate location which is placed on the test classpath
doFirst {
mkdir(portsFileDir)
Expand Down
3 changes: 2 additions & 1 deletion plugins/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.opensearch.gradle.MavenFilteringHack
import org.opensearch.gradle.info.BuildParams
import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.test.TestTask
import org.opensearch.gradle.test.rest.YamlRestTestPlugin
import org.opensearch.gradle.test.InternalClusterTestPlugin

Expand Down Expand Up @@ -86,7 +87,7 @@ bundlePlugin {
}
}

task testRepositoryCreds(type: Test) {
task testRepositoryCreds(type: TestTask) {
include '**/RepositoryCredentialsTests.class'
systemProperty 'opensearch.allow_insecure_settings', 'true'
}
Expand Down
3 changes: 2 additions & 1 deletion qa/wildfly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.opensearch.gradle.Architecture
import org.opensearch.gradle.VersionProperties
import org.opensearch.gradle.test.TestTask

apply plugin: 'war'
apply plugin: 'opensearch.build'
Expand Down Expand Up @@ -81,7 +82,7 @@ dockerCompose {
useComposeFiles = ['docker-compose.yml']
}

tasks.register("integTest", Test) {
tasks.register("integTest", TestTask) {
outputs.doNotCacheIf('Build cache is disabled for Docker tests') { true }
maxParallelForks = '1'
include '**/*IT.class'
Expand Down