Search in sources :

Example 1 with JvmTestSuite

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());
    });
}
Also used : TestSuiteType(org.gradle.api.attributes.TestSuiteType) JacocoCoverageVerification(org.gradle.testing.jacoco.tasks.JacocoCoverageVerification) StringUtils(org.apache.commons.lang.StringUtils) Category(org.gradle.api.attributes.Category) JavaPlugin(org.gradle.api.plugins.JavaPlugin) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) TestSuite(org.gradle.testing.base.TestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ExtensiblePolymorphicDomainObjectContainer(org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) FileOperations(org.gradle.api.internal.file.FileOperations) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport) Test(org.gradle.api.tasks.testing.Test) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) Report(org.gradle.api.reporting.Report) JvmTestSuiteTarget(org.gradle.api.plugins.jvm.JvmTestSuiteTarget) TestSuiteTargetName(org.gradle.api.attributes.TestSuiteTargetName) TestingExtension(org.gradle.testing.base.TestingExtension) SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) ReportingBasePlugin(org.gradle.api.plugins.ReportingBasePlugin) File(java.io.File) Instantiator(org.gradle.internal.reflect.Instantiator) VerificationType(org.gradle.api.attributes.VerificationType) ObjectFactory(org.gradle.api.model.ObjectFactory) SingleFileReport(org.gradle.api.reporting.SingleFileReport) ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) TestSuiteName(org.gradle.api.attributes.TestSuiteName) JvmTestSuitePlugin(org.gradle.api.plugins.JvmTestSuitePlugin) JacocoBase(org.gradle.testing.jacoco.tasks.JacocoBase) Plugin(org.gradle.api.Plugin) DirectoryReport(org.gradle.api.reporting.DirectoryReport) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) JacocoAgentJar(org.gradle.internal.jacoco.JacocoAgentJar) Category(org.gradle.api.attributes.Category) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ObjectFactory(org.gradle.api.model.ObjectFactory) VerificationType(org.gradle.api.attributes.VerificationType) TestSuiteName(org.gradle.api.attributes.TestSuiteName) TestSuiteTargetName(org.gradle.api.attributes.TestSuiteTargetName)

Example 2 with JvmTestSuite

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);
        });
    });
}
Also used : TestingExtension(org.gradle.testing.base.TestingExtension) Test(org.gradle.api.tasks.testing.Test) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite)

Example 3 with JvmTestSuite

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));
}
Also used : FileCollection(org.gradle.api.file.FileCollection) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite)

Example 4 with JvmTestSuite

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()));
        });
    });
}
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)4 TestingExtension (org.gradle.testing.base.TestingExtension)3 File (java.io.File)2 Configuration (org.gradle.api.artifacts.Configuration)2 JavaPlugin (org.gradle.api.plugins.JavaPlugin)2 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)2 Test (org.gradle.api.tasks.testing.Test)2 TestSuite (org.gradle.testing.base.TestSuite)2 Collection (java.util.Collection)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang.StringUtils)1 Action (org.gradle.api.Action)1 ExtensiblePolymorphicDomainObjectContainer (org.gradle.api.ExtensiblePolymorphicDomainObjectContainer)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)1