|
39 | 39 | import org.gradle.api.artifacts.dsl.RepositoryHandler;
|
40 | 40 | import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
|
41 | 41 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
| 42 | +import org.gradle.api.execution.TaskActionListener; |
42 | 43 | import org.gradle.api.file.FileCollection;
|
43 | 44 | import org.gradle.api.plugins.BasePlugin;
|
44 | 45 | import org.gradle.api.plugins.JavaPlugin;
|
@@ -78,8 +79,11 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
78 | 79 | public void apply(Project project) {
|
79 | 80 | // make sure the global build info plugin is applied to the root project
|
80 | 81 | project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
|
| 82 | + // apply global test task failure listener |
| 83 | + project.getRootProject().getPluginManager().apply(TestFailureReportingPlugin.class); |
81 | 84 |
|
82 | 85 | project.getPluginManager().apply(JavaPlugin.class);
|
| 86 | + |
83 | 87 | configureConfigurations(project);
|
84 | 88 | configureRepositories(project);
|
85 | 89 | configureCompile(project);
|
@@ -545,4 +549,31 @@ private static void configureJavadoc(Project project) {
|
545 | 549 | .named(LifecycleBasePlugin.CHECK_TASK_NAME)
|
546 | 550 | .configure(t -> t.dependsOn(project.getTasks().withType(Javadoc.class)));
|
547 | 551 | }
|
| 552 | + |
| 553 | + static class TestFailureReportingPlugin implements Plugin<Project> { |
| 554 | + @Override |
| 555 | + public void apply(Project project) { |
| 556 | + if (project != project.getRootProject()) { |
| 557 | + throw new IllegalStateException(this.getClass().getName() + " can only be applied to the root project."); |
| 558 | + } |
| 559 | + |
| 560 | + project.getGradle().addListener(new TaskActionListener() { |
| 561 | + @Override |
| 562 | + public void beforeActions(Task task) {} |
| 563 | + |
| 564 | + @Override |
| 565 | + public void afterActions(Task task) { |
| 566 | + if (task instanceof Test) { |
| 567 | + ErrorReportingTestListener listener = task.getExtensions().findByType(ErrorReportingTestListener.class); |
| 568 | + if (listener != null && listener.getFailedTests().size() > 0) { |
| 569 | + task.getLogger().lifecycle("\nTests with failures:"); |
| 570 | + for (ErrorReportingTestListener.Descriptor failure : listener.getFailedTests()) { |
| 571 | + task.getLogger().lifecycle(" - " + failure.getFullName()); |
| 572 | + } |
| 573 | + } |
| 574 | + } |
| 575 | + } |
| 576 | + }); |
| 577 | + } |
| 578 | + } |
548 | 579 | }
|
0 commit comments