Skip to content

Commit

Permalink
Move protobufExtension to ProtobufPlugin field
Browse files Browse the repository at this point in the history
  • Loading branch information
rougsig committed Jul 12, 2022
1 parent fe768bf commit 8500641
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
18 changes: 6 additions & 12 deletions src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ProtobufPlugin implements Plugin<Project> {

private final FileResolver fileResolver
private Project project
private ProtobufExtension protobufExtension
private boolean wasApplied = false

@Inject
Expand All @@ -85,7 +86,7 @@ class ProtobufPlugin implements Plugin<Project> {
"Gradle version is ${project.gradle.gradleVersion}. Minimum supported version is 5.6")
}

ProtobufExtension protobufExtension = project.extensions.create("protobuf", ProtobufExtension, project)
this.protobufExtension = project.extensions.create("protobuf", ProtobufExtension, project)

this.project = project
// At least one of the prerequisite plugins must by applied before this plugin can be applied, so
Expand Down Expand Up @@ -121,7 +122,7 @@ class ProtobufPlugin implements Plugin<Project> {
task.source genProtoTask.getOutputSourceDirectorySet().include("**/*.java", "**/*.kt")
}

private void doApply(final ProtobufExtension protobufExtension) {
private void doApply() {
// Provides the osdetector extension
project.apply([plugin:com.google.gradle.osdetector.OsDetectorPlugin])

Expand Down Expand Up @@ -248,7 +249,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Adds Protobuf-related tasks to the project.
*/
private void addProtoTasks(final ProtobufExtension protobufExtension) {
private void addProtoTasks() {
if (Utils.isAndroidProject(project)) {
getNonTestVariants().each { variant ->
addTasksForVariant(protobufExtension, variant, false)
Expand All @@ -266,10 +267,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Creates Protobuf tasks for a sourceSet in a Java project.
*/
private void addTasksForSourceSet(
final ProtobufExtension protobufExtension,
final SourceSet sourceSet
) {
private void addTasksForSourceSet(final SourceSet sourceSet) {
Task generateProtoTask = addGenerateProtoTask(protobufExtension, sourceSet.name, [sourceSet])
generateProtoTask.sourceSet = sourceSet
generateProtoTask.doneInitializing()
Expand All @@ -293,11 +291,7 @@ class ProtobufPlugin implements Plugin<Project> {
/**
* Creates Protobuf tasks for a variant in an Android project.
*/
private void addTasksForVariant(
final ProtobufExtension protobufExtension,
final Object variant,
final boolean isTestVariant
) {
private void addTasksForVariant(final Object variant, final boolean isTestVariant) {
// GenerateProto task, one per variant (compilation unit).
Task generateProtoTask = addGenerateProtoTask(protobufExtension, variant.name, variant.sourceSets)
generateProtoTask.setVariant(variant, isTestVariant)
Expand Down
7 changes: 2 additions & 5 deletions testProjectBase/build_base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ def assertFileExists(boolean exists, String path) {
}

test.doLast {
assert [
'generateProto',
'generateGrpcProto',
'generateTestProto'
] as Set == protobuf.generateProtoTasks.all().collect({ it.name }) as Set
assert ['generateProto', 'generateGrpcProto', 'generateTestProto'] as Set ==
protobuf.generateProtoTasks.all().collect({ it.name }) as Set

assert ['generateProto'] as Set == protobuf.generateProtoTasks.ofSourceSet('main').collect({ it.name }) as Set
assert [] as Set == protobuf.generateProtoTasks.ofTest().collect({ it.name }) as Set
Expand Down

0 comments on commit 8500641

Please sign in to comment.