Skip to content

Commit

Permalink
Add AndroidSourceSet.proto extension for agp 7+
Browse files Browse the repository at this point in the history
More details can be found here:
google#540
  • Loading branch information
rougsig committed Jun 25, 2022
1 parent 162fe5f commit f01ce9c
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.protobuf.gradle

import com.android.build.gradle.api.AndroidSourceSet
import com.android.build.api.dsl.AndroidSourceSet
import com.android.build.gradle.api.AndroidSourceSet as DeprecatedAndroidSourceSet
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
Expand Down Expand Up @@ -64,7 +65,7 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) {

/**
* Applies the supplied action to the "proto" [SourceDirectorySet] extension on
* a receiver of type [AndroidSourceSet] for Android builds.
* a receiver of type [DeprecatedAndroidSourceSet] for Android builds.
*
* @since 0.8.15
* @usage
Expand All @@ -80,6 +81,38 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) {
* }
* ```
*
* @receiver [DeprecatedAndroidSourceSet] The Android source set for which the "proto"
* [SourceDirectorySet] extension will be configured
*
* @param action A configuration lambda to apply on a receiver of type [SourceDirectorySet]
* @return [Unit]
*/
fun DeprecatedAndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet }
?.apply(action)
}

/**
* Applies the supplied action to the "proto" [SourceDirectorySet] extension on
* a receiver of type [AndroidSourceSet] for Android builds.
*
* @since 0.8.19
* @usage
* ```
* android {
* sourceSets {
* create("sample") {
* proto {
* srcDir("src/sample/protobuf")
* }
* }
* }
* }
* ```
*
* @receiver [AndroidSourceSet] The Android source set for which the "proto"
* [SourceDirectorySet] extension will be configured
*
Expand All @@ -90,7 +123,7 @@ fun AndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet }
?.let { it as? SourceDirectorySet }
?.apply(action)
}

Expand Down

0 comments on commit f01ce9c

Please sign in to comment.