Search in sources :

Example 11 with TaskProvider

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

the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.

private void configureTestSuiteBuildingTasks(final Project project, final DefaultSwiftXCTestBinary binary) {
    // Overwrite the source to exclude `LinuxMain.swift`
    SwiftCompile compile = binary.getCompileTask().get();
    compile.getSource().setFrom(binary.getSwiftSource().getAsFileTree().matching(patterns -> patterns.include("**/*").exclude("**/LinuxMain.swift")));
    if (binary instanceof SwiftXCTestBundle) {
        TaskContainer tasks = project.getTasks();
        final Names names = binary.getNames();
        // TODO - creating a bundle should be done by some general purpose plugin
        // TODO - make this lazy
        final DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
        final ModelRegistry modelRegistry = ((ProjectInternal) project).getModelRegistry();
        final NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
        // Platform specific arguments
        // TODO: Need to lazily configure compile task
        // TODO: Ultimately, this should be some kind of 3rd party dependency that's visible to dependency management.
        compile.getCompilerArgs().addAll(project.provider(() -> {
            File platformSdkPath = sdkPlatformPathLocator.find();
            File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
            // Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
            File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
            return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath(), "-I", extraInclude.getAbsolutePath(), "-v");
        }));
        // Add a link task
        final TaskProvider<LinkMachOBundle> link = tasks.register(names.getTaskName("link"), LinkMachOBundle.class, task -> {
            task.getLinkerArgs().set(project.provider(() -> {
                File platformSdkPath = sdkPlatformPathLocator.find();
                File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
                // Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
                File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
                return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-L", extraInclude.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
            }));
            task.source(binary.getObjects());
            task.lib(binary.getLinkLibraries());
            final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
            Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(binary.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName)));
            task.getLinkedFile().set(exeLocation);
            task.getTargetPlatform().set(currentPlatform);
            task.getToolChain().set(toolChain);
            task.getDebuggable().set(binary.isDebuggable());
        });
        final TaskProvider<InstallXCTestBundle> install = tasks.register(names.getTaskName("install"), InstallXCTestBundle.class, task -> {
            task.getBundleBinaryFile().set(link.get().getLinkedFile());
            task.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
        });
        binary.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
        binary.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
        DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
        bundle.getLinkTask().set(link);
        bundle.getRunScriptFile().set(install.flatMap(task -> task.getRunScriptFile()));
    } else {
        DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
        executable.getRunScriptFile().set(executable.getInstallTask().flatMap(task -> task.getRunScriptFile()));
        // Rename `LinuxMain.swift` to `main.swift` so the entry point is correctly detected by swiftc
        if (binary.getTargetMachine().getOperatingSystemFamily().isLinux()) {
            TaskProvider<Sync> renameLinuxMainTask = project.getTasks().register("renameLinuxMain", Sync.class, task -> {
                task.from(binary.getSwiftSource());
                task.into(project.provider(() -> task.getTemporaryDir()));
                task.include("LinuxMain.swift");
                task.rename(it -> "main.swift");
            });
            compile.getSource().from(project.files(renameLinuxMainTask).getAsFileTree().matching(patterns -> patterns.include("**/*.swift")));
        }
    }
}
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) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) RegularFile(org.gradle.api.file.RegularFile) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Names(org.gradle.language.nativeplatform.internal.Names) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) TaskContainer(org.gradle.api.tasks.TaskContainer) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Sync(org.gradle.api.tasks.Sync) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 12 with TaskProvider

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

the class XCTestConventionPlugin method configureTestSuiteWithTestedComponentWhenAvailable.

