All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ksoichiro.console.reporter.ReportTestTask.groovy Maven / Gradle / Ivy

There is a newer version: 0.6.3
Show newest version
package com.github.ksoichiro.console.reporter

import com.github.ksoichiro.console.reporter.parser.JUnitReportParser
import com.github.ksoichiro.console.reporter.report.JUnitReport
import com.github.ksoichiro.console.reporter.writer.JUnitReportWriter
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskState
import org.gradle.api.tasks.testing.Test

class ReportTestTask extends DefaultTask {
    public static String NAME = 'reportTest'
    ConsoleReporterExtension extension

    ReportTestTask() {
        project.afterEvaluate {
            extension = project.extensions."${ConsoleReporterExtension.NAME}"

            if (extension.junit.reportOnFailure) {
                project.gradle.taskGraph.afterTask { Task task, TaskState state ->
                    if (task instanceof Test && state.failure) {
                        reportJUnit([task] as Set)
                    }
                }
            }
        }
    }

    @TaskAction
    void exec() {
        if (extension.junit.enabled) {
            reportJUnit(project.getTasks().findAll{ t -> t instanceof Test} as Set)
        }
    }

    void reportJUnit(Set testTask) {
        JUnitReport report = new JUnitReportParser(testTask).parse(project, extension.junit)
        new JUnitReportWriter().write(project, report, extension.junit)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy