From 676f8f2a3ae420b231263549c2979a648627407f Mon Sep 17 00:00:00 2001 From: Holger Stolzenberg Date: Wed, 13 Nov 2024 11:43:03 +0100 Subject: [PATCH] Try to fix all tests by adopting new output path for generated sources --- README.md | 2 +- .../protobuf/gradle/ProtobufExtension.groovy | 4 +-- .../protobuf/gradle/IDESupportTest.groovy | 26 +++++++++---------- .../ProtobufKotlinDslCopySpecTest.groovy | 2 +- .../gradle/ProtobufPluginTestHelper.groovy | 2 +- testProjectAndroidKotlinDsl/build.gradle.kts | 4 +-- testProjectBase/build_base.gradle | 8 +++--- testProjectKotlinDslBase/build.gradle.kts | 8 +++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 48b27750..bdc9b51e 100644 --- a/README.md +++ b/README.md @@ -410,7 +410,7 @@ protobuf { Generated files are under `task.outputBaseDir` with a subdirectory per builtin and plugin. This produces a folder structure of -``$buildDir/generated/source/proto/$sourceSet/$builtinPluginName``. +``$buildDir/generated/sources/proto/$sourceSet/$builtinPluginName``. The subdirectory name, which is by default ``$builtinPluginName``, can be changed by setting the ``outputSubDir`` property in the ``builtins`` or diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy index c08d203f..e18be041 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufExtension.groovy @@ -65,7 +65,7 @@ abstract class ProtobufExtension { this.tasks = new GenerateProtoTaskCollection(project) this.tools = new ToolsLocator(project) this.taskConfigActions = [] - this.defaultGeneratedFilesBaseDir = project.layout.buildDirectory.dir("generated/source/proto").map { + this.defaultGeneratedFilesBaseDir = project.layout.buildDirectory.dir("generated/sources/proto").map { it.asFile.path } this.generatedFilesBaseDirProperty.convention(defaultGeneratedFilesBaseDir) @@ -107,7 +107,7 @@ abstract class ProtobufExtension { /** * The base directory of generated files. The default is - * "${project.buildDir}/generated/source/proto". + * "${project.buildDir}/generated/sources/proto". */ @PackageScope abstract Property getGeneratedFilesBaseDirProperty() diff --git a/src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy b/src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy index 02422537..6178c9c5 100644 --- a/src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy @@ -87,28 +87,28 @@ class IDESupportTest extends Specification { 'file://$MODULE_DIR$/build/extracted-protos/main', 'file://$MODULE_DIR$/build/extracted-include-protos/main', 'file://$MODULE_DIR$/build/extracted-protos/grpc', - 'file://$MODULE_DIR$/build/generated/source/proto/grpc/java', - 'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output', - 'file://$MODULE_DIR$/build/generated/source/proto/main/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/grpc/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/grpc/grpc_output', + 'file://$MODULE_DIR$/build/generated/sources/proto/main/java', ] Set expectedTestSourceDir = [ 'file://$MODULE_DIR$/src/test/java', 'file://$MODULE_DIR$/src/test/proto', 'file://$MODULE_DIR$/build/extracted-protos/test', 'file://$MODULE_DIR$/build/extracted-include-protos/test', - 'file://$MODULE_DIR$/build/generated/source/proto/test/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/test/java', ] Set expectedGeneratedDirs = [ 'file://$MODULE_DIR$/build/extracted-include-protos/grpc', 'file://$MODULE_DIR$/build/extracted-protos/main', 'file://$MODULE_DIR$/build/extracted-include-protos/main', 'file://$MODULE_DIR$/build/extracted-protos/grpc', - 'file://$MODULE_DIR$/build/generated/source/proto/grpc/java', - 'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output', - 'file://$MODULE_DIR$/build/generated/source/proto/main/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/grpc/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/grpc/grpc_output', + 'file://$MODULE_DIR$/build/generated/sources/proto/main/java', 'file://$MODULE_DIR$/build/extracted-protos/test', 'file://$MODULE_DIR$/build/extracted-include-protos/test', - 'file://$MODULE_DIR$/build/generated/source/proto/test/java', + 'file://$MODULE_DIR$/build/generated/sources/proto/test/java', ] assert Objects.equals(expectedSourceDir, sourceDir) assert Objects.equals(expectedTestSourceDir, testSourceDir) @@ -143,7 +143,7 @@ class IDESupportTest extends Specification { srcEntries.each { String path = it.@path sourceDir.add(path) - if (path.startsWith("build/generated/source/proto")) { + if (path.startsWith("build/generated/sources/proto")) { if (path.contains("test")) { // test source path has one more attribute: ["test"="true"] assert it.attributes.attribute.size() == 3 @@ -156,10 +156,10 @@ class IDESupportTest extends Specification { Set expectedSourceDir = [ 'src/main/java', 'src/test/java', - 'build/generated/source/proto/grpc/java', - 'build/generated/source/proto/grpc/grpc_output', - 'build/generated/source/proto/main/java', - 'build/generated/source/proto/test/java', + 'build/generated/sources/proto/grpc/java', + 'build/generated/sources/proto/grpc/grpc_output', + 'build/generated/sources/proto/main/java', + 'build/generated/sources/proto/test/java', ] assert Objects.equals(expectedSourceDir, sourceDir) diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufKotlinDslCopySpecTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufKotlinDslCopySpecTest.groovy index 6a35cdce..68d0c195 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufKotlinDslCopySpecTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufKotlinDslCopySpecTest.groovy @@ -39,7 +39,7 @@ class ProtobufKotlinDslCopySpecTest extends Specification { } private static void verifyProjectDir(File projectDir) { - File generatedSrcDir = new File(projectDir.path, "build/generated/source/proto/main/java") + File generatedSrcDir = new File(projectDir.path, "build/generated/sources/proto/main/java") List fileList = [] generatedSrcDir.eachFileRecurse { file -> if (file.path.endsWith('.java')) { diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy index 8a7ca7e6..8ef270bc 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufPluginTestHelper.groovy @@ -15,7 +15,7 @@ final class ProtobufPluginTestHelper { static void verifyProjectDir(File projectDir) { ['grpc', 'main', 'test'].each { - File generatedSrcDir = new File(projectDir.path, "build/generated/source/proto/$it") + File generatedSrcDir = new File(projectDir.path, "build/generated/sources/proto/$it") List fileList = [] generatedSrcDir.eachFileRecurse { file -> if (file.path.endsWith('.java')) { diff --git a/testProjectAndroidKotlinDsl/build.gradle.kts b/testProjectAndroidKotlinDsl/build.gradle.kts index cad04866..f8cb68c3 100644 --- a/testProjectAndroidKotlinDsl/build.gradle.kts +++ b/testProjectAndroidKotlinDsl/build.gradle.kts @@ -310,10 +310,10 @@ fun assertJavaCompileHasProtoGeneratedDir( compileJavaTask: JavaCompile, codegenPlugins: Collection ) { - val baseDir = File("${project.buildDir}/generated/source/proto/$variant") + val baseDir = File("${project.buildDir}/generated/sources/protos/$variant") // The expected direct subdirectories under baseDir val expectedDirs = codegenPlugins.map { codegenPlugin -> - File("${project.buildDir}/generated/source/proto/$variant/$codegenPlugin") + File("${project.buildDir}/generated/sources/proto/$variant/$codegenPlugin") }.toSet() val actualDirs = mutableSetOf() diff --git a/testProjectBase/build_base.gradle b/testProjectBase/build_base.gradle index 287e151d..75c5332f 100644 --- a/testProjectBase/build_base.gradle +++ b/testProjectBase/build_base.gradle @@ -97,9 +97,9 @@ test.doLast { // Check generateDescriptorSet option has been honored ['main', 'test'].each { sourceSet -> - assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc") + assertFileExists(false, "$buildDir/generated/sources/proto/$sourceSet/descriptor_set.desc") } - assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc") + assertFileExists(true, "$buildDir/generated/sources/proto/grpc/descriptor_set.desc") } rootProject.ext { @@ -108,10 +108,10 @@ rootProject.ext { // not include any other dirs under the generated code base dir. assertJavaCompileHasProtoGeneratedDir = { Project project, String sourceSet, JavaCompile compileJavaTask, Collection codegenPlugins -> - def baseDir = "${project.buildDir}/generated/source/proto/$sourceSet" as File + def baseDir = "${project.buildDir}/generated/sources/proto/$sourceSet" as File // The expected direct subdirectories under baseDir def expectedDirs = codegenPlugins.collect { codegenPlugin -> - "${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin" as File + "${project.buildDir}/generated/sources/proto/$sourceSet/$codegenPlugin" as File } as Set def actualDirs = new HashSet() diff --git a/testProjectKotlinDslBase/build.gradle.kts b/testProjectKotlinDslBase/build.gradle.kts index ed2a37a5..3ade54f9 100644 --- a/testProjectKotlinDslBase/build.gradle.kts +++ b/testProjectKotlinDslBase/build.gradle.kts @@ -97,9 +97,9 @@ tasks { assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output")) listOf("main", "test").forEach { sourceSet -> - assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc") + assertFileExists(false, "$buildDir/generated/sources/proto/$sourceSet/descriptor_set.desc") } - assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc") + assertFileExists(true, "$buildDir/generated/sources/proto/grpc/descriptor_set.desc") } } } @@ -123,10 +123,10 @@ fun assertJavaCompileHasProtoGeneratedDir( compileJavaTask: JavaCompile, codegenPlugins: Collection ) { - val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet") + val baseDir = File("${project.buildDir}/generated/sources/proto/$sourceSet") // The expected direct subdirectories under baseDir val expectedDirs = codegenPlugins.map { codegenPlugin -> - File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin") + File("${project.buildDir}/generated/sources/proto/$sourceSet/$codegenPlugin") }.toSet() val actualDirs = mutableSetOf()