use of org.gradle.testing.jacoco.tasks.JacocoReport in project checkstyle-idea by jshiell.
the class CustomSourceSetCreator method setupCoverageVerification.
public void setupCoverageVerification() {
final TaskContainer tasks = project.getTasks();
// Disable JaCoCo for 'test' source set
final JacocoTaskExtension jacocoTestTaskExtension = (JacocoTaskExtension) tasks.getByName(JavaPlugin.TEST_TASK_NAME).getExtensions().getByName(JacocoPluginExtension.TASK_EXTENSION_NAME);
jacocoTestTaskExtension.setEnabled(false);
tasks.remove(tasks.getByName("jacocoTestReport"));
tasks.remove(tasks.getByName("jacocoTestCoverageVerification"));
// Enable JaCoCo reporting for 'csaccess' source set
final JacocoReport jacocoReportTask = tasks.create(JACOCO_REPORT_TASK_NAME, JacocoReport.class);
jacocoReportTask.dependsOn(tasks.getByName(CsaccessTestTask.NAME), tasks.getByName(CsaccessTestTask.XTEST_TASK_NAME));
jacocoReportTask.setDescription("Generate exclusive JaCoCo test report on the '" + CSACCESS_SOURCESET_NAME + "' classes");
configureJacocoTask(jacocoReportTask);
jacocoReportTask.getReports().getXml().setEnabled(true);
jacocoReportTask.getReports().getCsv().setEnabled(false);
jacocoReportTask.getReports().getHtml().setEnabled(true);
// Verify minimum line coverage for 'csaccess' source set
final JacocoCoverageVerification jacocoVerificationTask = tasks.create(JACOCO_VERIFICATION_TASK_NAME, JacocoCoverageVerification.class);
jacocoVerificationTask.dependsOn(jacocoReportTask);
jacocoVerificationTask.setDescription("Ensure that '" + CSACCESS_SOURCESET_NAME + "' test coverage does not drop below a certain level");
configureJacocoTask(jacocoVerificationTask);
jacocoVerificationTask.getViolationRules().rule((final JacocoViolationRule rule) -> {
rule.limit((final JacocoLimit jacocoLimit) -> {
jacocoLimit.setMinimum(BigDecimal.valueOf(MINIMUM_CSACCESS_COVERAGE));
});
});
// Wire 'build' task so that it ensures coverage
tasks.getByName(LifecycleBasePlugin.BUILD_TASK_NAME).dependsOn(jacocoVerificationTask);
}
use of org.gradle.testing.jacoco.tasks.JacocoReport 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());
}
}));
}
}
});
}
use of org.gradle.testing.jacoco.tasks.JacocoReport in project gradle by gradle.
the class JacocoPlugin method configureJacocoReportDefaults.
private void configureJacocoReportDefaults(final JacocoPluginExtension extension, final JacocoReport reportTask) {
reportTask.getReports().all(action(report -> report.getRequired().convention(report.getName().equals("html"))));
DirectoryProperty reportsDir = extension.getReportsDirectory();
reportTask.getReports().all(action(report -> {
if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
((DirectoryReport) report).getOutputLocation().convention(reportsDir.dir(reportTask.getName() + "/" + report.getName()));
} else {
((SingleFileReport) report).getOutputLocation().convention(reportsDir.file(reportTask.getName() + "/" + reportTask.getName() + "." + report.getName()));
}
}));
}
Aggregations