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