Make LoggerUsageTask cacheable (#42550)
(cherry picked from commit 0bb46d73cb89016ab9d96e76693bb0d7cee267a1)
This commit is contained in:
parent
24cf86a013
commit
63eccb16de
|
@ -238,7 +238,6 @@ class PrecommitTasks {
|
||||||
"org.elasticsearch.test:logger-usage:${VersionProperties.elasticsearch}")
|
"org.elasticsearch.test:logger-usage:${VersionProperties.elasticsearch}")
|
||||||
return project.tasks.create('loggerUsageCheck', LoggerUsageTask.class) {
|
return project.tasks.create('loggerUsageCheck', LoggerUsageTask.class) {
|
||||||
classpath = project.configurations.loggerUsagePlugin
|
classpath = project.configurations.loggerUsagePlugin
|
||||||
javaHome = project.runtimeJavaHome
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,13 @@ package org.elasticsearch.gradle.precommit;
|
||||||
import org.elasticsearch.gradle.LoggedExec;
|
import org.elasticsearch.gradle.LoggedExec;
|
||||||
import org.gradle.api.file.FileCollection;
|
import org.gradle.api.file.FileCollection;
|
||||||
import org.gradle.api.plugins.JavaPluginConvention;
|
import org.gradle.api.plugins.JavaPluginConvention;
|
||||||
|
import org.gradle.api.tasks.CacheableTask;
|
||||||
import org.gradle.api.tasks.Classpath;
|
import org.gradle.api.tasks.Classpath;
|
||||||
import org.gradle.api.tasks.Input;
|
|
||||||
import org.gradle.api.tasks.InputFiles;
|
import org.gradle.api.tasks.InputFiles;
|
||||||
|
import org.gradle.api.tasks.PathSensitive;
|
||||||
|
import org.gradle.api.tasks.PathSensitivity;
|
||||||
import org.gradle.api.tasks.SkipWhenEmpty;
|
import org.gradle.api.tasks.SkipWhenEmpty;
|
||||||
|
import org.gradle.api.tasks.SourceSet;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -33,13 +36,13 @@ import java.io.File;
|
||||||
/**
|
/**
|
||||||
* Runs LoggerUsageCheck on a set of directories.
|
* Runs LoggerUsageCheck on a set of directories.
|
||||||
*/
|
*/
|
||||||
|
@CacheableTask
|
||||||
public class LoggerUsageTask extends PrecommitTask {
|
public class LoggerUsageTask extends PrecommitTask {
|
||||||
|
|
||||||
|
private FileCollection classpath;
|
||||||
|
|
||||||
public LoggerUsageTask() {
|
public LoggerUsageTask() {
|
||||||
setDescription("Runs LoggerUsageCheck on output directories of all source sets");
|
setDescription("Runs LoggerUsageCheck on output directories of all source sets");
|
||||||
getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
|
|
||||||
dependsOn(sourceSet.getClassesTaskName());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
|
@ -47,7 +50,6 @@ public class LoggerUsageTask extends PrecommitTask {
|
||||||
LoggedExec.javaexec(getProject(), spec -> {
|
LoggedExec.javaexec(getProject(), spec -> {
|
||||||
spec.setMain("org.elasticsearch.test.loggerusage.ESLoggerUsageChecker");
|
spec.setMain("org.elasticsearch.test.loggerusage.ESLoggerUsageChecker");
|
||||||
spec.classpath(getClasspath());
|
spec.classpath(getClasspath());
|
||||||
spec.executable(getJavaHome() + "/bin/java");
|
|
||||||
getClassDirectories().forEach(spec::args);
|
getClassDirectories().forEach(spec::args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -62,26 +64,17 @@ public class LoggerUsageTask extends PrecommitTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
@InputFiles
|
@InputFiles
|
||||||
|
@PathSensitive(PathSensitivity.RELATIVE)
|
||||||
@SkipWhenEmpty
|
@SkipWhenEmpty
|
||||||
public FileCollection getClassDirectories() {
|
public FileCollection getClassDirectories() {
|
||||||
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
|
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
|
||||||
// Don't pick up all source sets like the java9 ones as logger-check doesn't support the class format
|
// Don't pick up all source sets like the java9 ones as logger-check doesn't support the class format
|
||||||
.filter(sourceSet -> sourceSet.getName().equals("main") || sourceSet.getName().equals("test"))
|
.filter(sourceSet -> sourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||||
|
|| sourceSet.getName().equals(SourceSet.TEST_SOURCE_SET_NAME))
|
||||||
.map(sourceSet -> sourceSet.getOutput().getClassesDirs())
|
.map(sourceSet -> sourceSet.getOutput().getClassesDirs())
|
||||||
.reduce(FileCollection::plus)
|
.reduce(FileCollection::plus)
|
||||||
.orElse(getProject().files())
|
.orElse(getProject().files())
|
||||||
.filter(File::exists);
|
.filter(File::exists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input
|
|
||||||
public Object getJavaHome() {
|
|
||||||
return javaHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setJavaHome(Object javaHome) {
|
|
||||||
this.javaHome = javaHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileCollection classpath;
|
|
||||||
private Object javaHome;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ public class PrecommitTask extends DefaultTask {
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void writeMarker() throws IOException {
|
public void writeMarker() throws IOException {
|
||||||
getSuccessMarker().getParentFile().mkdirs();
|
|
||||||
Files.write(getSuccessMarker().toPath(), new byte[]{}, StandardOpenOption.CREATE);
|
Files.write(getSuccessMarker().toPath(), new byte[]{}, StandardOpenOption.CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue