diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy index 0ce9b0e7..913367e8 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufJavaPluginTest.groovy @@ -15,7 +15,6 @@ import spock.lang.Unroll */ @CompileDynamic class ProtobufJavaPluginTest extends Specification { - // Current supported version is Gradle 5+. private static final List GRADLE_VERSIONS = ["5.6", "6.0", "6.7.1"] private static final List KOTLIN_VERSIONS = ["1.3.20", "1.3.30"] @@ -284,23 +283,23 @@ class ProtobufJavaPluginTest extends Specification { } @Unroll - void "testProjectDependentApp should be successfully executed [gradle #gradleVersion]"() { - given: "project from testProject & testProjectDependent" - File testProjectStaging = ProtobufPluginTestHelper.projectBuilder('testProjectJavaLibrary') + void "testProjectLibraryDependent should be successfully executed [gradle #gradleVersion]"() { + given: "project from testProjectJavaLibrary & testProjectDependent" + File testProjectStaging = ProtobufPluginTestHelper.projectBuilder('testProject') .copyDirs('testProjectBase', 'testProjectJavaLibrary') .build() - File testProjectDependentStaging = ProtobufPluginTestHelper.projectBuilder('testProjectDependentApp') - .copyDirs('testProjectDependentApp') + File testProjectDependentStaging = ProtobufPluginTestHelper.projectBuilder('testProjectDependent') + .copyDirs('testProjectDependent') .build() - File mainProjectDir = ProtobufPluginTestHelper.projectBuilder('testProjectDependentAppMain') + File mainProjectDir = ProtobufPluginTestHelper.projectBuilder('testProjectLibraryDependentMain') .copySubProjects(testProjectStaging, testProjectDependentStaging) .build() when: "build is invoked" BuildResult result = GradleRunner.create() .withProjectDir(mainProjectDir) - .withArguments('testProjectDependentApp:build', '--stacktrace') + .withArguments('testProjectDependent:build', '--stacktrace') .withPluginClasspath() .withGradleVersion(gradleVersion) .forwardStdOutput(new OutputStreamWriter(System.out)) @@ -309,7 +308,7 @@ class ProtobufJavaPluginTest extends Specification { .build() then: "it succeed" - result.task(":testProjectDependentApp:build").outcome == TaskOutcome.SUCCESS + result.task(":testProjectDependent:build").outcome == TaskOutcome.SUCCESS where: gradleVersion << GRADLE_VERSIONS diff --git a/testProjectAndroid/build.gradle b/testProjectAndroid/build.gradle index 07ec38f0..d8bac6df 100644 --- a/testProjectAndroid/build.gradle +++ b/testProjectAndroid/build.gradle @@ -2,7 +2,7 @@ // See: ProtobufPluginTestHelper.groovy plugins { + id 'com.android.application' id 'com.google.protobuf' } -apply plugin: 'com.android.application' apply from: 'build_base.gradle' diff --git a/testProjectDependentApp/build.gradle b/testProjectDependentApp/build.gradle deleted file mode 100644 index 64421ccd..00000000 --- a/testProjectDependentApp/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -// A project that depends on another project and a published artifact, both of -// which include proto files. The included proto files are added to the -// --proto_path argument of protoc, so that the protos from this project can -// import them. However, these imported proto files will not be compiled in -// this project, since they have already been compiled in their own projects. - -plugins { - id 'java' - id 'com.google.protobuf' -} - -repositories { - maven { url "https://plugins.gradle.org/m2/" } -} - -dependencies { - implementation 'com.google.protobuf:protobuf-java:3.0.0' - implementation project(':testProjectJavaLibrary') - - testImplementation 'junit:junit:4.12' -} - -protobuf.protoc { - artifact = 'com.google.protobuf:protoc:3.0.0' -} - -test.doLast { - // This project has compiled only one proto file, despite that it imports - // other proto files from dependencies. - def generatedFiles = project.fileTree(protobuf.generatedFilesBaseDir + "/main") - File onlyGeneratedFile = generatedFiles.singleFile - assert 'Dependent.java' == onlyGeneratedFile.name -} diff --git a/testProjectDependentApp/settings.gradle b/testProjectDependentApp/settings.gradle deleted file mode 100644 index 55032de8..00000000 --- a/testProjectDependentApp/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'testProjectDependentApp' diff --git a/testProjectDependentApp/src/main/proto/dependent.proto b/testProjectDependentApp/src/main/proto/dependent.proto deleted file mode 100644 index f6c6317f..00000000 --- a/testProjectDependentApp/src/main/proto/dependent.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -package dependent; - -// From testProject/src/main/proto -import "ws/antonov/protobuf/test/test.proto"; - -// From protobuf-java artifact -import "google/protobuf/any.proto"; - -message WrapperMessage { - ws.antonov.protobuf.test.Item item = 1; - google.protobuf.Any any = 2; -} diff --git a/testProjectDependentApp/src/test/java/DependentTest.java b/testProjectDependentApp/src/test/java/DependentTest.java deleted file mode 100644 index 5b45aad0..00000000 --- a/testProjectDependentApp/src/test/java/DependentTest.java +++ /dev/null @@ -1,19 +0,0 @@ -import static org.junit.Assert.assertSame; - -import org.junit.Test; - -public class DependentTest { - - @Test public void testProtos() { - dependent.Dependent.WrapperMessage message = - dependent.Dependent.WrapperMessage.newBuilder() - .setItem(ws.antonov.protobuf.test.Test.Item.getDefaultInstance()) - .setAny(com.google.protobuf.Any.getDefaultInstance()) - .build(); - assertSame(ws.antonov.protobuf.test.Test.Item.getDefaultInstance(), - message.getItem()); - Dependent2.TestWrapperMessage testMessage = - Dependent2.TestWrapperMessage.newBuilder() - .setM(message).build(); - } -} diff --git a/testProjectDependentApp/src/test/proto/dependent2.proto b/testProjectDependentApp/src/test/proto/dependent2.proto deleted file mode 100644 index 4e19d4ba..00000000 --- a/testProjectDependentApp/src/test/proto/dependent2.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -// From the 'main' sourceSet -import "dependent.proto"; - -message TestWrapperMessage { - dependent.WrapperMessage m = 1; -} \ No newline at end of file diff --git a/testProjectKotlinDslBase/build.gradle.kts b/testProjectKotlinDslBase/build.gradle.kts index 0c437444..d39fad9d 100644 --- a/testProjectKotlinDslBase/build.gradle.kts +++ b/testProjectKotlinDslBase/build.gradle.kts @@ -1,123 +1,121 @@ import com.google.protobuf.gradle.* -import org.gradle.api.internal.HasConvention -import org.gradle.kotlin.dsl.provider.gradleKotlinDslOf plugins { - java - idea - id("com.google.protobuf") + java + idea + id("com.google.protobuf") } -// This extension is not auto generated when we apply the plugin using -// apply(plugin = "com.google.protobuf") -val Project.protobuf: ProtobufConvention get() = - this.convention.getPlugin(ProtobufConvention::class) - repositories { - maven("https://plugins.gradle.org/m2/") + maven("https://plugins.gradle.org/m2/") } java { - sourceCompatibility = JavaVersion.VERSION_1_7 - targetCompatibility = JavaVersion.VERSION_1_7 + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_7 } val grpcCompile by configurations.creating the().sourceSets { - val grpc by creating { - compileClasspath += grpcCompile - } + val grpc by creating { + compileClasspath += grpcCompile + } - "test"{ - compileClasspath += grpc.output - runtimeClasspath += grpc.output - } + "test"{ + compileClasspath += grpc.output + runtimeClasspath += grpc.output + } } val protobufDep = "com.google.protobuf:protobuf-java:3.0.0" dependencies { - protobuf(files("lib/protos.tar.gz")) - protobuf(files("ext/")) - testProtobuf(files("lib/protos-test.tar.gz")) - - compile(protobufDep) - testCompile("junit:junit:4.12") - // KotlinFooTest.kt requires reflection utilities - testCompile("org.jetbrains.kotlin:kotlin-reflect:1.2.0") - grpcCompile(protobufDep) - grpcCompile("io.grpc:grpc-stub:1.0.0-pre2") - grpcCompile("io.grpc:grpc-protobuf:1.0.0-pre2") + protobuf(files("lib/protos.tar.gz")) + protobuf(files("ext/")) + testProtobuf(files("lib/protos-test.tar.gz")) + + compile(protobufDep) + testCompile("junit:junit:4.12") + // KotlinFooTest.kt requires reflection utilities + testCompile("org.jetbrains.kotlin:kotlin-reflect:1.2.0") + grpcCompile(protobufDep) + grpcCompile("io.grpc:grpc-stub:1.0.0-pre2") + grpcCompile("io.grpc:grpc-protobuf:1.0.0-pre2") } protobuf { - protoc { - artifact = "com.google.protobuf:protoc:3.0.0" + protoc { + artifact = "com.google.protobuf:protoc:3.0.0" + } + plugins { + id("grpc") { + artifact = "io.grpc:protoc-gen-grpc-java:1.0.0-pre2" } - plugins { + } + generateProtoTasks { + ofSourceSet("grpc").forEach { task -> + task.plugins { id("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:1.0.0-pre2" - } - } - generateProtoTasks { - ofSourceSet("grpc").forEach { task -> - task.plugins { - id("grpc") { - outputSubDir = "grpc_output" - } - } - task.generateDescriptorSet = true + outputSubDir = "grpc_output" } + } + task.generateDescriptorSet = true } + } } tasks { - "jar"(Jar::class) { - sourceSets.forEach { sourceSet -> - from(sourceSet.output) + "jar"(Jar::class) { + sourceSets.forEach { sourceSet -> + from(sourceSet.output) - val compileTaskName = sourceSet.getCompileTaskName("java") - dependsOn(project.tasks.getByName(compileTaskName)) - } + val compileTaskName = sourceSet.getCompileTaskName("java") + dependsOn(project.tasks.getByName(compileTaskName)) } + } - "test"{ + "test"{ - doLast{ - val generateProtoTasks = project.protobuf.protobuf.generateProtoTasks + doLast { + val generateProtoTasks = project.protobuf.protobuf.generateProtoTasks - val generateProtoTaskNames = generateProtoTasks.all().map { it.name }.toSet() - val generateProtoTaskNamesMain = generateProtoTasks.ofSourceSet("main").map { it.name }.toSet() + val generateProtoTaskNames = generateProtoTasks.all().map { it.name }.toSet() + val generateProtoTaskNamesMain = + generateProtoTasks.ofSourceSet("main").map { it.name }.toSet() - assert(setOf("generateProto", "generateGrpcProto", "generateTestProto") == generateProtoTaskNames) - assert(setOf("generateProto") == generateProtoTaskNamesMain) + assert(setOf("generateProto", + "generateGrpcProto", + "generateTestProto") == generateProtoTaskNames) + assert(setOf("generateProto") == generateProtoTaskNamesMain) - assertJavaCompileHasProtoGeneratedDir("main", listOf("java")) - assertJavaCompileHasProtoGeneratedDir("test", listOf("java")) - assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output")) + assertJavaCompileHasProtoGeneratedDir("main", listOf("java")) + assertJavaCompileHasProtoGeneratedDir("test", listOf("java")) + assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output")) - listOf("main", "test").forEach { sourceSet -> - assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc") - } - assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc") - } + listOf("main", "test").forEach { sourceSet -> + assertFileExists(false, + "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc") + } + assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc") } + } } fun assertJavaCompileHasProtoGeneratedDir(sourceSet: String, codegenPlugins: Collection) { - val compileJavaTask = tasks.getByName(sourceSets.getByName(sourceSet).getCompileTaskName("java")) as JavaCompile - assertJavaCompileHasProtoGeneratedDir(project, sourceSet, compileJavaTask, codegenPlugins) + val compileJavaTask = + tasks.getByName(sourceSets.getByName(sourceSet).getCompileTaskName("java")) as JavaCompile + assertJavaCompileHasProtoGeneratedDir(project, sourceSet, compileJavaTask, codegenPlugins) } fun assertFileExists(exists: Boolean, path: String) { - if (exists) { - assert(File(path).exists()) - } else { - assert(!File(path).exists()) - } + if (exists) { + assert(File(path).exists()) + } else { + assert(!File(path).exists()) + } } fun assertJavaCompileHasProtoGeneratedDir( @@ -126,28 +124,28 @@ fun assertJavaCompileHasProtoGeneratedDir( compileJavaTask: JavaCompile, codegenPlugins: Collection ) { - val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet") - // The expected direct subdirectories under baseDir - val expectedDirs = codegenPlugins.map { codegenPlugin -> - File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin") - }.toSet() - - val actualDirs = mutableSetOf() - compileJavaTask.source.visit { - - // If the visited file is or is under a direct subdirectory of baseDir, add - // that subdirectory to actualDirs. - var file = this@visit.file - while (true) { - if (file.parentFile == baseDir) { - actualDirs.add(file) - } - if (file.parentFile == null) { - break - } - file = file.parentFile - } + val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet") + // The expected direct subdirectories under baseDir + val expectedDirs = codegenPlugins.map { codegenPlugin -> + File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin") + }.toSet() + + val actualDirs = mutableSetOf() + compileJavaTask.source.visit { + + // If the visited file is or is under a direct subdirectory of baseDir, add + // that subdirectory to actualDirs. + var file = this@visit.file + while (true) { + if (file.parentFile == baseDir) { + actualDirs.add(file) + } + if (file.parentFile == null) { + break + } + file = file.parentFile } - assert(expectedDirs == actualDirs) + } + assert(expectedDirs == actualDirs) }