use of org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite in project gradle by gradle.
the class XCTestConventionPlugin method apply.
@Override
public void apply(ProjectInternal project) {
project.getPluginManager().apply(SwiftBasePlugin.class);
project.getPluginManager().apply(NativeTestingBasePlugin.class);
// Create test suite component
final DefaultSwiftXCTestSuite testComponent = createTestSuite(project);
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(final Project project) {
String operatingSystemSuffix = "";
OperatingSystemFamily operatingSystem = objectFactory.named(OperatingSystemFamily.class, DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName());
Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
Provider<String> group = project.provider(new Callable<String>() {
@Override
public String call() throws Exception {
return project.getGroup().toString();
}
});
Provider<String> version = project.provider(new Callable<String>() {
@Override
public String call() throws Exception {
return project.getVersion().toString();
}
});
AttributeContainer attributesDebug = attributesFactory.mutable();
attributesDebug.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
attributesDebug.attribute(DEBUGGABLE_ATTRIBUTE, true);
attributesDebug.attribute(OPTIMIZED_ATTRIBUTE, false);
NativeVariantIdentity debugVariant = new NativeVariantIdentity("debug" + operatingSystemSuffix, testComponent.getModule(), group, version, true, false, operatingSystem, null, new DefaultUsageContext("debug" + operatingSystemSuffix + "-runtime", runtimeUsage, attributesDebug));
ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class);
// Create test suite executable
DefaultSwiftXCTestBinary binary;
if (result.getTargetPlatform().getOperatingSystem().isMacOsX()) {
binary = (DefaultSwiftXCTestBinary) testComponent.addBundle("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
} else {
binary = (DefaultSwiftXCTestBinary) testComponent.addExecutable("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
testComponent.getTestBinary().set(binary);
// TODO: Publishing for test executable?
final ProductionSwiftComponent mainComponent = project.getComponents().withType(ProductionSwiftComponent.class).findByName("main");
if (mainComponent != null) {
testComponent.getTestedComponent().set(mainComponent);
// Test configuration extends main configuration
testComponent.getImplementationDependencies().extendsFrom(mainComponent.getImplementationDependencies());
project.getDependencies().add(binary.getImportPathConfiguration().getName(), project);
}
testComponent.getBinaries().whenElementKnown(DefaultSwiftXCTestBinary.class, new Action<DefaultSwiftXCTestBinary>() {
@Override
public void execute(DefaultSwiftXCTestBinary binary) {
// Create test suite test task
XCTest testingTask = createTestingTask(project);
binary.getRunTask().set(testingTask);
// Configure tasks
configureTestingTask(binary, testingTask);
configureTestSuiteBuildingTasks((ProjectInternal) project, binary);
configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
}
});
testComponent.getBinaries().realizeNow();
}
});
}
use of org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite in project gradle by gradle.
the class XCTestConventionPlugin method createTestSuite.
private DefaultSwiftXCTestSuite createTestSuite(final Project project) {
// 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"));
return testSuite;
}
Aggregations