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