From 1391e446021e6e12bc50c6bcac83a503f131ac4b Mon Sep 17 00:00:00 2001 From: Ivan Gavrilovic Date: Tue, 11 Jan 2022 11:19:17 +0000 Subject: [PATCH] Android - Add tested top-level dirs that contains protos When adding protos from the tested variant in Android projects, add only top-level dirs to avoid logging the warning. Fixes #357 Test: ProtobufAndroidPluginTest --- .../protobuf/gradle/ProtobufPlugin.groovy | 2 +- .../gradle/ProtobufAndroidPluginTest.groovy | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 91ba8321..59399917 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -426,7 +426,7 @@ class ProtobufPlugin implements Plugin { // ad-hoc solution that manually includes the source protos of 'main' and its // dependencies. if (Utils.isTest(sourceSetOrVariantName)) { - inputFiles.from getSourceSets()['main'].proto + inputFiles.from getSourceSets()['main'].proto.sourceDirectories inputFiles.from testedCompileClasspathConfiguration } } else { diff --git a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginTest.groovy b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginTest.groovy index 348111a0..300f8b3a 100644 --- a/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginTest.groovy +++ b/src/test/groovy/com/google/protobuf/gradle/ProtobufAndroidPluginTest.groovy @@ -137,4 +137,38 @@ class ProtobufAndroidPluginTest extends Specification { agpVersion << ANDROID_PLUGIN_VERSION gradleVersion << GRADLE_VERSION } + + @Unroll + void "testProjectAndroid tests build without warnings [android #agpVersion, gradle #gradleVersion]"() { + given: "project from testProject, testProjectLite & testProjectAndroid" + File testProjectStaging = ProtobufPluginTestHelper.projectBuilder('testProject') + .copyDirs('testProjectBase', 'testProject') + .build() + File testProjectAndroidStaging = ProtobufPluginTestHelper.projectBuilder('testProjectAndroid') + .copyDirs('testProjectAndroidBase', 'testProjectAndroid') + .build() + File testProjectLiteStaging = ProtobufPluginTestHelper.projectBuilder('testProjectLite') + .copyDirs('testProjectLite') + .build() + File mainProjectDir = ProtobufPluginTestHelper.projectBuilder('testProjectAndroidMain') + .copySubProjects(testProjectStaging, testProjectLiteStaging, testProjectAndroidStaging) + .withAndroidPlugin(agpVersion) + .build() + when: "build is invoked" + BuildResult result = buildAndroidProject( + mainProjectDir, + gradleVersion, + "testProjectAndroid:assembleAndroidTest" + ) + + then: "it succeed" + result.task(":testProjectAndroid:assembleAndroidTest").outcome == TaskOutcome.SUCCESS + + and: "does not contain warnings about proto location" + !result.output.contains("This makes you vulnerable to https://github.com/google/protobuf-gradle-plugin/issues/248") + + where: + agpVersion << ANDROID_PLUGIN_VERSION.takeRight(1) + gradleVersion << GRADLE_VERSION.takeRight(1) + } }