Search in sources :

Example 16 with TaskProvider

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

the class EarPlugin method setupEarTask.

private void setupEarTask(final Project project, EarPluginConvention convention, PluginContainer plugins) {
    TaskProvider<Ear> ear = project.getTasks().register(EAR_TASK_NAME, Ear.class, new Action<Ear>() {

        @Override
        public void execute(Ear ear) {
            ear.setDescription("Generates a ear archive with all the modules, the application descriptor and the libraries.");
            ear.setGroup(BasePlugin.BUILD_GROUP);
            ear.getGenerateDeploymentDescriptor().convention(convention.getGenerateDeploymentDescriptor());
            plugins.withType(JavaPlugin.class, javaPlugin -> {
                final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
                SourceSet sourceSet = mainSourceSetOf(javaPluginExtension);
                sourceSet.getResources().srcDir(ear.getAppDirectory());
            });
        }
    });
    DeploymentDescriptor deploymentDescriptor = convention.getDeploymentDescriptor();
    if (deploymentDescriptor != null) {
        if (deploymentDescriptor.getDisplayName() == null) {
            deploymentDescriptor.setDisplayName(project.getName());
        }
        if (deploymentDescriptor.getDescription() == null) {
            deploymentDescriptor.setDescription(project.getDescription());
        }
    }
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(new LazyPublishArtifact(ear, ((ProjectInternal) project).getFileResolver()));
    project.getTasks().withType(Ear.class).configureEach(new Action<Ear>() {

        @Override
        public void execute(Ear task) {
        }
    });
}
Also used : LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) Action(org.gradle.api.Action) Project(org.gradle.api.Project) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Callable(java.util.concurrent.Callable) BasePlugin(org.gradle.api.plugins.BasePlugin) FileCollection(org.gradle.api.file.FileCollection) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) ObjectFactory(org.gradle.api.model.ObjectFactory) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) PluginContainer(org.gradle.api.plugins.PluginContainer) DeploymentDescriptor(org.gradle.plugins.ear.descriptor.DeploymentDescriptor) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) SourceSet(org.gradle.api.tasks.SourceSet) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) DeploymentDescriptor(org.gradle.plugins.ear.descriptor.DeploymentDescriptor) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) JavaPlugin(org.gradle.api.plugins.JavaPlugin) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension)

Example 17 with TaskProvider

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

the class GroovyBasePlugin method configureSourceSetDefaults.

@SuppressWarnings("deprecation")
private void configureSourceSetDefaults() {
    javaPluginExtension().getSourceSets().all(sourceSet -> {
        final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet("groovy", ((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
        addSourceSetExtension(sourceSet, groovySourceSet);
        final SourceDirectorySet groovySource = groovySourceSet.getGroovy();
        groovySource.srcDir("src/" + sourceSet.getName() + "/groovy");
        // Explicitly capture only a FileCollection in the lambda below for compatibility with configuration-cache.
        @SuppressWarnings("UnnecessaryLocalVariable") final FileCollection groovySourceFiles = groovySource;
        sourceSet.getResources().getFilter().exclude(spec(element -> groovySourceFiles.contains(element.getFile())));
        sourceSet.getAllJava().source(groovySource);
        sourceSet.getAllSource().source(groovySource);
        final TaskProvider<GroovyCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, compile -> {
            JvmPluginsHelper.configureForSourceSet(sourceSet, groovySource, compile, compile.getOptions(), project);
            compile.setDescription("Compiles the " + sourceSet.getName() + " Groovy source.");
            compile.setSource(groovySource);
            compile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
            compile.getGroovyOptions().getDisabledGlobalASTTransformations().convention(Sets.newHashSet("groovy.grape.GrabAnnotationTransformation"));
        });
        String compileClasspathConfigurationName = sourceSet.getCompileClasspathConfigurationName();
        JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, groovySource, project, compileTask, compileTask.map(GroovyCompile::getOptions));
        useDefaultTargetPlatformInference(compileTask, compileClasspathConfigurationName);
        useDefaultTargetPlatformInference(compileTask, sourceSet.getRuntimeClasspathConfigurationName());
        // TODO: `classes` should be a little more tied to the classesDirs for a SourceSet so every plugin
        // doesn't need to do this.
        project.getTasks().named(sourceSet.getClassesTaskName(), task -> task.dependsOn(compileTask));
        // Explain that Groovy, for compile, also needs the resources (#9872)
        project.getConfigurations().getByName(compileClasspathConfigurationName).attributes(attrs -> attrs.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.getObjects().named(LibraryElements.class, LibraryElements.CLASSES_AND_RESOURCES)));
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) Groovydoc(org.gradle.api.tasks.javadoc.Groovydoc) BiFunction(java.util.function.BiFunction) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) FileCollection(org.gradle.api.file.FileCollection) LibraryElements(org.gradle.api.attributes.LibraryElements) DslObject(org.gradle.api.internal.plugins.DslObject) Inject(javax.inject.Inject) Provider(org.gradle.api.provider.Provider) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) TaskProvider(org.gradle.api.tasks.TaskProvider) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) GroovyRuntime(org.gradle.api.tasks.GroovyRuntime) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) Sets(com.google.common.collect.Sets) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) ObjectFactory(org.gradle.api.model.ObjectFactory) SerializableLambdas.spec(org.gradle.api.internal.lambdas.SerializableLambdas.spec) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) Plugin(org.gradle.api.Plugin) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) FileCollection(org.gradle.api.file.FileCollection)

