diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/LicenseHeadersTask.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/LicenseHeadersTask.java index 45b6b1d142963..414d6c4762e44 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/LicenseHeadersTask.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/LicenseHeadersTask.java @@ -25,6 +25,7 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.provider.ListProperty; import org.gradle.api.tasks.CacheableTask; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; @@ -68,6 +69,7 @@ public LicenseHeadersTask() { * constructor can write to it. */ @InputFiles + @IgnoreEmptyDirectories @SkipWhenEmpty @PathSensitive(PathSensitivity.RELATIVE) public List getJavaFiles() { diff --git a/build-tools-internal/gradle/wrapper/gradle-wrapper.properties b/build-tools-internal/gradle/wrapper/gradle-wrapper.properties index 7cec6af44e192..d5190930b2f32 100644 --- a/build-tools-internal/gradle/wrapper/gradle-wrapper.properties +++ b/build-tools-internal/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=c9490e938b221daf0094982288e4038deed954a3f12fb54cbf270ddf4e37d879 +distributionSha256Sum=cd5c2958a107ee7f0722004a12d0f8559b4564c34daad7df06cffd4d12a426d0 diff --git a/build-tools-internal/performance/elasticsearch-build-tool-update.scenarios b/build-tools-internal/performance/elasticsearch-build-tool-update.scenarios index 27ff2443e7371..9c7c7abdb8394 100644 --- a/build-tools-internal/performance/elasticsearch-build-tool-update.scenarios +++ b/build-tools-internal/performance/elasticsearch-build-tool-update.scenarios @@ -69,10 +69,9 @@ precommit_master { single_project_branch { title = "single project (@testGitCommit@)" - cleanup-tasks = [":server:clean"] - tasks = [":server:spotlessApply", ":server:precommit"] + tasks = [":server:precommit"] gradle-args = ["--no-scan"] - apply-abi-change-to = "server/src/main/java/org/elasticsearch/Build.java" + apply-abi-change-to = "server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java" run-using = cli // value can be "cli" or "tooling-api" daemon = warm // value can be "warm", "cold", or "none" warm-ups = 5 @@ -87,10 +86,9 @@ single_project_branch { single_project_master { title = "single project (master)" - cleanup-tasks = [":server:clean"] - tasks = [":server:spotlessApply", ":server:precommit"] + tasks = [":server:precommit"] gradle-args = ["--no-scan"] - apply-abi-change-to = "server/src/main/java/org/elasticsearch/Build.java" + apply-abi-change-to = "server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java" run-using = cli // value can be "cli" or "tooling-api" daemon = warm // value can be "warm", "cold", or "none" warm-ups = 5 diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java new file mode 100644 index 0000000000000..e158dd7c755c9 --- /dev/null +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckForbiddenApisTask.java @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.gradle.internal.precommit; + +import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis; + +import org.gradle.api.file.FileTree; +import org.gradle.api.tasks.IgnoreEmptyDirectories; + +/** + * This implementation is used to fix gradle 8 compatibility of + * the CheckForbiddenApis task which is built with gradle 4 support + * in mind. + * */ +public class CheckForbiddenApisTask extends CheckForbiddenApis { + + /** + * Add additional annotation to make this input gradle 8 compliant. + * Otherwise we see a deprecation warning here starting with gradle 7.4 + * */ + @Override + @IgnoreEmptyDirectories + public FileTree getClassFiles() { + return super.getClassFiles(); + } +} diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/FilePermissionsTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/FilePermissionsTask.java index ee3e58fd0552e..bc53358d0a507 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/FilePermissionsTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/FilePermissionsTask.java @@ -14,6 +14,7 @@ import org.gradle.api.file.FileTree; import org.gradle.api.file.ProjectLayout; import org.gradle.api.provider.ListProperty; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; @@ -75,6 +76,7 @@ private static boolean isExecutableFile(File file) { * Returns the files this task will check */ @InputFiles + @IgnoreEmptyDirectories @SkipWhenEmpty public FileCollection getFiles() { return getSources().get() diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenApisPrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenApisPrecommitPlugin.java index 10efa35695cd4..99c36ebabcd1c 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenApisPrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenApisPrecommitPlugin.java @@ -8,19 +8,19 @@ package org.elasticsearch.gradle.internal.precommit; -import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis; -import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin; +import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApisExtension; import groovy.lang.Closure; import org.elasticsearch.gradle.internal.ExportElasticsearchBuildResourcesTask; import org.elasticsearch.gradle.internal.InternalPlugin; import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin; import org.elasticsearch.gradle.internal.info.BuildParams; -import org.elasticsearch.gradle.util.GradleUtils; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.plugins.ExtraPropertiesExtension; -import org.gradle.api.tasks.SourceSet; +import org.gradle.api.plugins.JavaBasePlugin; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.specs.Specs; import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.TaskProvider; @@ -29,10 +29,24 @@ import java.util.List; import java.util.Set; +import static de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin.FORBIDDEN_APIS_EXTENSION_NAME; +import static de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME; + public class ForbiddenApisPrecommitPlugin extends PrecommitPlugin implements InternalPlugin { @Override public TaskProvider createTask(Project project) { - project.getPluginManager().apply(ForbiddenApisPlugin.class); + project.getPluginManager().apply(JavaBasePlugin.class); + + // create Extension for defaults: + var checkForbiddenApisExtension = project.getExtensions() + .create(FORBIDDEN_APIS_EXTENSION_NAME, CheckForbiddenApisExtension.class, project); + + // Create a convenience task for all checks (this does not conflict with extension, as it has higher priority in DSL): + var forbiddenTask = project.getTasks() + .register(FORBIDDEN_APIS_TASK_NAME, task -> { task.setDescription("Runs forbidden-apis checks."); }); + + JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); + // Define our tasks (one for each SourceSet): TaskProvider resourcesTask = project.getTasks() .register("forbiddenApisResources", ExportElasticsearchBuildResourcesTask.class); @@ -47,76 +61,69 @@ public TaskProvider createTask(Project project) { t.copy("forbidden/es-server-signatures.txt"); t.copy("forbidden/snakeyaml-signatures.txt"); }); - project.getTasks().withType(CheckForbiddenApis.class).configureEach(t -> { - t.dependsOn(resourcesTask); - assert t.getName().startsWith(ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME); - String sourceSetName; - if (ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME.equals(t.getName())) { - sourceSetName = "main"; - } else { - // parse out the sourceSetName - char[] chars = t.getName().substring(ForbiddenApisPlugin.FORBIDDEN_APIS_TASK_NAME.length()).toCharArray(); - chars[0] = Character.toLowerCase(chars[0]); - sourceSetName = new String(chars); - } - - SourceSetContainer sourceSets = GradleUtils.getJavaSourceSets(project); - SourceSet sourceSet = sourceSets.getByName(sourceSetName); - t.setClasspath(project.files(sourceSet.getRuntimeClasspath()).plus(sourceSet.getCompileClasspath())); - - t.setTargetCompatibility(BuildParams.getMinimumRuntimeVersion().getMajorVersion()); - t.setBundledSignatures(Set.of("jdk-unsafe", "jdk-non-portable", "jdk-system-out")); - t.setSignaturesFiles( - project.files( - resourcesDir.resolve("forbidden/jdk-signatures.txt"), - resourcesDir.resolve("forbidden/es-all-signatures.txt"), - resourcesDir.resolve("forbidden/jdk-deprecated.txt") - ) - ); - t.setSuppressAnnotations(Set.of("**.SuppressForbidden")); - if (t.getName().endsWith("Test")) { + project.getExtensions().getByType(SourceSetContainer.class).configureEach(sourceSet -> { + String sourceSetTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null); + var sourceSetTask = project.getTasks().register(sourceSetTaskName, CheckForbiddenApisTask.class, t -> { + t.setDescription("Runs forbidden-apis checks on '${sourceSet.name}' classes."); + t.dependsOn(sourceSet.getOutput()); + t.getOutputs().upToDateWhen(Specs.SATISFIES_ALL); + t.setClassesDirs(sourceSet.getOutput().getClassesDirs()); + t.dependsOn(resourcesTask); + t.setClasspath(project.files(sourceSet.getRuntimeClasspath()).plus(sourceSet.getCompileClasspath())); + t.setTargetCompatibility(BuildParams.getMinimumRuntimeVersion().getMajorVersion()); + t.setBundledSignatures(Set.of("jdk-unsafe", "jdk-non-portable", "jdk-system-out")); t.setSignaturesFiles( - t.getSignaturesFiles() - .plus( - project.files( - resourcesDir.resolve("forbidden/es-test-signatures.txt"), - resourcesDir.resolve("forbidden/http-signatures.txt") - ) - ) + project.files( + resourcesDir.resolve("forbidden/jdk-signatures.txt"), + resourcesDir.resolve("forbidden/es-all-signatures.txt"), + resourcesDir.resolve("forbidden/jdk-deprecated.txt") + ) ); - } else { - t.setSignaturesFiles( - t.getSignaturesFiles().plus(project.files(resourcesDir.resolve("forbidden/es-server-signatures.txt"))) - ); - } - ExtraPropertiesExtension ext = t.getExtensions().getExtraProperties(); - ext.set("replaceSignatureFiles", new Closure(t) { - @Override - public Void call(Object... names) { - List resources = new ArrayList<>(names.length); - for (Object name : names) { - resources.add(resourcesDir.resolve("forbidden/" + name + ".txt")); - } - t.setSignaturesFiles(project.files(resources)); - return null; + t.setSuppressAnnotations(Set.of("**.SuppressForbidden")); + if (t.getName().endsWith("Test")) { + t.setSignaturesFiles( + t.getSignaturesFiles() + .plus( + project.files( + resourcesDir.resolve("forbidden/es-test-signatures.txt"), + resourcesDir.resolve("forbidden/http-signatures.txt") + ) + ) + ); + } else { + t.setSignaturesFiles( + t.getSignaturesFiles().plus(project.files(resourcesDir.resolve("forbidden/es-server-signatures.txt"))) + ); } + ExtraPropertiesExtension ext = t.getExtensions().getExtraProperties(); + ext.set("replaceSignatureFiles", new Closure(t) { + @Override + public Void call(Object... names) { + List resources = new ArrayList<>(names.length); + for (Object name : names) { + resources.add(resourcesDir.resolve("forbidden/" + name + ".txt")); + } + t.setSignaturesFiles(project.files(resources)); + return null; + } - }); - ext.set("addSignatureFiles", new Closure(t) { - @Override - public Void call(Object... names) { - List resources = new ArrayList<>(names.length); - for (Object name : names) { - resources.add(resourcesDir.resolve("forbidden/" + name + ".txt")); + }); + ext.set("addSignatureFiles", new Closure(t) { + @Override + public Void call(Object... names) { + List resources = new ArrayList<>(names.length); + for (Object name : names) { + resources.add(resourcesDir.resolve("forbidden/" + name + ".txt")); + } + t.setSignaturesFiles(t.getSignaturesFiles().plus(project.files(resources))); + return null; } - t.setSignaturesFiles(t.getSignaturesFiles().plus(project.files(resources))); - return null; - } + }); + }); + forbiddenTask.configure(t -> t.dependsOn(sourceSetTask)); }); - TaskProvider forbiddenApis = project.getTasks().named("forbiddenApis"); - forbiddenApis.configure(t -> t.setGroup("")); - return forbiddenApis; + return forbiddenTask; } } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java index e4d732149e0eb..32059eefb8683 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ForbiddenPatternsTask.java @@ -16,6 +16,7 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; @@ -90,6 +91,7 @@ public ForbiddenPatternsTask(ProjectLayout projectLayout) { } @InputFiles + @IgnoreEmptyDirectories @PathSensitive(PathSensitivity.RELATIVE) @SkipWhenEmpty public FileCollection getFiles() { diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java index 8d03ff609d685..bfb53c23b5f1c 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java @@ -44,6 +44,7 @@ import org.gradle.api.file.FileSystemOperations; import org.gradle.api.file.FileTree; import org.gradle.api.model.ObjectFactory; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; @@ -417,6 +418,7 @@ public DirectoryProperty getOutputDirectory() { } @SkipWhenEmpty + @IgnoreEmptyDirectories @InputFiles public FileTree getTestFiles() { return sourceDirectory.getAsFileTree().matching(testPatternSet); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java index e6a4a0a7a1397..5c00e0428c9b7 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java @@ -15,6 +15,7 @@ import org.gradle.api.file.ProjectLayout; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.ListProperty; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; @@ -86,6 +87,7 @@ public boolean isSkipHasRestTestCheck() { } @SkipWhenEmpty + @IgnoreEmptyDirectories @InputFiles public FileTree getInputDir() { FileTree coreFileTree = null; diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java index 4513c64d91183..5cc68f8e73d45 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java @@ -16,6 +16,7 @@ import org.gradle.api.file.ProjectLayout; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.ListProperty; +import org.gradle.api.tasks.IgnoreEmptyDirectories; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Optional; @@ -98,6 +99,7 @@ public Map getSubstitutions() { } @SkipWhenEmpty + @IgnoreEmptyDirectories @InputFiles public FileTree getInputDir() { FileTree coreFileTree = null; diff --git a/build-tools-internal/src/main/resources/minimumGradleVersion b/build-tools-internal/src/main/resources/minimumGradleVersion index c6db724bfd030..9904c66141eab 100644 --- a/build-tools-internal/src/main/resources/minimumGradleVersion +++ b/build-tools-internal/src/main/resources/minimumGradleVersion @@ -1 +1 @@ -7.3.3 \ No newline at end of file +7.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2ae88..41d9927a4d4fb 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7cec6af44e192..d5190930b2f32 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=c9490e938b221daf0094982288e4038deed954a3f12fb54cbf270ddf4e37d879 +distributionSha256Sum=cd5c2958a107ee7f0722004a12d0f8559b4564c34daad7df06cffd4d12a426d0 diff --git a/plugins/examples/gradle/wrapper/gradle-wrapper.properties b/plugins/examples/gradle/wrapper/gradle-wrapper.properties index 7cec6af44e192..d5190930b2f32 100644 --- a/plugins/examples/gradle/wrapper/gradle-wrapper.properties +++ b/plugins/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=c9490e938b221daf0094982288e4038deed954a3f12fb54cbf270ddf4e37d879 +distributionSha256Sum=cd5c2958a107ee7f0722004a12d0f8559b4564c34daad7df06cffd4d12a426d0