|
4 | 4 | */ |
5 | 5 | package aws.sdk.kotlin.codegen |
6 | 6 |
|
7 | | -import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait |
8 | | -import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait |
9 | | -import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList |
10 | 7 | import software.amazon.smithy.kotlin.codegen.core.* |
11 | 8 | import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration |
12 | | -import software.amazon.smithy.kotlin.codegen.model.expectShape |
13 | | -import software.amazon.smithy.kotlin.codegen.model.hasTrait |
14 | 9 | import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter |
15 | | -import software.amazon.smithy.kotlin.codegen.utils.topDownOperations |
16 | | -import software.amazon.smithy.model.shapes.ServiceShape |
17 | | -import software.amazon.smithy.smoketests.traits.SmokeTestsTrait |
18 | 10 |
|
19 | 11 | // TODO - would be nice to allow integrations to define custom settings in the plugin |
20 | 12 | // e.g. we could then more consistently apply this integration if we could define a property like: `build.isAwsSdk: true` |
@@ -72,72 +64,9 @@ class GradleGenerator : KotlinIntegration { |
72 | 64 | } |
73 | 65 | } |
74 | 66 | } |
75 | | - if (ctx.model.topDownOperations(ctx.settings.service).any { it.hasTrait<SmokeTestsTrait>() } && ctx.settings.sdkId !in smokeTestDenyList) { |
76 | | - write("") |
77 | | - generateSmokeTestConfig(writer, ctx) |
78 | | - } |
79 | 67 | } |
80 | 68 |
|
81 | 69 | val contents = writer.toString() |
82 | 70 | delegator.fileManifest.writeFile("build.gradle.kts", contents) |
83 | 71 | } |
84 | | - |
85 | | - private fun generateSmokeTestConfig(writer: GradleWriter, ctx: CodegenContext) { |
86 | | - generateSmokeTestJarTask(writer, ctx) |
87 | | - writer.write("") |
88 | | - generateSmokeTestTask(writer, ctx) |
89 | | - } |
90 | | - |
91 | | - /** |
92 | | - * Generates a gradle task to create smoke test runner JARs |
93 | | - */ |
94 | | - private fun generateSmokeTestJarTask(writer: GradleWriter, ctx: CodegenContext) { |
95 | | - writer.withBlock("jvm {", "}") { |
96 | | - withBlock("compilations {", "}") { |
97 | | - write("val mainPath = getByName(#S).output.classesDirs", "main") |
98 | | - write("val testPath = getByName(#S).output.classesDirs", "test") |
99 | | - withBlock("tasks {", "}") { |
100 | | - withBlock("register<Jar>(#S) {", "}", "smokeTestJar") { |
101 | | - write("description = #S", "Creates smoke tests jar") |
102 | | - write("group = #S", "application") |
103 | | - write("dependsOn(build)") |
104 | | - write("mustRunAfter(build)") |
105 | | - withBlock("manifest {", "}") { |
106 | | - write("attributes[#S] = #S", "Main-Class", "${ctx.settings.pkg.name}.smoketests.SmokeTestsKt") |
107 | | - } |
108 | | - write("val runtimePath = configurations.getByName(#S).map { if (it.isDirectory) it else zipTree(it) }", "jvmRuntimeClasspath") |
109 | | - write("duplicatesStrategy = DuplicatesStrategy.EXCLUDE") |
110 | | - write("from(runtimePath, mainPath, testPath)") |
111 | | - write("archiveBaseName.set(#S)", "\${project.name}-smoketests") |
112 | | - } |
113 | | - } |
114 | | - } |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Generates a gradle task to run smoke tests |
120 | | - */ |
121 | | - private fun generateSmokeTestTask(writer: GradleWriter, ctx: CodegenContext) { |
122 | | - val hasSuccessResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(TestSuccessResponseTrait.ID) |
123 | | - val hasFailedResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(TestFailedResponseTrait.ID) |
124 | | - val inTestingEnvironment = hasFailedResponseTrait || hasSuccessResponseTrait |
125 | | - |
126 | | - /** |
127 | | - * E2E tests don't have sdkVersion in jar names. They're added later for publishing. |
128 | | - * @see SmokeTestE2ETest |
129 | | - */ |
130 | | - val jarName = if (inTestingEnvironment) "\${project.name}-smoketests.jar" else "\${project.name}-smoketests-\$sdkVersion.jar" |
131 | | - |
132 | | - writer.withBlock("tasks.register<JavaExec>(#S) {", "}", "smokeTest") { |
133 | | - write("description = #S", "Runs smoke tests jar") |
134 | | - write("group = #S", "verification") |
135 | | - write("dependsOn(tasks.getByName(#S))", "smokeTestJar") |
136 | | - write("mustRunAfter(tasks.getByName(#S))", "smokeTestJar") |
137 | | - write("") |
138 | | - write("val sdkVersion: String by project") |
139 | | - write("val jarFile = file(#S)", "build/libs/$jarName") |
140 | | - write("classpath = files(jarFile)") |
141 | | - } |
142 | | - } |
143 | 72 | } |
0 commit comments