Search in sources :

Example 21 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.

the class XCTestConventionPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply(SwiftBasePlugin.class);
    project.getPluginManager().apply(NativeTestingBasePlugin.class);
    final ProviderFactory providers = project.getProviders();
    // Create test suite component
    // TODO - Reuse logic from Swift*Plugin
    // TODO - component name and extension name aren't the same
    // TODO - should use `src/xctest/swift` as the convention?
    // Add the test suite and extension
    DefaultSwiftXCTestSuite testSuite = componentFactory.newInstance(SwiftXCTestSuite.class, DefaultSwiftXCTestSuite.class, "test");
    project.getExtensions().add(SwiftXCTestSuite.class, "xctest", testSuite);
    project.getComponents().add(testSuite);
    // Setup component
    testSuite.getModule().set(GUtil.toCamelCase(project.getName() + "Test"));
    final DefaultSwiftXCTestSuite testComponent = testSuite;
    testComponent.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
    testComponent.getSourceCompatibility().convention(testComponent.getTestedComponent().flatMap(it -> it.getSourceCompatibility()));
    final String mainComponentName = "main";
    project.getComponents().withType(ProductionSwiftComponent.class, component -> {
        if (mainComponentName.equals(component.getName())) {
            testComponent.getTargetMachines().convention(component.getTargetMachines());
            testComponent.getTestedComponent().convention(component);
        }
    });
    testComponent.getTestBinary().convention(project.provider(() -> {
        return testComponent.getBinaries().get().stream().filter(SwiftXCTestBinary.class::isInstance).map(SwiftXCTestBinary.class::cast).findFirst().orElse(null);
    }));
    testComponent.getBinaries().whenElementKnown(DefaultSwiftXCTestBinary.class, binary -> {
        // Create test suite test task
        TaskProvider<XCTest> testingTask = project.getTasks().register("xcTest", XCTest.class, task -> {
            task.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
            task.setDescription("Executes XCTest suites");
            task.getTestInstallDirectory().set(binary.getInstallDirectory());
            task.getRunScriptFile().set(binary.getRunScriptFile());
            task.getWorkingDirectory().set(binary.getInstallDirectory());
        });
        binary.getRunTask().set(testingTask);
        configureTestSuiteBuildingTasks(project, binary);
        configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
    });
    project.afterEvaluate(p -> {
        final SwiftComponent mainComponent = testComponent.getTestedComponent().getOrNull();
        final SetProperty<TargetMachine> mainTargetMachines = mainComponent != null ? mainComponent.getTargetMachines() : null;
        Dimensions.unitTestVariants(testComponent.getModule(), testComponent.getTargetMachines(), mainTargetMachines, objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
            if (tryToBuildOnHost(variantIdentity)) {
                testComponent.getSourceCompatibility().finalizeValue();
                ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class, new DefaultSwiftPlatform(variantIdentity.getTargetMachine(), testComponent.getSourceCompatibility().getOrNull()));
                // Create test suite executable
                if (result.getTargetPlatform().getTargetMachine().getOperatingSystemFamily().isMacOs()) {
                    testComponent.addBundle(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
                } else {
                    testComponent.addExecutable(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
                }
            }
        });
        testComponent.getBinaries().realizeNow();
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) GUtil(org.gradle.util.internal.GUtil) Provider(org.gradle.api.provider.Provider) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) SwiftBasePlugin(org.gradle.language.swift.plugins.SwiftBasePlugin) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) MacOSSdkPlatformPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPlatformPathLocator) TaskContainer(org.gradle.api.tasks.TaskContainer) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Lists(com.google.common.collect.Lists) Sync(org.gradle.api.tasks.Sync) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) SwiftApplication(org.gradle.language.swift.SwiftApplication) SwiftComponent(org.gradle.language.swift.SwiftComponent) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) File(java.io.File) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) ObjectFactory(org.gradle.api.model.ObjectFactory) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) RegularFile(org.gradle.api.file.RegularFile) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) SwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.SwiftXCTestSuite) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftComponent(org.gradle.language.swift.SwiftComponent) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform)

Example 22 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.

the class MavenPublishPlugin method realizePublishingTasksLater.