private void configureTestSuiteWithTestedComponentWhenAvailable(final Project project, final DefaultSwiftXCTestSuite testSuite, final DefaultSwiftXCTestBinary testExecutable) {
    SwiftComponent target = testSuite.getTestedComponent().getOrNull();
    if (!(target instanceof ProductionSwiftComponent)) {
        return;
    }
    final ProductionSwiftComponent testedComponent = (ProductionSwiftComponent) target;
    final TaskContainer tasks = project.getTasks();
    testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
        if (testedBinary != testedComponent.getDevelopmentBinary().get()) {
            return;
        }
        // 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(((DefaultSwiftBinary) testedBinary).getImplementationDependencies());
        // Configure test binary to compile against binary under test
        Dependency compileDependency = project.getDependencies().create(project.files(testedBinary.getModuleFile()));
        testExecutable.getImportPathConfiguration().getDependencies().add(compileDependency);
        // Configure test binary to link against tested component compiled objects
        ConfigurableFileCollection testableObjects = project.files();
        if (testedComponent instanceof SwiftApplication) {
            TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register("relocateMainForTest", UnexportMainSymbol.class, task -> {
                String dirName = ((DefaultSwiftBinary) 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) 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) TaskContainer(org.gradle.api.tasks.TaskContainer) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftComponent(org.gradle.language.swift.SwiftComponent) SwiftApplication(org.gradle.language.swift.SwiftApplication)

Example 13 with TaskProvider

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

the class JacocoPlugin method addDefaultReportTask.

private void addDefaultReportTask(final JacocoPluginExtension extension, final TaskProvider<? extends Task> testTaskProvider) {
    final String testTaskName = testTaskProvider.getName();
    project.getTasks().register("jacoco" + StringUtils.capitalize(testTaskName) + "Report", JacocoReport.class, reportTask -> {
        reportTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        reportTask.setDescription(String.format("Generates code coverage report for the %s task.", testTaskName));
        reportTask.executionData(testTaskProvider.get());
        reportTask.sourceSets(project.getExtensions().getByType(SourceSetContainer.class).getByName("main"));
        // TODO: Change the default location for these reports to follow the convention defined in ReportOutputDirectoryAction
        DirectoryProperty reportsDir = extension.getReportsDirectory();
        reportTask.getReports().all(action(report -> {
            // https://github.com/gradle/gradle/issues/6343
            if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                ((DirectoryReport) report).getOutputLocation().convention(reportsDir.dir(testTaskName + "/" + report.getName()));
            } else {
                ((SingleFileReport) report).getOutputLocation().convention(reportsDir.file(testTaskName + "/" + reportTask.getName() + "." + report.getName()));
            }
        }));
    });
}
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) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DirectoryReport(org.gradle.api.reporting.DirectoryReport) SingleFileReport(org.gradle.api.reporting.SingleFileReport)

Example 14 with TaskProvider

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

the class PrecompiledGroovyPluginsPlugin method exposeScriptsAsPlugins.

private void exposeScriptsAsPlugins(Project project) {
    GradlePluginDevelopmentExtension pluginExtension = project.getExtensions().getByType(GradlePluginDevelopmentExtension.class);
    SourceSet pluginSourceSet = pluginExtension.getPluginSourceSet();
    FileTree scriptPluginFiles = pluginSourceSet.getAllSource().matching(PrecompiledGroovyScript::filterPluginFiles);
    List<PrecompiledGroovyScript> scriptPlugins = scriptPluginFiles.getFiles().stream().map(file -> new PrecompiledGroovyScript(file, getTextFileResourceLoader())).peek(scriptPlugin -> validateScriptPlugin(project, scriptPlugin)).collect(Collectors.toList());
    declarePluginMetadata(pluginExtension, scriptPlugins);
    DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
    TaskContainer tasks = project.getTasks();
    TaskProvider<ExtractPluginRequestsTask> extractPluginRequests = tasks.register("extractPluginRequests", ExtractPluginRequestsTask.class, task -> {
        task.getScriptPlugins().convention(scriptPlugins);
        task.getScriptFiles().from(scriptPluginFiles.getFiles());
        task.getExtractedPluginRequestsClassesDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-requests"));
        task.getExtractedPluginRequestsClassesStagingDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-requests-staging"));
    });
    TaskProvider<GeneratePluginAdaptersTask> generatePluginAdapters = tasks.register("generatePluginAdapters", GeneratePluginAdaptersTask.class, task -> {
        task.getScriptPlugins().convention(scriptPlugins);
        task.getExtractedPluginRequestsClassesDirectory().convention(extractPluginRequests.flatMap(ExtractPluginRequestsTask::getExtractedPluginRequestsClassesDirectory));
        task.getPluginAdapterSourcesOutputDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/adapter-src"));
    });
    TaskProvider<CompileGroovyScriptPluginsTask> precompilePlugins = tasks.register("compileGroovyPlugins", CompileGroovyScriptPluginsTask.class, task -> {
        task.getScriptPlugins().convention(scriptPlugins);
        task.getScriptFiles().from(scriptPluginFiles.getFiles());
        task.getPrecompiledGroovyScriptsOutputDirectory().convention(buildDir.dir("groovy-dsl-plugins/output/plugin-classes"));
        SourceDirectorySet javaSource = pluginSourceSet.getJava();
        SourceDirectorySet groovySource = pluginSourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
        task.getClasspath().from(pluginSourceSet.getCompileClasspath(), javaSource.getClassesDirectory(), groovySource.getClassesDirectory());
    });
    pluginSourceSet.getJava().srcDir(generatePluginAdapters.flatMap(GeneratePluginAdaptersTask::getPluginAdapterSourcesOutputDirectory));
    pluginSourceSet.getOutput().dir(precompilePlugins.flatMap(CompileGroovyScriptPluginsTask::getPrecompiledGroovyScriptsOutputDirectory));
    pluginSourceSet.getOutput().dir(extractPluginRequests.flatMap(ExtractPluginRequestsTask::getExtractedPluginRequestsClassesStagingDirectory));
}
Also used : CORE_PLUGIN_PREFIX(org.gradle.api.internal.plugins.DefaultPluginManager.CORE_PLUGIN_PREFIX) Project(org.gradle.api.Project) JavaGradlePluginPlugin(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) CORE_PLUGIN_NAMESPACE(org.gradle.api.internal.plugins.DefaultPluginManager.CORE_PLUGIN_NAMESPACE) TextFileResourceLoader(org.gradle.internal.resource.TextFileResourceLoader) GradlePluginDevelopmentExtension(org.gradle.plugin.devel.GradlePluginDevelopmentExtension) Collectors(java.util.stream.Collectors) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) List(java.util.List) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) TaskContainer(org.gradle.api.tasks.TaskContainer) GradleException(org.gradle.api.GradleException) FileTree(org.gradle.api.file.FileTree) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Documentation(org.gradle.internal.deprecation.Documentation) Plugin(org.gradle.api.Plugin) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryProperty(org.gradle.api.file.DirectoryProperty) TaskContainer(org.gradle.api.tasks.TaskContainer) GradlePluginDevelopmentExtension(org.gradle.plugin.devel.GradlePluginDevelopmentExtension) FileTree(org.gradle.api.file.FileTree) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet)

