@@ -73,38 +73,63 @@ dependencies {
7373 codegen(libs.smithy.aws.protocol.tests)
7474}
7575
76+ abstract class ProtocolTestTask @Inject constructor(private val project : Project ) : DefaultTask() {
77+ /* *
78+ * The projection
79+ */
80+ @get:Input
81+ abstract val projectionName: Property <String >
82+
83+ /* *
84+ * The projection root directory
85+ */
86+ @get:Input
87+ abstract val projectionRootDirectory: Property <String >
88+
89+ @TaskAction
90+ fun runTests () {
91+ val projectionRootDir = project.file(projectionRootDirectory.get())
92+ println (" [$projectionName ] buildDir: $projectionRootDir " )
93+ if (! projectionRootDir.exists()) {
94+ throw GradleException (" $projectionRootDir does not exist" )
95+ }
96+ val wrapper = if (System .getProperty(" os.name" ).lowercase().contains(" windows" )) " gradlew.bat" else " gradlew"
97+ val gradlew = project.rootProject.file(wrapper).absolutePath
98+
99+ // NOTE - this still requires us to publish to maven local.
100+ project.exec {
101+ workingDir = projectionRootDir
102+ executable = gradlew
103+ args = listOf (" test" )
104+ }
105+ }
106+ }
107+
76108smithyBuild.projections.forEach {
77109 val protocolName = it.name
78110
79- val dirProvider = smithyBuild
80- .smithyKotlinProjectionPath(protocolName)
81- .map { file(it.toString()) }
111+ tasks.register<ProtocolTestTask >(" testProtocol-$protocolName " ) {
112+ dependsOn(tasks.generateSmithyProjections)
113+ group = " Verification"
114+ projectionName.set(it.name)
115+ projectionRootDirectory.set(smithyBuild.smithyKotlinProjectionPath(it.name).map { it.toString() })
116+ }
82117
118+ // FIXME This is a hack to work around how protocol tests aren't in the actual service model and thus codegen
119+ // separately from service customizations.
83120 val copyStaticFiles = tasks.register<Copy >(" copyStaticFiles-$protocolName " ) {
84121 group = " codegen"
85122 from(rootProject.projectDir.resolve(" services/$protocolName /common/src" ))
86- into(smithyBuild.smithyKotlinProjectionSrcDir(protocolName ))
123+ into(smithyBuild.smithyKotlinProjectionSrcDir(it.name ))
87124 }
88125
89- tasks.register<Exec >(" testProtocol-$protocolName " ) {
90- group = " Verification"
91- dependsOn(tasks.generateSmithyProjections, copyStaticFiles)
92-
93- doFirst {
94- val dir = dirProvider.get()
95- require(dir.exists()) { " $dir does not exist" }
96-
97- val wrapper = if (System .getProperty(" os.name" ).lowercase().contains(" windows" )) " gradlew.bat" else " gradlew"
98- val gradlew = rootProject.layout.projectDirectory.file(wrapper).asFile.absolutePath
99-
100- workingDir = dir
101- executable = gradlew
102- args = listOf (" test" )
103- }
126+ tasks.generateSmithyProjections.configure {
127+ finalizedBy(copyStaticFiles)
104128 }
105129}
106130
107131tasks.register(" testAllProtocols" ) {
108132 group = " Verification"
109- dependsOn(tasks.matching { it.name.startsWith(" testProtocol-" ) })
133+ val allTests = tasks.withType<ProtocolTestTask >()
134+ dependsOn(allTests)
110135}
0 commit comments