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")));
}
}
}
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);
});
}
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()));
}
}));
});
}
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));
}
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);
}
}
}
Aggregations