From 651736d345fbcbcf85513ac92d406f6b5fd7d8b2 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 12 Nov 2024 13:43:03 +0100 Subject: [PATCH] Build GrpcTestApps without polluting grpc-client Tmp --- GrpcClientTestApp/build.gradle.kts | 38 +++++++++++++++++++ GrpcServerTestApp/build.gradle.kts | 38 +++++++++++++++++++ grpc-client/build.gradle.kts | 26 +++++++------ .../src/main => test}/proto/Door.proto | 0 .../main => test}/proto/FoldingService.proto | 0 .../proto/FronthousingService.proto | 0 .../resources/VehicleService.json | 0 7 files changed, 90 insertions(+), 12 deletions(-) rename {grpc-client/src/main => test}/proto/Door.proto (100%) rename {grpc-client/src/main => test}/proto/FoldingService.proto (100%) rename {grpc-client/src/main => test}/proto/FronthousingService.proto (100%) rename {grpc-client/src/main => test}/resources/VehicleService.json (100%) diff --git a/GrpcClientTestApp/build.gradle.kts b/GrpcClientTestApp/build.gradle.kts index b0c43b5..50639cf 100644 --- a/GrpcClientTestApp/build.gradle.kts +++ b/GrpcClientTestApp/build.gradle.kts @@ -66,3 +66,41 @@ dependencies { androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) } + +tasks.register("cleanProtos") { + delete( + fileTree("$rootDir/grpc-client/src/main") { + exclude("java") + include( + "*/Door.proto", + "*/FoldingService.proto", + "*/FronthousingService.proto", + "*/VehicleService.json", + ) + }, + ) +} + +tasks.register("setup") { + finalizedBy(":grpc-client:generateGrpcServiceClients", ":grpc-client:assemble") + + doFirst { + copy { + from("$rootDir/test/proto") + into("$rootDir/grpc-client/src/main/proto") + } + copy { + from("$rootDir/test/resources") + into("$rootDir/grpc-client/src/main/resources") + } + } +} + +afterEvaluate { + tasks.getByName("clean").finalizedBy("cleanProtos") + + tasks.getByName("test").dependsOn("setup") + tasks.getByName("test").finalizedBy("cleanProtos") + tasks.getByName("assemble").dependsOn("setup") + tasks.getByName("assemble").finalizedBy("cleanProtos") +} diff --git a/GrpcServerTestApp/build.gradle.kts b/GrpcServerTestApp/build.gradle.kts index 40f1264..53ff117 100644 --- a/GrpcServerTestApp/build.gradle.kts +++ b/GrpcServerTestApp/build.gradle.kts @@ -28,3 +28,41 @@ dependencies { implementation(project(":sdk")) implementation(project(":grpc-client")) } + +tasks.register("cleanProtos") { + delete( + fileTree("$rootDir/grpc-client/src/main") { + exclude("java") + include( + "*/Door.proto", + "*/FoldingService.proto", + "*/FronthousingService.proto", + "*/VehicleService.json", + ) + }, + ) +} + +tasks.register("setup") { + finalizedBy(":grpc-client:generateGrpcServiceClients", ":grpc-client:assemble") + + doFirst { + copy { + from("$rootDir/test/proto") + into("$rootDir/grpc-client/src/main/proto") + } + copy { + from("$rootDir/test/resources") + into("$rootDir/grpc-client/src/main/resources") + } + } +} + +afterEvaluate { + tasks.getByName("clean").finalizedBy("cleanProtos") + + tasks.getByName("test").dependsOn("setup") + tasks.getByName("test").finalizedBy("cleanProtos") + tasks.getByName("assemble").dependsOn("setup") + tasks.getByName("assemble").finalizedBy("cleanProtos") +} diff --git a/grpc-client/build.gradle.kts b/grpc-client/build.gradle.kts index d71962c..bfa014e 100644 --- a/grpc-client/build.gradle.kts +++ b/grpc-client/build.gradle.kts @@ -74,20 +74,22 @@ tasks.register("installDependencies") { commandLine("python3", "-m", "pip", "install", "-r", "./requirements.txt") } -fileTree("$projectDir/src/main/resources").forEach { file -> - val name = file.nameWithoutExtension - tasks.register("generateGrpcServiceClientFor$name") { - group = "grpc" - dependsOn("installDependencies", "generateProto") - - workingDir("$projectDir/tools") - val inputFile = file.path - commandLine("python3", "generate_code.py", inputFile) +tasks.register("generateGrpcServiceClients") { + dependsOn("installDependencies", "generateProto") + + doLast { + fileTree("$projectDir/src/main/resources").forEach { file -> + exec { + workingDir("$projectDir/tools") + val inputFilePath = file.path + commandLine("python3", "generate_code.py", inputFilePath) + } + } } +} - tasks.getByName("compileJava") { - dependsOn("generateGrpcServiceClientFor$name") - } +tasks.getByName("compileJava") { + dependsOn("generateGrpcServiceClients") } tasks.register("javadocJar") { diff --git a/grpc-client/src/main/proto/Door.proto b/test/proto/Door.proto similarity index 100% rename from grpc-client/src/main/proto/Door.proto rename to test/proto/Door.proto diff --git a/grpc-client/src/main/proto/FoldingService.proto b/test/proto/FoldingService.proto similarity index 100% rename from grpc-client/src/main/proto/FoldingService.proto rename to test/proto/FoldingService.proto diff --git a/grpc-client/src/main/proto/FronthousingService.proto b/test/proto/FronthousingService.proto similarity index 100% rename from grpc-client/src/main/proto/FronthousingService.proto rename to test/proto/FronthousingService.proto diff --git a/grpc-client/src/main/resources/VehicleService.json b/test/resources/VehicleService.json similarity index 100% rename from grpc-client/src/main/resources/VehicleService.json rename to test/resources/VehicleService.json