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

Fix up-to-date checks for precommit related tasks #57203

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
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ public static void configureConfigurations(Project project) {

private static final Pattern LUCENE_SNAPSHOT_REGEX = Pattern.compile("\\w+-snapshot-([a-z0-9]+)");

/** Adds repositories used by ES dependencies */
/**
* Adds repositories used by ES dependencies
*/
public static void configureRepositories(Project project) {
// ensure all repositories use secure urls
// TODO: remove this with gradle 7.0, which no longer allows insecure urls
Expand Down Expand Up @@ -216,7 +218,9 @@ private static void assertRepositoryURIIsSecure(final String repositoryName, fin
}
}

/** Adds compiler settings to the project */
/**
* Adds compiler settings to the project
*/
public static void configureCompile(Project project) {
project.getExtensions().getExtraProperties().set("compactProfile", "full");

Expand Down Expand Up @@ -483,8 +487,11 @@ static void configureJars(Project project) {
// we put all our distributable files under distributions
jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions"));
// fixup the jar manifest
jarTask.doFirst(
t -> {
// Explicitly using an Action interface as java lambdas
// are not supported by Gradle up-to-date checks
jarTask.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
// this doFirst is added before the info plugin, therefore it will run
// after the doFirst added by the info plugin, and we can override attributes
jarTask.getManifest()
Expand All @@ -497,7 +504,7 @@ static void configureJars(Project project) {
)
);
}
);
});
}
);
project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.gradle.VersionProperties;
import org.elasticsearch.gradle.util.Util;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.dsl.DependencyHandler;
Expand Down Expand Up @@ -62,17 +63,22 @@ public TaskProvider<? extends Task> createTask(Project project) {
copyCheckstyleConf.configure(t -> t.getInputs().files(checkstyleConfUrl.getFile(), checkstyleSuppressionsUrl.getFile()));
}

copyCheckstyleConf.configure(t -> t.doLast(task -> {
checkstyleDir.mkdirs();
try (InputStream stream = checkstyleConfUrl.openStream()) {
Files.copy(stream, checkstyleConf.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
try (InputStream stream = checkstyleSuppressionsUrl.openStream()) {
Files.copy(stream, checkstyleSuppressions.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
// Explicitly using an Action interface as java lambdas
// are not supported by Gradle up-to-date checks
copyCheckstyleConf.configure(t -> t.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
checkstyleDir.mkdirs();
try (InputStream stream = checkstyleConfUrl.openStream()) {
Files.copy(stream, checkstyleConf.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
try (InputStream stream = checkstyleSuppressionsUrl.openStream()) {
Files.copy(stream, checkstyleSuppressions.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;

import java.io.File;
Expand Down Expand Up @@ -223,6 +224,15 @@ public void checkDependencies() throws IOException, NoSuchAlgorithmException {
if (shaFiles.isEmpty() == false) {
throw new GradleException("Unused sha files found: \n" + joinFilenames(shaFiles));
}

}

// This is just a marker output folder to allow this task being up-to-date.
// The check logic is exception driven so a failed tasks will not be defined
// by this output but when successful we can safely mark the task as up-to-date.
@OutputDirectory
public File getOutputMarker() {
return new File(getProject().getBuildDir(), "dependencyLicense");
}

private void failIfAnyMissing(String item, Boolean exists, String type) {
Expand Down