Search in sources :

Example 1 with ConfigurableReport

use of org.gradle.api.reporting.ConfigurableReport in project gradle by gradle.

the class JacocoPlugin method addDefaultReportTask.

private void addDefaultReportTask(final JacocoPluginExtension extension, final Test task) {
    final JacocoReport reportTask = project.getTasks().create("jacoco" + StringUtils.capitalize(task.getName()) + "Report", JacocoReport.class);
    reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
    reportTask.setDescription(String.format("Generates code coverage report for the %s task.", task.getName()));
    reportTask.executionData(task);
    reportTask.sourceSets(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main"));
    reportTask.getReports().all(new Action<ConfigurableReport>() {

        @Override
        public void execute(final ConfigurableReport report) {
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                report.setDestination(project.provider(new Callable<File>() {

                    @Override
                    public File call() throws Exception {
                        return new File(extension.getReportsDir(), task.getName() + "/" + report.getName());
                    }
                }));
            } else {
                report.setDestination(project.provider(new Callable<File>() {

                    @Override
                    public File call() throws Exception {
                        return new File(extension.getReportsDir(), task.getName() + "/" + reportTask.getName() + "." + report.getName());
                    }
                }));
            }
        }
    });
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) File(java.io.File) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport) ConfigurableReport(org.gradle.api.reporting.ConfigurableReport)

Aggregations

File (java.io.File)1 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)1 ConfigurableReport (org.gradle.api.reporting.ConfigurableReport)1 JacocoReport (org.gradle.testing.jacoco.tasks.JacocoReport)1