use of org.gradle.nativeplatform.internal.DefaultTargetMachineFactory in project gradle by gradle.
the class NativeTestingBasePlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
project.getPluginManager().apply(NativeBasePlugin.class);
project.getPluginManager().apply(TestingBasePlugin.class);
// Create test lifecycle task
TaskContainer tasks = project.getTasks();
final TaskProvider<Task> test = tasks.register(TEST_TASK_NAME, task -> task.dependsOn((Callable<Object>) () -> {
TestSuiteComponent unitTestSuite = project.getComponents().withType(TestSuiteComponent.class).findByName(TEST_COMPONENT_NAME);
if (unitTestSuite != null && unitTestSuite.getTestBinary().isPresent()) {
return unitTestSuite.getTestBinary().get().getRunTask();
}
return null;
}));
project.getComponents().withType(TestSuiteComponent.class, testSuiteComponent -> {
if (testSuiteComponent instanceof ComponentWithTargetMachines) {
ComponentWithTargetMachines componentWithTargetMachines = (ComponentWithTargetMachines) testSuiteComponent;
if (TEST_COMPONENT_NAME.equals(testSuiteComponent.getName())) {
test.configure(task -> task.dependsOn((Callable) () -> {
TargetMachine currentHost = ((DefaultTargetMachineFactory) targetMachineFactory).host();
boolean targetsCurrentMachine = componentWithTargetMachines.getTargetMachines().get().stream().anyMatch(targetMachine -> currentHost.getOperatingSystemFamily().equals(targetMachine.getOperatingSystemFamily()));
if (!targetsCurrentMachine) {
task.getLogger().warn("'" + testSuiteComponent.getName() + "' component in project '" + project.getPath() + "' does not target this operating system.");
}
return Collections.emptyList();
}));
}
}
});
tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME, task -> task.dependsOn(test));
}
use of org.gradle.nativeplatform.internal.DefaultTargetMachineFactory in project gradle by gradle.
the class NativeBasePlugin method addLifecycleTasks.
private void addLifecycleTasks(final Project project, final TaskContainer tasks, final SoftwareComponentContainer components) {
components.withType(ComponentWithBinaries.class, component -> {
// Register each child of each component
component.getBinaries().whenElementKnown(binary -> components.add(binary));
if (component instanceof ProductionComponent) {
// Add an assemble task for each binary and also wire the development binary in to the `assemble` task
component.getBinaries().whenElementFinalized(ComponentWithOutputs.class, binary -> {
// Determine which output to produce at development time.
final FileCollection outputs = binary.getOutputs();
Names names = ((ComponentWithNames) binary).getNames();
tasks.register(names.getTaskName("assemble"), task -> task.dependsOn(outputs));
if (binary == ((ProductionComponent) component).getDevelopmentBinary().get()) {
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> task.dependsOn(outputs));
}
});
}
if (component instanceof ComponentWithTargetMachines) {
ComponentWithTargetMachines componentWithTargetMachines = (ComponentWithTargetMachines) component;
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> {
task.dependsOn((Callable) () -> {
TargetMachine currentHost = ((DefaultTargetMachineFactory) targetMachineFactory).host();
boolean targetsCurrentMachine = componentWithTargetMachines.getTargetMachines().get().stream().anyMatch(targetMachine -> currentHost.getOperatingSystemFamily().equals(targetMachine.getOperatingSystemFamily()));
if (!targetsCurrentMachine) {
task.getLogger().warn("'" + component.getName() + "' component in project '" + project.getPath() + "' does not target this operating system.");
}
return Collections.emptyList();
});
});
}
});
}
Aggregations