use of org.gradle.nativeplatform.test.TestSuiteComponent in project gradle by gradle.
the class NativeTestingBasePlugin method apply.
@Override
public void apply(final ProjectInternal project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
project.getPluginManager().apply(NativeBasePlugin.class);
project.getPluginManager().apply(TestingBasePlugin.class);
// Create test lifecycle task
TaskContainer tasks = project.getTasks();
Task test = tasks.create("test");
test.dependsOn(new Callable<Object>() {
@Override
public Object call() {
TestSuiteComponent unitTestSuite = project.getComponents().withType(TestSuiteComponent.class).findByName("test");
if (unitTestSuite != null && unitTestSuite.getTestBinary().isPresent()) {
return unitTestSuite.getTestBinary().get().getRunTask().get();
}
return null;
}
});
tasks.getByName(LifecycleBasePlugin.CHECK_TASK_NAME).dependsOn(test);
}
use of org.gradle.nativeplatform.test.TestSuiteComponent 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));
}
Aggregations