private void realizePublishingTasksLater(final Project project, final PublishingExtension extension) {
    final NamedDomainObjectSet<MavenPublicationInternal> mavenPublications = extension.getPublications().withType(MavenPublicationInternal.class);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final TaskProvider<Task> publishLifecycleTask = tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME);
    final TaskProvider<Task> publishLocalLifecycleTask = tasks.named(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME);
    final NamedDomainObjectList<MavenArtifactRepository> repositories = extension.getRepositories().withType(MavenArtifactRepository.class);
    repositories.all(repository -> tasks.register(publishAllToSingleRepoTaskName(repository), publish -> {
        publish.setDescription("Publishes all Maven publications produced by this project to the " + repository.getName() + " repository.");
        publish.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    }));
    mavenPublications.all(publication -> {
        createGenerateMetadataTask(tasks, publication, mavenPublications, buildDirectory);
        createGeneratePomTask(tasks, publication, buildDirectory, project);
        createLocalInstallTask(tasks, publishLocalLifecycleTask, publication);
        createPublishTasksForEachMavenRepo(tasks, publishLifecycleTask, publication, repositories);
    });
}
Also used : NamedDomainObjectFactory(org.gradle.api.NamedDomainObjectFactory) VersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal) MavenArtifactNotationParserFactory(org.gradle.api.publish.maven.internal.artifact.MavenArtifactNotationParserFactory) PluginManager(org.gradle.api.plugins.PluginManager) GenerateModuleMetadata(org.gradle.api.publish.tasks.GenerateModuleMetadata) NamedDomainObjectList(org.gradle.api.NamedDomainObjectList) MavenPublication(org.gradle.api.publish.maven.MavenPublication) PublishToMavenLocal(org.gradle.api.publish.maven.tasks.PublishToMavenLocal) PublishToMavenRepository(org.gradle.api.publish.maven.tasks.PublishToMavenRepository) Module(org.gradle.api.internal.artifacts.Module) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Task(org.gradle.api.Task) WritableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publication.WritableMavenProjectIdentity) PublishingExtension(org.gradle.api.publish.PublishingExtension) PublishingPlugin(org.gradle.api.publish.plugins.PublishingPlugin) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) DefaultVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVersionMappingStrategy) StringUtils.capitalize(org.apache.commons.lang.StringUtils.capitalize) Usage(org.gradle.api.attributes.Usage) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Project(org.gradle.api.Project) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) InstantiatorFactory(org.gradle.internal.instantiation.InstantiatorFactory) Set(java.util.Set) NamedDomainObjectSet(org.gradle.api.NamedDomainObjectSet) DefaultMavenPublication(org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication) MutableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MutableMavenProjectIdentity) Instantiator(org.gradle.internal.reflect.Instantiator) ProviderFactory(org.gradle.api.provider.ProviderFactory) GenerateMavenPom(org.gradle.api.publish.maven.tasks.GenerateMavenPom) FileResolver(org.gradle.api.internal.file.FileResolver) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) DependencyMetaDataProvider(org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider) Plugin(org.gradle.api.Plugin) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) NotationParser(org.gradle.internal.typeconversion.NotationParser) Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)

Example 23 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.

the class DefaultJvmVariantBuilder method build.