Example 15 with TaskProvider

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

the class ExternalPluginValidationPlugin method configurePluginValidation.

private void configurePluginValidation(Project project, TaskProvider<Task> lifecycleTask, PluginRegistry registry, Map<String, List<File>> jarsByPlugin, Plugin<?> plugin) {
    Class<?> pluginClass = plugin.getClass();
    if (isExternal(pluginClass)) {
        Optional<PluginId> pluginForClass = registry.findPluginForClass(pluginClass);
        String pluginId;
        pluginId = pluginForClass.map(PluginId::getId).orElseGet(() -> computePluginName(plugin));
        File pluginJar = findPluginJar(pluginClass);
        if (pluginJar != null) {
            jarsByPlugin.computeIfAbsent(pluginId, firstSeenPlugin -> registerValidationTaskForNewPlugin(firstSeenPlugin, project, lifecycleTask)).add(pluginJar);
        } else {
            LOGGER.warn("Validation won't be performed for plugin '{}' because we couldn't locate its jar file", pluginId);
        }
    }
}
Also used : PluginId(org.gradle.plugin.use.PluginId) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Logger(org.gradle.api.logging.Logger) Inject(javax.inject.Inject) Task(org.gradle.api.Task) Lists(com.google.common.collect.Lists) FileTree(org.gradle.api.file.FileTree) TaskProvider(org.gradle.api.tasks.TaskProvider) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Map(java.util.Map) FileOperations(org.gradle.api.internal.file.FileOperations) Incubating(org.gradle.api.Incubating) Nullable(javax.annotation.Nullable) ValidatePlugins(org.gradle.plugin.devel.tasks.ValidatePlugins) PluginRegistry(org.gradle.api.internal.plugins.PluginRegistry) Project(org.gradle.api.Project) VALIDATE_PLUGIN_TASK_DESCRIPTION(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin.VALIDATE_PLUGIN_TASK_DESCRIPTION) PLUGIN_DEVELOPMENT_GROUP(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin.PLUGIN_DEVELOPMENT_GROUP) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) File(java.io.File) ScriptHandlerInternal(org.gradle.api.internal.initialization.ScriptHandlerInternal) List(java.util.List) Logging(org.gradle.api.logging.Logging) CacheableTask(org.gradle.api.tasks.CacheableTask) Optional(java.util.Optional) Plugin(org.gradle.api.Plugin) PluginId(org.gradle.plugin.use.PluginId) File(java.io.File)

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