Search in sources :

Example 1 with JacocoLimit

use of org.gradle.testing.jacoco.tasks.rules.JacocoLimit 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 JacocoLimit

use of org.gradle.testing.jacoco.tasks.rules.JacocoLimit in project gradle by gradle.

the class JacocoViolationRuleImpl method limit.

@Override
public JacocoLimit limit(Action<? super JacocoLimit> configureAction) {
    JacocoLimit limit = new JacocoLimitImpl();
    configureAction.execute(limit);
    limits.add(limit);
    return limit;
}
Also used : JacocoLimit(org.gradle.testing.jacoco.tasks.rules.JacocoLimit)

Example 3 with JacocoLimit

use of org.gradle.testing.jacoco.tasks.rules.JacocoLimit in project gradle by gradle.

the class AntJacocoCheck method configureReport.

@Override
protected void configureReport(final GroovyObjectSupport antBuilder, final JacocoViolationRulesContainer violationRules) {
    if (!violationRules.getRules().isEmpty()) {
        Map<String, Object> checkArgs = ImmutableMap.<String, Object>of("failonviolation", violationRules.isFailOnViolation(), "violationsproperty", VIOLATIONS_ANT_PROPERTY);
        antBuilder.invokeMethod("check", new Object[] { checkArgs, new Closure<Object>(this, this) {

            @SuppressWarnings("UnusedDeclaration")
            public Object doCall(Object ignore) {
                for (final JacocoViolationRule rule : filter(violationRules.getRules(), RULE_ENABLED_PREDICATE)) {
                    Map<String, Object> ruleArgs = ImmutableMap.<String, Object>of("element", rule.getElement(), "includes", Joiner.on(':').join(rule.getIncludes()), "excludes", Joiner.on(':').join(rule.getExcludes()));
                    antBuilder.invokeMethod("rule", new Object[] { ruleArgs, new Closure<Object>(this, this) {

                        @SuppressWarnings("UnusedDeclaration")
                        public Object doCall(Object ignore) {
                            for (JacocoLimit limit : rule.getLimits()) {
                                Map<String, Object> limitArgs = new HashMap<String, Object>();
                                limitArgs.put("counter", limit.getCounter());
                                limitArgs.put("value", limit.getValue());
                                if (limit.getMinimum() != null) {
                                    limitArgs.put("minimum", limit.getMinimum());
                                }
                                if (limit.getMaximum() != null) {
                                    limitArgs.put("maximum", limit.getMaximum());
                                }
                                antBuilder.invokeMethod("limit", new Object[] { ImmutableMap.copyOf(limitArgs) });
                            }
                            return null;
                        }
                    } });
                }
                return null;
            }
        } });
    }
}
Also used : JacocoLimit(org.gradle.testing.jacoco.tasks.rules.JacocoLimit) Closure(groovy.lang.Closure) HashMap(java.util.HashMap) JacocoViolationRule(org.gradle.testing.jacoco.tasks.rules.JacocoViolationRule) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JacocoLimit (org.gradle.testing.jacoco.tasks.rules.JacocoLimit)3 JacocoViolationRule (org.gradle.testing.jacoco.tasks.rules.JacocoViolationRule)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Closure (groovy.lang.Closure)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1 JacocoTaskExtension (org.gradle.testing.jacoco.plugins.JacocoTaskExtension)1 JacocoCoverageVerification (org.gradle.testing.jacoco.tasks.JacocoCoverageVerification)1 JacocoReport (org.gradle.testing.jacoco.tasks.JacocoReport)1