void build() {
    SourceSet sourceSet = this.sourceSet == null ? sourceSets.maybeCreate(name) : this.sourceSet;
    boolean mainSourceSet = SourceSet.isMain(sourceSet);
    String apiConfigurationName;
    String implementationConfigurationName;
    String apiElementsConfigurationName;
    String runtimeElementsConfigurationName;
    String compileOnlyConfigurationName;
    String compileOnlyApiConfigurationName;
    String runtimeOnlyConfigurationName;
    if (mainSourceSet) {
        apiConfigurationName = name + "Api";
        implementationConfigurationName = name + "Implementation";
        apiElementsConfigurationName = apiConfigurationName + "Elements";
        runtimeElementsConfigurationName = name + "RuntimeElements";
        compileOnlyConfigurationName = name + "CompileOnly";
        compileOnlyApiConfigurationName = name + "CompileOnlyApi";
        runtimeOnlyConfigurationName = name + "RuntimeOnly";
    } else {
        apiConfigurationName = sourceSet.getApiConfigurationName();
        implementationConfigurationName = sourceSet.getImplementationConfigurationName();
        apiElementsConfigurationName = sourceSet.getApiElementsConfigurationName();
        runtimeElementsConfigurationName = sourceSet.getRuntimeElementsConfigurationName();
        compileOnlyConfigurationName = sourceSet.getCompileOnlyConfigurationName();
        compileOnlyApiConfigurationName = sourceSet.getCompileOnlyApiConfigurationName();
        runtimeOnlyConfigurationName = sourceSet.getRuntimeOnlyConfigurationName();
    }
    String displayName = this.displayName == null ? name : this.displayName;
    // In the general case, the following configurations are already created
    // but if we're using the "main" source set, it means that the component we're creating shares
    // the same source set (main) but declares its dependencies in its own buckets, so we need
    // to create them
    Configuration implementation = bucket("Implementation", implementationConfigurationName, displayName);
    Configuration compileOnly = bucket("Compile-Only", compileOnlyConfigurationName, displayName);
    Configuration compileOnlyApi = bucket("Compile-Only API", compileOnlyApiConfigurationName, displayName);
    Configuration runtimeOnly = bucket("Runtime-Only", runtimeOnlyConfigurationName, displayName);
    TaskProvider<Task> jarTask = registerOrGetJarTask(sourceSet, displayName);
    Configuration api = exposeApi ? bucket("API", apiConfigurationName, displayName) : null;
    Configuration apiElements = exposeApi ? jvmPluginServices.createOutgoingElements(apiElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesApi().withDescription("API elements for " + displayName).extendsFrom(api, compileOnlyApi).withCapabilities(capabilities).withClassDirectoryVariant().artifact(jarTask);
    }) : null;
    if (exposeApi) {
        implementation.extendsFrom(api);
    }
    Configuration runtimeElements = jvmPluginServices.createOutgoingElements(runtimeElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesRuntime().withDescription("Runtime elements for " + displayName).extendsFrom(implementation, runtimeOnly).withCapabilities(capabilities).artifact(jarTask);
    });
    if (mainSourceSet) {
        // we need to wire the compile only and runtime only to the classpath configurations
        configurations.getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(implementation, compileOnly);
        configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(implementation, runtimeOnly);
        // and we also want the feature dependencies to be available on the test classpath
        configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, compileOnlyApi);
        configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, runtimeOnly);
    }
    final AdhocComponentWithVariants component = findJavaComponent();
    JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
    configureJavaDocTask(name, sourceSet, tasks, javaPluginExtension);
    if (javadocJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getJavadocElementsConfigurationName(), mainSourceSet ? null : name, displayName, JAVADOC, sourceSet.getJavadocJarTaskName(), tasks.named(sourceSet.getJavadocTaskName()), component);
    }
    if (sourcesJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getSourcesElementsConfigurationName(), mainSourceSet ? null : name, displayName, SOURCES, sourceSet.getSourcesJarTaskName(), sourceSet.getAllSource(), component);
    }
    if (published && component != null) {
        if (apiElements != null) {
            component.addVariantsFromConfiguration(apiElements, new JavaConfigurationVariantMapping("compile", true));
        }
        component.addVariantsFromConfiguration(runtimeElements, new JavaConfigurationVariantMapping("runtime", true));
    }
}
Also used : SOURCES(org.gradle.api.attributes.DocsType.SOURCES) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Task(org.gradle.api.Task) Lists(com.google.common.collect.Lists) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TextUtil(org.gradle.util.internal.TextUtil) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) ProjectDerivedCapability(org.gradle.internal.component.external.model.ProjectDerivedCapability) Nullable(javax.annotation.Nullable) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) JAVADOC(org.gradle.api.attributes.DocsType.JAVADOC) List(java.util.List) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) Capability(org.gradle.api.capabilities.Capability) TaskContainer(org.gradle.api.tasks.TaskContainer) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SoftwareComponent(org.gradle.api.component.SoftwareComponent) SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) Configuration(org.gradle.api.artifacts.Configuration) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension)

Example 24 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.

the class EclipsePlugin method configureEclipseJdt.

