Search in sources :

Example 6 with TestSuite

use of org.gradle.testing.base.TestSuite 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()));
        });
    });
}
Also used : Action(org.gradle.api.Action) Configuration(org.gradle.api.artifacts.Configuration) TestingExtension(org.gradle.testing.base.TestingExtension) JavaPlugin(org.gradle.api.plugins.JavaPlugin) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) JavaTestFixturesPlugin(org.gradle.api.plugins.JavaTestFixturesPlugin) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Callable(java.util.concurrent.Callable) SourceSet(org.gradle.api.tasks.SourceSet) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) TestSuite(org.gradle.testing.base.TestSuite) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Collection(java.util.Collection) List(java.util.List) AppliedPlugin(org.gradle.api.plugins.AppliedPlugin) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite)

Aggregations

JvmTestSuite (org.gradle.api.plugins.jvm.JvmTestSuite)6 TestSuite (org.gradle.testing.base.TestSuite)6 TestingExtension (org.gradle.testing.base.TestingExtension)6 Callable (java.util.concurrent.Callable)3 Configuration (org.gradle.api.artifacts.Configuration)3 ExtensiblePolymorphicDomainObjectContainer (org.gradle.api.ExtensiblePolymorphicDomainObjectContainer)2 Incubating (org.gradle.api.Incubating)2 Plugin (org.gradle.api.Plugin)2 Project (org.gradle.api.Project)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Category (org.gradle.api.attributes.Category)2 TestSuiteType (org.gradle.api.attributes.TestSuiteType)2 VerificationType (org.gradle.api.attributes.VerificationType)2 FileCollection (org.gradle.api.file.FileCollection)2 ObjectFactory (org.gradle.api.model.ObjectFactory)2 DefaultJvmTestSuite (org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuite)2 ReportingExtension (org.gradle.api.reporting.ReportingExtension)2 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1