use of org.gradle.testing.base.TestingExtension in project gradle by gradle.
the class JvmTestSuitePlugin method apply.
@Override
public void apply(Project project) {
project.getPluginManager().apply("org.gradle.test-suite-base");
project.getPluginManager().apply("org.gradle.java-base");
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
testSuites.registerBinding(JvmTestSuite.class, DefaultJvmTestSuite.class);
// TODO: Deprecate this behavior?
// Why would any Test task created need to use the test source set's classes?
project.getTasks().withType(Test.class).configureEach(test -> {
// The test task may have already been created but the test sourceSet may not exist yet.
// So defer looking up the java extension and sourceSet until the convention mapping is resolved.
// See https://github.com/gradle/gradle/issues/18622
test.getConventionMapping().map("testClassesDirs", () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().findByName(SourceSet.TEST_SOURCE_SET_NAME).getOutput().getClassesDirs());
test.getConventionMapping().map("classpath", () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().findByName(SourceSet.TEST_SOURCE_SET_NAME).getRuntimeClasspath());
test.getModularity().getInferModulePath().convention(java.getModularity().getInferModulePath());
});
testSuites.withType(JvmTestSuite.class).all(testSuite -> {
testSuite.getTestType().convention(getDefaultTestType(testSuite));
testSuite.getTargets().all(target -> {
target.getTestTask().configure(test -> {
test.getConventionMapping().map("testClassesDirs", () -> testSuite.getSources().getOutput().getClassesDirs());
test.getConventionMapping().map("classpath", () -> testSuite.getSources().getRuntimeClasspath());
});
});
});
configureTestDataElementsVariants(project);
}
use of org.gradle.testing.base.TestingExtension in project gradle by gradle.
the class IdeaPlugin method configureIdeaModuleForTestSuites.
private void configureIdeaModuleForTestSuites(final Project project) {
final TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
final IdeaModule ideaModule = ideaModelFor(project).getModule();
testing.getSuites().withType(JvmTestSuite.class).configureEach(suite -> {
ideaModule.getTestSources().from(suite.getSources().getAllJava().getSourceDirectories());
ideaModule.getTestResources().from(suite.getSources().getResources().getSourceDirectories());
});
}
use of org.gradle.testing.base.TestingExtension 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