Skip to content

Commit

Permalink
Make JarHell task cacheable (#42551)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed May 30, 2019
1 parent 7cabe8a commit 2a0c30c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
Expand Up @@ -107,14 +107,12 @@ class PrecommitTasks {
}

private static Task configureJarHell(Project project) {
Task task = project.tasks.create('jarHell', JarHellTask.class)
task.classpath = project.sourceSets.test.runtimeClasspath
if (project.plugins.hasPlugin(ShadowPlugin)) {
task.classpath += project.configurations.bundle
return project.tasks.create('jarHell', JarHellTask) { task ->
task.classpath = project.sourceSets.test.runtimeClasspath
if (project.plugins.hasPlugin(ShadowPlugin)) {
task.classpath += project.configurations.bundle
}
}
task.dependsOn(project.sourceSets.test.classesTaskName)
task.javaHome = project.runtimeJavaHome
return task
}

private static Task configureThirdPartyAudit(Project project) {
Expand Down
Expand Up @@ -21,19 +21,20 @@

import org.elasticsearch.gradle.LoggedExec;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.TaskAction;

import java.io.File;

/**
* Runs CheckJarHell on a classpath.
*/
@CacheableTask
public class JarHellTask extends PrecommitTask {

private FileCollection classpath;

private Object javaHome;

public JarHellTask() {
setDescription("Runs CheckJarHell on the configured classpath");
}
Expand All @@ -42,23 +43,15 @@ public JarHellTask() {
public void runJarHellCheck() {
LoggedExec.javaexec(getProject(), spec -> {
spec.classpath(getClasspath());
spec.executable(getJavaHome() + "/bin/java");
spec.setMain("org.elasticsearch.bootstrap.JarHell");
});
}

@Input
public Object getJavaHome() {
return javaHome;
}

public void setJavaHome(Object javaHome) {
this.javaHome = javaHome;
}

@Classpath
// We use compile classpath normalization here because class implementation changes are irrelevant for the purposes of jar hell.
// We only care about the runtime classpath ABI here.
@CompileClasspath
public FileCollection getClasspath() {
return classpath.filter(file -> file.exists());
return classpath.filter(File::exists);
}

public void setClasspath(FileCollection classpath) {
Expand Down

0 comments on commit 2a0c30c

Please sign in to comment.