Search in sources :

Example 1 with TestSuiteComponent

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);
}
Also used : Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) TestSuiteComponent(org.gradle.nativeplatform.test.TestSuiteComponent)

Example 2 with TestSuiteComponent

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));
}
Also used : Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) ComponentWithTargetMachines(org.gradle.language.ComponentWithTargetMachines) TargetMachine(org.gradle.nativeplatform.TargetMachine) Callable(java.util.concurrent.Callable) TestSuiteComponent(org.gradle.nativeplatform.test.TestSuiteComponent) DefaultTargetMachineFactory(org.gradle.nativeplatform.internal.DefaultTargetMachineFactory)

Aggregations

Task (org.gradle.api.Task)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 TestSuiteComponent (org.gradle.nativeplatform.test.TestSuiteComponent)2 Callable (java.util.concurrent.Callable)1 ComponentWithTargetMachines (org.gradle.language.ComponentWithTargetMachines)1 TargetMachine (org.gradle.nativeplatform.TargetMachine)1 DefaultTargetMachineFactory (org.gradle.nativeplatform.internal.DefaultTargetMachineFactory)1