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