Search in sources :

Example 1 with JacocoReport

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);
}
Also used : JacocoLimit(org.gradle.testing.jacoco.tasks.rules.JacocoLimit) TaskContainer(org.gradle.api.tasks.TaskContainer) JacocoViolationRule(org.gradle.testing.jacoco.tasks.rules.JacocoViolationRule) JacocoCoverageVerification(org.gradle.testing.jacoco.tasks.JacocoCoverageVerification) JacocoTaskExtension(org.gradle.testing.jacoco.plugins.JacocoTaskExtension) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport)

Example 2 with JacocoReport

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());
                    }
                }));
            }
        }
    });
}
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)

Example 3 with JacocoReport

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()));
        }
    }));
}
Also used : TestSuiteType(org.gradle.api.attributes.TestSuiteType) JacocoCoverageVerification(org.gradle.testing.jacoco.tasks.JacocoCoverageVerification) StringUtils(org.apache.commons.lang.StringUtils) Category(org.gradle.api.attributes.Category) JavaPlugin(org.gradle.api.plugins.JavaPlugin) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) TestSuite(org.gradle.testing.base.TestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ExtensiblePolymorphicDomainObjectContainer(org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) FileOperations(org.gradle.api.internal.file.FileOperations) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport) Test(org.gradle.api.tasks.testing.Test) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) Report(org.gradle.api.reporting.Report) JvmTestSuiteTarget(org.gradle.api.plugins.jvm.JvmTestSuiteTarget) TestSuiteTargetName(org.gradle.api.attributes.TestSuiteTargetName) TestingExtension(org.gradle.testing.base.TestingExtension) SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) ReportingBasePlugin(org.gradle.api.plugins.ReportingBasePlugin) File(java.io.File) Instantiator(org.gradle.internal.reflect.Instantiator) VerificationType(org.gradle.api.attributes.VerificationType) ObjectFactory(org.gradle.api.model.ObjectFactory) SingleFileReport(org.gradle.api.reporting.SingleFileReport) ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) TestSuiteName(org.gradle.api.attributes.TestSuiteName) JvmTestSuitePlugin(org.gradle.api.plugins.JvmTestSuitePlugin) JacocoBase(org.gradle.testing.jacoco.tasks.JacocoBase) Plugin(org.gradle.api.Plugin) DirectoryReport(org.gradle.api.reporting.DirectoryReport) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) JacocoAgentJar(org.gradle.internal.jacoco.JacocoAgentJar) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DirectoryReport(org.gradle.api.reporting.DirectoryReport) SingleFileReport(org.gradle.api.reporting.SingleFileReport)

Aggregations

JacocoReport (org.gradle.testing.jacoco.tasks.JacocoReport)3 File (java.io.File)2 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang.StringUtils)1 ExtensiblePolymorphicDomainObjectContainer (org.gradle.api.ExtensiblePolymorphicDomainObjectContainer)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)1 Category (org.gradle.api.attributes.Category)1 TestSuiteName (org.gradle.api.attributes.TestSuiteName)1 TestSuiteTargetName (org.gradle.api.attributes.TestSuiteTargetName)1 TestSuiteType (org.gradle.api.attributes.TestSuiteType)1 VerificationType (org.gradle.api.attributes.VerificationType)1 DirectoryProperty (org.gradle.api.file.DirectoryProperty)1 FileOperations (org.gradle.api.internal.file.FileOperations)1 SerializableLambdas.action (org.gradle.api.internal.lambdas.SerializableLambdas.action)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1