use of org.gradle.api.plugins.jvm.JvmTestSuite in project gradle by gradle.
the class JacocoPlugin method createCoverageDataVariant.
private void createCoverageDataVariant(Project project, JvmTestSuite suite, JvmTestSuiteTarget target) {
final Configuration variant = project.getConfigurations().create(COVERAGE_DATA_ELEMENTS_VARIANT_PREFIX + StringUtils.capitalize(target.getName()));
variant.setDescription("Binary data file containing results of Jacoco test coverage reporting for the " + suite.getName() + " Test Suite's " + target.getName() + " target.");
variant.setVisible(false);
variant.setCanBeResolved(false);
variant.setCanBeConsumed(true);
variant.extendsFrom(project.getConfigurations().getByName(suite.getSources().getImplementationConfigurationName()), project.getConfigurations().getByName(suite.getSources().getRuntimeOnlyConfigurationName()));
final ObjectFactory objects = project.getObjects();
variant.attributes(attributes -> {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
attributes.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, objects.named(TestSuiteName.class, suite.getName()));
attributes.attribute(TestSuiteTargetName.TEST_SUITE_TARGET_NAME_ATTRIBUTE, objects.named(TestSuiteTargetName.class, target.getName()));
attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, suite.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.JACOCO_RESULTS));
});
variant.getOutgoing().artifact(target.getTestTask().map(task -> task.getExtensions().getByType(JacocoTaskExtension.class).getDestinationFile()), artifact -> {
artifact.setType(ArtifactTypeDefinition.BINARY_DATA_TYPE);
artifact.builtBy(target.getTestTask());
});
}
use of org.gradle.api.plugins.jvm.JvmTestSuite in project gradle by gradle.
the class JacocoPlugin method addDefaultReportAndCoverageVerificationTasks.
/**
* Adds report and coverage verification tasks for specific default test tasks.
*
* @param extension the extension describing the test task names
*/
private void addDefaultReportAndCoverageVerificationTasks(final JacocoPluginExtension extension) {
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
JvmTestSuite defaultTestSuite = testing.getSuites().withType(JvmTestSuite.class).getByName(JvmTestSuitePlugin.DEFAULT_TEST_SUITE_NAME);
defaultTestSuite.getTargets().configureEach(target -> {
TaskProvider<Test> testTask = target.getTestTask();
addDefaultReportTask(extension, testTask);
addDefaultCoverageVerificationTask(testTask);
});
});
}
use of org.gradle.api.plugins.jvm.JvmTestSuite in project gradle by gradle.
the class JavaPlugin method configureBuiltInTest.
private void configureBuiltInTest(Project project, TestingExtension testing, JavaPluginExtension java, SourceSet mainSourceSet) {
final NamedDomainObjectProvider<JvmTestSuite> testSuite = testing.getSuites().register(DEFAULT_TEST_SUITE_NAME, JvmTestSuite.class, suite -> {
final FileCollection mainSourceSetOutput = mainSourceSet.getOutput();
final FileCollection testSourceSetOutput = suite.getSources().getOutput();
suite.getSources().setCompileClasspath(project.getObjects().fileCollection().from(mainSourceSetOutput, project.getConfigurations().getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME)));
suite.getSources().setRuntimeClasspath(project.getObjects().fileCollection().from(testSourceSetOutput, mainSourceSetOutput, project.getConfigurations().getByName(TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
});
// Force the realization of this test suite, targets and task
testSuite.get();
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, task -> task.dependsOn(testSuite));
}
use of org.gradle.api.plugins.jvm.JvmTestSuite in project gradle by gradle.
the class EclipsePlugin method configureJavaClasspath.
private static void configureJavaClasspath(final Project project, final TaskProvider<GenerateEclipseClasspath> task, final EclipseModel model, Collection<SourceSet> testSourceSetsConvention, Collection<Configuration> testConfigurationsConvention) {
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
((IConventionAware) model.getClasspath()).getConventionMapping().map("plusConfigurations", new Callable<Collection<Configuration>>() {
@Override
public Collection<Configuration> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
List<Configuration> sourceSetsConfigurations = Lists.newArrayListWithCapacity(sourceSets.size() * 2);
ConfigurationContainer configurations = project.getConfigurations();
for (SourceSet sourceSet : sourceSets) {
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getCompileClasspathConfigurationName()));
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
return sourceSetsConfigurations;
}
}).cache();
((IConventionAware) model.getClasspath()).getConventionMapping().map("classFolders", new Callable<List<File>>() {
@Override
public List<File> call() {
List<File> result = Lists.newArrayList();
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
result.addAll(sourceSet.getOutput().getDirs().getFiles());
}
return result;
}
});
task.configure(new Action<GenerateEclipseClasspath>() {
@Override
public void execute(GenerateEclipseClasspath task) {
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
task.dependsOn(sourceSet.getOutput().getDirs());
}
}
});
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
sourceSets.configureEach(new Action<SourceSet>() {
@Override
public void execute(SourceSet sourceSet) {
if (sourceSet.getName().toLowerCase(Locale.ROOT).contains("test")) {
// source sets with 'test' in their name are marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the source sets with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
}
});
project.getConfigurations().all(new Action<Configuration>() {
@Override
public void execute(Configuration configuration) {
if (configuration.isCanBeResolved() && configuration.getName().toLowerCase(Locale.ROOT).contains("test")) {
// resolved dependencies from custom configurations with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(configuration);
}
}
});
}
});
project.getPlugins().withType(JavaTestFixturesPlugin.class, new Action<JavaTestFixturesPlugin>() {
@Override
public void execute(JavaTestFixturesPlugin javaTestFixturesPlugin) {
model.getClasspath().getContainsTestFixtures().convention(true);
project.getPluginManager().withPlugin("java", new Action<AppliedPlugin>() {
@Override
public void execute(AppliedPlugin appliedPlugin) {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
SourceSet sourceSet = sourceSets.getByName(TestFixturesSupport.TEST_FIXTURE_SOURCESET_NAME);
// the testFixtures source set is marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the testFixtures source set are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
});
}
});
project.getPlugins().withType(TestSuiteBasePlugin.class, testSuiteBasePlugin -> {
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
ExtensiblePolymorphicDomainObjectContainer<TestSuite> suites = testing.getSuites();
suites.withType(JvmTestSuite.class).configureEach(jvmTestSuite -> {
// jvm test suite source sets are marked as test on the Eclipse classpath
testSourceSetsConvention.add(jvmTestSuite.getSources());
// resolved dependencies from jvm test suites are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getRuntimeClasspathConfigurationName()));
});
});
}
Aggregations