|
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;
|
@@ -79,8 +80,11 @@ public class ElasticsearchJavaPlugin implements Plugin<Project> {
|
79 | 80 | public void apply(Project project) {
|
80 | 81 | // make sure the global build info plugin is applied to the root project
|
81 | 82 | project.getRootProject().getPluginManager().apply(GlobalBuildInfoPlugin.class);
|
| 83 | + // apply global test task failure listener |
| 84 | + project.getRootProject().getPluginManager().apply(TestFailureReportingPlugin.class); |
82 | 85 |
|
83 | 86 | project.getPluginManager().apply(JavaPlugin.class);
|
| 87 | + |
84 | 88 | configureConfigurations(project);
|
85 | 89 | configureRepositories(project);
|
86 | 90 | configureCompile(project);
|
@@ -541,4 +545,31 @@ private static void configureJavadoc(Project project) {
|
541 | 545 | // ensure javadoc task is run with 'check'
|
542 | 546 | project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(t -> t.dependsOn(javadoc));
|
543 | 547 | }
|
| 548 | + |
| 549 | + static class TestFailureReportingPlugin implements Plugin<Project> { |
| 550 | + @Override |
| 551 | + public void apply(Project project) { |
| 552 | + if (project != project.getRootProject()) { |
| 553 | + throw new IllegalStateException(this.getClass().getName() + " can only be applied to the root project."); |
| 554 | + } |
| 555 | + |
| 556 | + project.getGradle().addListener(new TaskActionListener() { |
| 557 | + @Override |
| 558 | + public void beforeActions(Task task) {} |
| 559 | + |
| 560 | + @Override |
| 561 | + public void afterActions(Task task) { |
| 562 | + if (task instanceof Test) { |
| 563 | + ErrorReportingTestListener listener = task.getExtensions().findByType(ErrorReportingTestListener.class); |
| 564 | + if (listener != null && listener.getFailedTests().size() > 0) { |
| 565 | + task.getLogger().lifecycle("\nTests with failures:"); |
| 566 | + for (ErrorReportingTestListener.Descriptor failure : listener.getFailedTests()) { |
| 567 | + task.getLogger().lifecycle(" - " + failure.getFullName()); |
| 568 | + } |
| 569 | + } |
| 570 | + } |
| 571 | + } |
| 572 | + }); |
| 573 | + } |
| 574 | + } |
544 | 575 | }
|
0 commit comments