use of org.gradle.api.tasks.testing.AggregateTestReport in project gradle by gradle.
the class TestReportAggregationPlugin method apply.
@Override
public void apply(Project project) {
project.getPluginManager().apply("org.gradle.reporting-base");
final Configuration testAggregation = project.getConfigurations().create(TEST_REPORT_AGGREGATION_CONFIGURATION_NAME);
testAggregation.setDescription("A configuration to collect test execution results");
testAggregation.setVisible(false);
testAggregation.setCanBeConsumed(false);
testAggregation.setCanBeResolved(false);
ReportingExtension reporting = project.getExtensions().getByType(ReportingExtension.class);
reporting.getReports().registerBinding(AggregateTestReport.class, DefaultAggregateTestReport.class);
ObjectFactory objects = project.getObjects();
final DirectoryProperty testReportDirectory = objects.directoryProperty().convention(reporting.getBaseDirectory().dir(TestingBasePlugin.TESTS_DIR_NAME));
// prepare testReportDirectory with a reasonable default, but override with JavaPluginExtension#testReportDirectory if available
project.getPlugins().withId("java-base", plugin -> {
JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
testReportDirectory.convention(javaPluginExtension.getTestReportDir());
});
// iterate and configure each user-specified report, creating a <reportName>Results configuration for each
reporting.getReports().withType(AggregateTestReport.class).all(report -> {
// A resolvable configuration to collect test results; typically named "testResults"
Configuration testResultsConf = project.getConfigurations().create(report.getName() + "Results");
testResultsConf.extendsFrom(testAggregation);
testResultsConf.setDescription(String.format("Supplies test result data to the %s. External library dependencies may appear as resolution failures, but this is expected behavior.", report.getName()));
testResultsConf.setVisible(false);
testResultsConf.setCanBeConsumed(false);
testResultsConf.setCanBeResolved(true);
testResultsConf.attributes(attributes -> {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, report.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.TEST_RESULTS));
});
report.getReportTask().configure(task -> {
Callable<FileCollection> testResults = () -> testResultsConf.getIncoming().artifactView(view -> {
view.componentFilter(id -> id instanceof ProjectComponentIdentifier);
view.lenient(true);
}).getFiles();
task.getTestResults().from(testResults);
task.getDestinationDirectory().convention(testReportDirectory.dir(report.getTestType().map(tt -> tt + "/aggregated-results")));
});
});
// convention for synthesizing reports based on existing test suites in "this" project
project.getPlugins().withId("jvm-test-suite", plugin -> {
// Depend on this project for aggregation
project.getDependencies().add(TEST_REPORT_AGGREGATION_CONFIGURATION_NAME, project);
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
testSuites.withType(JvmTestSuite.class).all(testSuite -> {
reporting.getReports().create(testSuite.getName() + "AggregateTestReport", AggregateTestReport.class, report -> {
report.getTestType().convention(testSuite.getTestType());
});
});
});
}
Aggregations