private void configureEclipseJdt(final Project project, final EclipseModel model) {
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            model.setJdt(project.getObjects().newInstance(EclipseJdt.class, new PropertiesFileContentMerger(new PropertiesTransformer())));
            final TaskProvider<GenerateEclipseJdt> task = project.getTasks().register(ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, model.getJdt());
            task.configure(new Action<GenerateEclipseJdt>() {

                @Override
                public void execute(GenerateEclipseJdt task) {
                    // task properties:
                    task.setDescription("Generates the Eclipse JDT settings file.");
                    task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                }
            });
            addWorker(task, ECLIPSE_JDT_TASK_NAME);
            // model properties:
            ConventionMapping conventionMapping = ((IConventionAware) model.getJdt()).getConventionMapping();
            conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {

                @Override
                public JavaVersion call() {
                    return project.getExtensions().getByType(JavaPluginExtension.class).getSourceCompatibility();
                }
            });
            conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {

                @Override
                public JavaVersion call() {
                    return project.getExtensions().getByType(JavaPluginExtension.class).getTargetCompatibility();
                }
            });
            conventionMapping.map("javaRuntimeName", new Callable<String>() {

                @Override
                public String call() {
                    return eclipseJavaRuntimeNameFor(project.getExtensions().getByType(JavaPluginExtension.class).getTargetCompatibility());
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) PropertiesFileContentMerger(org.gradle.plugins.ide.api.PropertiesFileContentMerger) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) ConventionMapping(org.gradle.api.internal.ConventionMapping) PropertiesTransformer(org.gradle.api.internal.PropertiesTransformer) TaskProvider(org.gradle.api.tasks.TaskProvider) Callable(java.util.concurrent.Callable)

Example 25 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project gradle by gradle.

the class EclipsePlugin method configureEclipseClasspath.

private void configureEclipseClasspath(final Project project, final EclipseModel model) {
    model.setClasspath(project.getObjects().newInstance(EclipseClasspath.class, project));
    ((IConventionAware) model.getClasspath()).getConventionMapping().map("defaultOutputDir", new Callable<File>() {

        @Override
        public File call() {
            return new File(project.getProjectDir(), EclipsePluginConstants.DEFAULT_PROJECT_OUTPUT_PATH);
        }
    });
    model.getClasspath().getTestSourceSets().convention(testSourceSetsConvention);
    model.getClasspath().getTestConfigurations().convention(testConfigurationsConvention);
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            final TaskProvider<GenerateEclipseClasspath> task = project.getTasks().register(ECLIPSE_CP_TASK_NAME, GenerateEclipseClasspath.class, model.getClasspath());
            task.configure(new Action<GenerateEclipseClasspath>() {

                @Override
                public void execute(final GenerateEclipseClasspath task) {
                    task.setDescription("Generates the Eclipse classpath file.");
                    task.setInputFile(project.file(".classpath"));
                    task.setOutputFile(project.file(".classpath"));
                }
            });
            addWorker(task, ECLIPSE_CP_TASK_NAME);
            XmlTransformer xmlTransformer = new XmlTransformer();
            xmlTransformer.setIndentation("\t");
            model.getClasspath().setFile(new XmlFileContentMerger(xmlTransformer));
            model.getClasspath().setSourceSets(project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets());
            AfterEvaluateHelper.afterEvaluateOrExecute(project, new Action<Project>() {

                @Override
                public void execute(Project p) {
                    // keep the ordering we had in earlier gradle versions
                    Set<String> containers = Sets.newLinkedHashSet();
                    containers.add("org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/" + model.getJdt().getJavaRuntimeName() + "/");
                    containers.addAll(model.getClasspath().getContainers());
                    model.getClasspath().setContainers(containers);
                }
            });
            configureScalaDependencies(project, model);
            configureJavaClasspath(project, task, model, testSourceSetsConvention, testConfigurationsConvention);
        }
    });
}
Also used : Action(org.gradle.api.Action) EclipseClasspath(org.gradle.plugins.ide.eclipse.model.EclipseClasspath) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) XmlTransformer(org.gradle.internal.xml.XmlTransformer) EclipseProject(org.gradle.plugins.ide.eclipse.model.EclipseProject) Project(org.gradle.api.Project) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) File(java.io.File) TaskProvider(org.gradle.api.tasks.TaskProvider)

Aggregations

TaskProvider (org.gradle.api.tasks.TaskProvider)28 Project (org.gradle.api.Project)25 Plugin (org.gradle.api.Plugin)23 TaskContainer (org.gradle.api.tasks.TaskContainer)18 Inject (javax.inject.Inject)17 ObjectFactory (org.gradle.api.model.ObjectFactory)14 Provider (org.gradle.api.provider.Provider)12 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)12 Task (org.gradle.api.Task)11 DirectoryProperty (org.gradle.api.file.DirectoryProperty)11 File (java.io.File)10 Configuration (org.gradle.api.artifacts.Configuration)10 Callable (java.util.concurrent.Callable)9 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)9 List (java.util.List)8 Action (org.gradle.api.Action)8 SourceSet (org.gradle.api.tasks.SourceSet)8 Names (org.gradle.language.nativeplatform.internal.Names)8 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)7 Set (java.util.Set)6