Skip to content

Commit

Permalink
Update gradle wrapper to 7.4 (elastic#81963) (elastic#83886)
Browse files Browse the repository at this point in the history
* Make ForbiddenApisPrecommitPlugin plugin Gradle 8.0 compatible
* Fix deprecations on ignoring empty folders for task inputs
* Update Gradle wrapper to 7.4 GA
  • Loading branch information
breskeby authored Feb 15, 2022
1 parent badfbda commit 2d6d830
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,7 @@ public LicenseHeadersTask() {
* constructor can write to it.
*/
@InputFiles
@IgnoreEmptyDirectories
@SkipWhenEmpty
@PathSensitive(PathSensitivity.RELATIVE)
public List<FileCollection> getJavaFiles() {
Expand Down
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Can specify scenarios to use when none are specified on the command line
default-scenarios = ["buildConfiguration_master", "buildConfiguration_branch", "single_project_master", "single_project_branch", "precommit_master", "precommit_branch"]

buildConfiguration_branch {
title = "configuration phase (@testGitCommit@)"
tasks = ["help"]
gradle-args = ["--no-scan", "--no-build-cache"]
run-using = cli // value can be "cli" or "tooling-api"
daemon = warm // value can be "warm", "cold", or "none"
warm-ups = 5
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "@testGitCommit@"
}
}

buildConfiguration_master {
title = "configuration phase (master)"
tasks = ["help"]
gradle-args = ["--no-scan", "--no-build-cache"]
run-using = cli // value can be "cli" or "tooling-api"
daemon = warm // value can be "warm", "cold", or "none"
warm-ups = 5
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "master"
}
}

precommit_branch {
title = "precommit (@testGitCommit@)"
cleanup-tasks = ["clean"]
tasks = ["precommit"]
gradle-args = ["--no-scan", "--no-build-cache"]
run-using = cli // value can be "cli" or "tooling-api"
daemon = warm // value can be "warm", "cold", or "none"
warm-ups = 5
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "@testGitCommit@"
}
}

precommit_master {
title = "precommit (master)"
cleanup-tasks = ["clean"]
tasks = ["precommit"]
gradle-args = ["--no-scan", "--no-build-cache"]
run-using = cli // value can be "cli" or "tooling-api"
daemon = warm // value can be "warm", "cold", or "none"
warm-ups = 5
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "master"
}
}

single_project_branch {
title = "single project (@testGitCommit@)"
tasks = [":server:precommit"]
gradle-args = ["--no-scan"]
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
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "@testGitCommit@"
}
}

single_project_master {
title = "single project (master)"
tasks = [":server:precommit"]
gradle-args = ["--no-scan"]
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
iterations = 10
system-properties {
"BUILD_PERFORMANCE_TEST" = "true"
}
git-checkout = {
build = "master"
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

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.JavaVersion;
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;

Expand All @@ -30,10 +30,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<? extends Task> 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<ExportElasticsearchBuildResourcesTask> resourcesTask = project.getTasks()
.register("forbiddenApisResources", ExportElasticsearchBuildResourcesTask.class);
Expand All @@ -47,76 +61,72 @@ public TaskProvider<? extends Task> 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.getRuntimeJavaVersion().getMajorVersion());
if (BuildParams.getRuntimeJavaVersion().compareTo(JavaVersion.VERSION_14) > 0) {
// TODO: forbidden apis does not yet support java 15, rethink using runtime version
t.setTargetCompatibility(JavaVersion.VERSION_14.getMajorVersion());
}
t.setBundledSignatures(Set.of("jdk-unsafe", "jdk-deprecated", "jdk-non-portable", "jdk-system-out"));
t.setSignaturesFiles(
project.files(resourcesDir.resolve("forbidden/jdk-signatures.txt"), resourcesDir.resolve("forbidden/es-all-signatures.txt"))
);
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 {
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());
if (BuildParams.getRuntimeJavaVersion().compareTo(JavaVersion.VERSION_14) > 0) {
// TODO: forbidden apis does not yet support java 15, rethink using runtime version
t.setTargetCompatibility(JavaVersion.VERSION_14.getMajorVersion());
}
t.setBundledSignatures(Set.of("jdk-unsafe", "jdk-non-portable", "jdk-system-out"));
t.setSignaturesFiles(
t.getSignaturesFiles().plus(project.files(resourcesDir.resolve("forbidden/es-server-signatures.txt")))
project.files(
resourcesDir.resolve("forbidden/jdk-signatures.txt"),
resourcesDir.resolve("forbidden/es-all-signatures.txt")
)
);
}
ExtraPropertiesExtension ext = t.getExtensions().getExtraProperties();
ext.set("replaceSignatureFiles", new Closure<Void>(t) {
@Override
public Void call(Object... names) {
List<Path> 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<Void>(t) {
@Override
public Void call(Object... names) {
List<Path> 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<Void>(t) {
@Override
public Void call(Object... names) {
List<Path> resources = new ArrayList<>(names.length);
for (Object name : names) {
resources.add(resourcesDir.resolve("forbidden/" + name + ".txt"));
});
ext.set("addSignatureFiles", new Closure<Void>(t) {
@Override
public Void call(Object... names) {
List<Path> 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<Task> forbiddenApis = project.getTasks().named("forbiddenApis");
forbiddenApis.configure(t -> t.setGroup(""));
return forbiddenApis;
return forbiddenTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,7 @@ public ForbiddenPatternsTask(ProjectLayout projectLayout) {
}

@InputFiles
@IgnoreEmptyDirectories
@PathSensitive(PathSensitivity.RELATIVE)
@SkipWhenEmpty
public FileCollection getFiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,7 @@ public boolean isSkipHasRestTestCheck() {
}

@SkipWhenEmpty
@IgnoreEmptyDirectories
@InputFiles
public FileTree getInputDir() {
FileTree coreFileTree = null;
Expand Down
Loading

0 comments on commit 2d6d830

Please sign in to comment.