@@ -25,15 +25,45 @@ dependencies {
2525 implementation(project(" :smithy-aws-swift-codegen" ))
2626}
2727
28+ val enabledProtocols = listOf (
29+ ProtocolTest (" ec2-query" , " aws.protocoltests.ec2#AwsEc2" , " Ec2QueryTestSDK" ),
30+ ProtocolTest (" aws-json-10" , " aws.protocoltests.json10#JsonRpc10" , " AWSJson1_0TestSDK" ),
31+ ProtocolTest (" aws-json-11" , " aws.protocoltests.json#JsonProtocol" , " AWSJson1_1TestSDK" ),
32+ ProtocolTest (" aws-restjson" , " aws.protocoltests.restjson#RestJson" , " AWSRestJsonTestSDK" ),
33+ ProtocolTest (" rest-xml" , " aws.protocoltests.restxml#RestXml" , " RestXmlTestSDK" ),
34+ // ProtocolTest("rest-xml-xmlns", "aws.protocoltests.restxml.xmlns#RestXmlWithNamespace", "RestXmlWithNamespaceTestSDK"),
35+ ProtocolTest (" aws-query" , " aws.protocoltests.query#AwsQuery" , " AWSQueryTestSDK" )
36+
37+ // service specific tests
38+ // ProtocolTest("apigateway", "com.amazonaws.apigateway#BackplaneControlService"),
39+ // ProtocolTest("glacier", "com.amazonaws.glacier#Glacier")
40+ )
41+
2842// This project doesn't produce a JAR.
2943tasks[" jar" ].enabled = false
3044
3145// Run the SmithyBuild task manually since this project needs the built JAR
3246// from smithy-aws-swift-codegen.
3347tasks[" smithyBuildJar" ].enabled = false
3448
49+ task(" generateSmithyBuild" ) {
50+ group = " codegen"
51+ description = " generate smithy-build.json"
52+ val buildFile = projectDir.resolve(" smithy-build.json" )
53+ doFirst {
54+ buildFile.writeText(generateSmithyBuild(enabledProtocols))
55+ }
56+ outputs.file(buildFile)
57+ }
58+
59+ tasks[" clean" ].doFirst {
60+ delete(" smithy-build.json" )
61+ }
62+
3563tasks.create<SmithyBuild >(" buildSdk" ) {
3664 addRuntimeClasspath = true
65+ dependsOn(tasks[" generateSmithyBuild" ])
66+ inputs.file(projectDir.resolve(" smithy-build.json" ))
3767}
3868
3969// Run the `buildSdk` automatically.
@@ -42,19 +72,60 @@ tasks["build"].finalizedBy(tasks["buildSdk"])
4272// force rebuild every time while developing
4373tasks[" buildSdk" ].outputs.upToDateWhen { false }
4474
45- // The following section exposes Smithy protocol test suites as gradle test targets
46- // for the configured protocols in [enabledProtocols].
47- val enabledProtocols = listOf (" aws-json-10" , " aws-json-11" , " aws-restjson" , " rest-xml" , " aws-query" , " ec2-query" )
48-
4975enabledProtocols.forEach {
50- tasks.register<ProtocolTestTask >(" testProtocol-${it} " ) {
76+ tasks.register<ProtocolTestTask >(" testProtocol-${it.projectionName } " ) {
5177 dependsOn(tasks.build)
5278 group = " Verification"
53- protocol = it
79+ protocol = it.projectionName
5480 plugin = " swift-codegen"
5581 }
5682}
5783
84+
85+ data class ProtocolTest (val projectionName : String ,
86+ val serviceShapeId : String ,
87+ val moduleName : String ) {
88+ val packageName: String
89+ get() = projectionName.toLowerCase().filter { it.isLetterOrDigit() }
90+ }
91+ fun generateSmithyBuild (tests : List <ProtocolTest >): String {
92+ val projections = tests.joinToString(" ," ) { test ->
93+ """
94+ "${test.projectionName} ": {
95+ "transforms": [
96+ {
97+ "name": "includeServices",
98+ "args": {
99+ "services": [
100+ "${test.serviceShapeId} "
101+ ]
102+ }
103+ }
104+ ],
105+ "plugins": {
106+ "swift-codegen": {
107+ "service": "${test.serviceShapeId} ",
108+ "module": "${test.moduleName} ",
109+ "moduleVersion": "1.0",
110+ "gitRepo": "https://github.com/aws-amplify/smithy-swift.git",
111+ "author": "Amazon Web Services",
112+ "homepage": "https://docs.amplify.aws/",
113+ "swiftVersion": "5.4.0",
114+ "shouldGenerateUnitTestTarget": true
115+ }
116+ }
117+ }"""
118+ }
119+ return """
120+ {
121+ "version": "1.0",
122+ "projections": {
123+ $projections
124+ }
125+ }
126+ """ .trimIndent()
127+ }
128+
58129tasks.register(" testAllProtocols" ) {
59130 group = " Verification"
60131 val allTests = tasks.withType<ProtocolTestTask >()
0 commit comments