Example 18 with TaskProvider

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

the class CppUnitTestPlugin method configureTestSuiteWithTestedComponentWhenAvailable.

private void configureTestSuiteWithTestedComponentWhenAvailable(Project project, DefaultCppTestSuite testSuite, DefaultCppTestExecutable testExecutable) {
    CppComponent target = testSuite.getTestedComponent().getOrNull();
    if (!(target instanceof ProductionCppComponent)) {
        return;
    }
    final ProductionCppComponent testedComponent = (ProductionCppComponent) target;
    final TaskContainer tasks = project.getTasks();
    testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
        if (!isTestedBinary(testExecutable, testedComponent, testedBinary)) {
            return;
        }
        // TODO - move this to a base plugin
        // Setup the dependency on the main binary
        // This should all be replaced by a single dependency that points at some "testable" variants of the main binary
        // Inherit implementation dependencies
        testExecutable.getImplementationDependencies().extendsFrom(((DefaultCppBinary) testedBinary).getImplementationDependencies());
        // Configure test binary to link against tested component compiled objects
        ConfigurableFileCollection testableObjects = project.files();
        if (target instanceof CppApplication) {
            // TODO - this should be an outgoing variant of the component under test
            TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register(testExecutable.getNames().getTaskName("relocateMainFor"), UnexportMainSymbol.class, task -> {
                String dirName = ((DefaultCppBinary) testedBinary).getNames().getDirName();
                task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
                task.getObjects().from(testedBinary.getObjects());
            });
            testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
        } else {
            testableObjects.from(testedBinary.getObjects());
        }
        Dependency linkDependency = project.getDependencies().create(testableObjects);
        testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) DefaultCppTestSuite(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestSuite) Callable(java.util.concurrent.Callable) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) CppPlatform(org.gradle.language.cpp.CppPlatform) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) CppComponent(org.gradle.language.cpp.CppComponent) CppApplication(org.gradle.language.cpp.CppApplication) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) DefaultCppTestExecutable(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestExecutable) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) CppTestSuite(org.gradle.nativeplatform.test.cpp.CppTestSuite) CppTestExecutable(org.gradle.nativeplatform.test.cpp.CppTestExecutable) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) Stream(java.util.stream.Stream) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) CppBinary(org.gradle.language.cpp.CppBinary) CppBasePlugin(org.gradle.language.cpp.plugins.CppBasePlugin) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) RunTestExecutable(org.gradle.nativeplatform.test.tasks.RunTestExecutable) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) TaskContainer(org.gradle.api.tasks.TaskContainer) CppComponent(org.gradle.language.cpp.CppComponent) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) CppApplication(org.gradle.language.cpp.CppApplication) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent)

Example 19 with TaskProvider

use of org.gradle.api.tasks.TaskProvider in project spring-boot by spring-projects.

the class JavaPluginAction method configureBootJarTask.

