Search in sources :

Example 1 with JavaTestFixturesPlugin

use of org.gradle.api.plugins.JavaTestFixturesPlugin 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)

Example 2 with JavaTestFixturesPlugin

use of org.gradle.api.plugins.JavaTestFixturesPlugin in project spring-security by spring-projects.

the class ManagementConfigurationPlugin method apply.

@Override
public void apply(Project project) {
    ConfigurationContainer configurations = project.getConfigurations();
    configurations.create(MANAGEMENT_CONFIGURATION_NAME, (management) -> {
        management.setVisible(false);
        management.setCanBeConsumed(false);
        management.setCanBeResolved(false);
        PluginContainer plugins = project.getPlugins();
        plugins.withType(JavaPlugin.class, (javaPlugin) -> {
            configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
            configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
            configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
            configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(management);
        });
        plugins.withType(JavaTestFixturesPlugin.class, (javaTestFixturesPlugin) -> {
            configurations.getByName("testFixturesCompileClasspath").extendsFrom(management);
            configurations.getByName("testFixturesRuntimeClasspath").extendsFrom(management);
        });
        plugins.withType(MavenPublishPlugin.class, (mavenPublish) -> {
            PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
            publishing.getPublications().withType(MavenPublication.class, (mavenPublication -> {
                mavenPublication.versionMapping((versions) -> versions.allVariants(versionMapping -> versionMapping.fromResolutionResult()));
            }));
        });
        plugins.withType(PropDepsPlugin.class, (propDepsPlugin -> {
            configurations.getByName("optional").extendsFrom(management);
            configurations.getByName("provided").extendsFrom(management);
        }));
    });
}
Also used : PublishingExtension(org.gradle.api.publish.PublishingExtension) Project(org.gradle.api.Project) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) JavaTestFixturesPlugin(org.gradle.api.plugins.JavaTestFixturesPlugin) PropDepsPlugin(org.springframework.gradle.propdeps.PropDepsPlugin) PluginContainer(org.gradle.api.plugins.PluginContainer) JavaPlugin(org.gradle.api.plugins.JavaPlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) Plugin(org.gradle.api.Plugin) PluginContainer(org.gradle.api.plugins.PluginContainer) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Aggregations

ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)2 JavaPlugin (org.gradle.api.plugins.JavaPlugin)2 JavaTestFixturesPlugin (org.gradle.api.plugins.JavaTestFixturesPlugin)2 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Action (org.gradle.api.Action)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 AppliedPlugin (org.gradle.api.plugins.AppliedPlugin)1 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)1 PluginContainer (org.gradle.api.plugins.PluginContainer)1 JvmTestSuite (org.gradle.api.plugins.jvm.JvmTestSuite)1 PublishingExtension (org.gradle.api.publish.PublishingExtension)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1 MavenPublishPlugin (org.gradle.api.publish.maven.plugins.MavenPublishPlugin)1 SourceSet (org.gradle.api.tasks.SourceSet)1