private TaskProvider<BootJar> configureBootJarTask(Project project) {
    SourceSet mainSourceSet = javaPluginExtension(project).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
    Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    Callable<FileCollection> classpath = () -> mainSourceSet.getRuntimeClasspath().minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
    TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_JAR_TASK_NAME, project, classpath);
    return project.getTasks().register(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class, (bootJar) -> {
        bootJar.setDescription("Assembles an executable jar archive containing the main classes and their dependencies.");
        bootJar.setGroup(BasePlugin.BUILD_GROUP);
        bootJar.classpath(classpath);
        Provider<String> manifestStartClass = project.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
        bootJar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
    });
}
Also used : BootRun(org.springframework.boot.gradle.tasks.run.BootRun) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) Callable(java.util.concurrent.Callable) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) FileCollection(org.gradle.api.file.FileCollection) ApplicationPlugin(org.gradle.api.plugins.ApplicationPlugin) LibraryElements(org.gradle.api.attributes.LibraryElements) SourceSet(org.gradle.api.tasks.SourceSet) BootBuildImage(org.springframework.boot.gradle.tasks.bundling.BootBuildImage) Bundling(org.gradle.api.attributes.Bundling) Configuration(org.gradle.api.artifacts.Configuration) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) AttributeContainer(org.gradle.api.attributes.AttributeContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) BootJar(org.springframework.boot.gradle.tasks.bundling.BootJar) Usage(org.gradle.api.attributes.Usage) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Set(java.util.Set) File(java.io.File) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) List(java.util.List) ObjectFactory(org.gradle.api.model.ObjectFactory) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) StringUtils(org.springframework.util.StringUtils) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) FileCollection(org.gradle.api.file.FileCollection)

Example 20 with TaskProvider

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

the class SwiftBasePlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(SwiftCompilerPlugin.class);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE).getCompatibilityRules().add(SwiftCppUsageCompatibilityRule.class);
    project.getComponents().withType(DefaultSwiftBinary.class, binary -> {
        final Names names = binary.getNames();
        TaskProvider<SwiftCompile> compile = tasks.register(names.getCompileTaskName("swift"), SwiftCompile.class, task -> {
            task.getModules().from(binary.getCompileModules());
            task.getSource().from(binary.getSwiftSource());
            task.getDebuggable().set(binary.isDebuggable());
            task.getOptimized().set(binary.isOptimized());
            if (binary.isTestable()) {
                task.getCompilerArgs().add("-enable-testing");
            }
            if (binary.getTargetMachine().getOperatingSystemFamily().isMacOs()) {
                task.getCompilerArgs().add("-sdk");
                task.getCompilerArgs().add(locator.find().getAbsolutePath());
            }
            task.getModuleName().set(binary.getModule());
            task.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            task.getModuleFile().set(buildDirectory.file(binary.getModule().map(moduleName -> "modules/" + names.getDirName() + moduleName + ".swiftmodule")));
            task.getSourceCompatibility().set(binary.getTargetPlatform().getSourceCompatibility());
            task.getTargetPlatform().set(binary.getNativePlatform());
            // TODO - make this lazy
            task.getToolChain().set(binary.getToolChain());
            if (binary instanceof SwiftSharedLibrary || binary instanceof SwiftStaticLibrary) {
                task.getCompilerArgs().add("-parse-as-library");
            }
        });
        binary.getModuleFile().set(compile.flatMap(task -> task.getModuleFile()));
        binary.getCompileTask().set(compile);
        binary.getObjectsDir().set(compile.flatMap(task -> task.getObjectFileDir()));
    });
    project.getComponents().withType(ProductionSwiftComponent.class, component -> {
        project.afterEvaluate(p -> {
            DefaultNativeComponent componentInternal = (DefaultNativeComponent) component;
            publicationRegistry.registerPublication((ProjectInternal) project, new NativeProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getModule().get())));
        });
    });
}
Also used : Names(org.gradle.language.nativeplatform.internal.Names) DefaultNativeComponent(org.gradle.language.nativeplatform.internal.DefaultNativeComponent) ProjectPublicationRegistry(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry) Project(org.gradle.api.Project) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) NativeBasePlugin(org.gradle.language.plugins.NativeBasePlugin) SwiftCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.SwiftCompilerPlugin) Inject(javax.inject.Inject) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) TaskContainer(org.gradle.api.tasks.TaskContainer) AttributeCompatibilityRule(org.gradle.api.attributes.AttributeCompatibilityRule) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) CompatibilityCheckDetails(org.gradle.api.attributes.CompatibilityCheckDetails) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) Names(org.gradle.language.nativeplatform.internal.Names) MacOSSdkPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPathLocator) Plugin(org.gradle.api.Plugin) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) Usage(org.gradle.api.attributes.Usage) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) DefaultNativeComponent(org.gradle.language.nativeplatform.internal.DefaultNativeComponent) NativeProjectPublication(org.gradle.swiftpm.internal.NativeProjectPublication) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget)

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