diff --git a/examples/exampleKotlinDslProject/build.gradle.kts b/examples/exampleKotlinDslProject/build.gradle.kts index 75451acf..7e10a901 100644 --- a/examples/exampleKotlinDslProject/build.gradle.kts +++ b/examples/exampleKotlinDslProject/build.gradle.kts @@ -47,12 +47,14 @@ protobuf { } generateProtoTasks { ofSourceSet("main").forEach { - it.plugins { - // Apply the "grpc" plugin whose spec is defined above, without - // options. Note the braces cannot be omitted, otherwise the - // plugin will not be added. This is because of the implicit way - // NamedDomainObjectContainer binds the methods. - id("grpc") { } + it.spec { + plugins { + // Apply the "grpc" plugin whose spec is defined above, without + // options. Note the braces cannot be omitted, otherwise the + // plugin will not be added. This is because of the implicit way + // NamedDomainObjectContainer binds the methods. + id("grpc") { } + } } } } diff --git a/examples/exampleProject/build.gradle b/examples/exampleProject/build.gradle index 4fd561f1..c0ff34be 100644 --- a/examples/exampleProject/build.gradle +++ b/examples/exampleProject/build.gradle @@ -45,12 +45,14 @@ protobuf { } generateProtoTasks { ofSourceSet('main').configureEach { - plugins { - // Apply the "grpc" plugin whose spec is defined above, without - // options. Note the braces cannot be omitted, otherwise the - // plugin will not be added. This is because of the implicit way - // NamedDomainObjectContainer binds the methods. - grpc { } + it.spec { + plugins { + // Apply the "grpc" plugin whose spec is defined above, without + // options. Note the braces cannot be omitted, otherwise the + // plugin will not be added. This is because of the implicit way + // NamedDomainObjectContainer binds the methods. + grpc { } + } } } } diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index c38506c9..267cdb22 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -31,15 +31,20 @@ package com.google.protobuf.gradle import static java.nio.charset.StandardCharsets.US_ASCII +import org.gradle.api.Action +import org.gradle.util.ConfigureUtil +import com.google.protobuf.gradle.internal.DefaultGenerateProtoTaskSpec +import com.google.protobuf.gradle.tasks.GenerateProtoTaskSpec +import com.google.protobuf.gradle.tasks.PluginSpec +import org.gradle.api.file.DeleteSpec +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Nested import groovy.transform.CompileStatic import groovy.transform.PackageScope import groovy.transform.TypeChecked import groovy.transform.TypeCheckingMode -import org.gradle.api.Action import org.gradle.api.DefaultTask import org.gradle.api.GradleException -import org.gradle.api.Named -import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection import org.gradle.api.file.ProjectLayout @@ -53,17 +58,12 @@ import org.gradle.api.tasks.IgnoreEmptyDirectories import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.Nested -import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskAction - -import javax.annotation.Nullable import javax.inject.Inject /** @@ -90,8 +90,6 @@ public abstract class GenerateProtoTask extends DefaultTask { private final ConfigurableFileCollection includeDirs = objectFactory.fileCollection() // source files are proto files that will be compiled by protoc private final ConfigurableFileCollection sourceDirs = objectFactory.fileCollection() - private final NamedDomainObjectContainer builtins = objectFactory.domainObjectContainer(PluginOptions) - private final NamedDomainObjectContainer plugins = objectFactory.domainObjectContainer(PluginOptions) private final ProjectLayout projectLayout = project.layout private final ToolsLocator toolsLocator = project.extensions.findByType(ProtobufExtension).tools @@ -116,49 +114,10 @@ public abstract class GenerateProtoTask extends DefaultTask { return Utils.isTest(sourceSet.name) } - /** - * If true, will set the protoc flag - * --descriptor_set_out="${outputBaseDir}/descriptor_set.desc" - * - * Default: false - */ - @Internal("Handled as input via getDescriptorSetOptionsForCaching()") - boolean generateDescriptorSet - - /** - * Configuration object for descriptor generation details. - */ - public class DescriptorSetOptions { - /** - * If set, specifies an alternative location than the default for storing the descriptor - * set. - * - * Default: null - */ - @Nullable - @Optional - @OutputFile - String path - - /** - * If true, source information (comments, locations) will be included in the descriptor set. - * - * Default: false - */ - @Input - boolean includeSourceInfo - - /** - * If true, imports are included in the descriptor set, such that it is self-containing. - * - * Default: false - */ - @Input - boolean includeImports - } - - @Internal("Handled as input via getDescriptorSetOptionsForCaching()") - final DescriptorSetOptions descriptorSetOptions = new DescriptorSetOptions() + @SuppressWarnings("AbstractClassWithPublicConstructor") // required to configure properties convention values + GenerateProtoTask() { + this.spec.convention(new DefaultGenerateProtoTaskSpec(this.project.objects)) + } // protoc allows you to prefix comma-delimited options to the path in // the --*_out flags, e.g., @@ -355,7 +314,7 @@ public abstract class GenerateProtoTask extends DefaultTask { } private List getAllExecutableLocators() { - [toolsLocator.protoc] + plugins.collect { PluginOptions it -> toolsLocator.plugins.getByName(it.name) } + [toolsLocator.protoc] + requireSpec().plugins.collect { PluginSpec it -> toolsLocator.plugins.getByName(it.name) } } @Internal("Not an actual input to the task, only used to find tasks belonging to a variant") @@ -402,11 +361,13 @@ public abstract class GenerateProtoTask extends DefaultTask { @Internal("Tracked as an input via getDescriptorSetOptionsForCaching()") String getDescriptorPath() { - if (!generateDescriptorSet) { + GenerateProtoTaskSpec spec = requireSpec() + if (!spec.generateDescriptorSet) { throw new IllegalStateException( "requested descriptor path but descriptor generation is off") } - return descriptorSetOptions.path != null ? descriptorSetOptions.path : "${outputBaseDir.get()}/descriptor_set.desc" + return spec.descriptorSetOptions.path != null ? spec.descriptorSetOptions.path + : "${outputBaseDir.get()}/descriptor_set.desc" } @Inject @@ -415,51 +376,21 @@ public abstract class GenerateProtoTask extends DefaultTask { @Inject abstract ObjectFactory getObjectFactory() + @Nested + abstract Property getSpec() + //=========================================================================== // Configuration methods //=========================================================================== - /** - * Configures the protoc builtins in a closure, which will be manipulating a - * NamedDomainObjectContainer. - */ - public void builtins(Action> configureAction) { - checkCanConfig() - configureAction.execute(this.builtins) + @Deprecated // temporary method for refactoring + void spec(Action configureAction) { + configureAction.execute(this.spec.get()) } - /** - * Returns the container of protoc builtins. - */ - @Internal("Tracked as an input via getBuiltinsForCaching()") - public NamedDomainObjectContainer getBuiltins() { - checkCanConfig() - return builtins - } - - /** - * Configures the protoc plugins in a closure, which will be maniuplating a - * NamedDomainObjectContainer. - */ - public void plugins(Action> configureAction) { - checkCanConfig() - configureAction.execute(this.plugins) - } - - /** - * Returns the container of protoc plugins. - */ - @Internal("Tracked as an input via getPluginsForCaching()") - public NamedDomainObjectContainer getPlugins() { - checkCanConfig() - return plugins - } - - /** - * Returns true if the task has a plugin with the given name, false otherwise. - */ - public boolean hasPlugin(String name) { - return plugins.findByName(name) != null + @Deprecated // temporary method for refactoring + void spec(@DelegatesTo(GenerateProtoTaskSpec) Closure closure) { + ConfigureUtil.configure(closure, this.spec.get()) } /** @@ -491,64 +422,11 @@ public abstract class GenerateProtoTask extends DefaultTask { return isTestProvider } - /** - * The container of command-line options for a protoc plugin or a built-in output. - */ - public static class PluginOptions implements Named { - private final List options = [] - private final String name - private String outputSubDir - - public PluginOptions(String name) { - this.name = name - } - - /** - * Adds a plugin option. - */ - public PluginOptions option(String option) { - options.add(option) - return this - } - - @Input - public List getOptions() { - return options - } - - /** - * Returns the name of the plugin or builtin. - */ - @Input - @Override - public String getName() { - return name - } - - /** - * Set the output directory for this plugin, relative to {@link GenerateProtoTask#outputBaseDir}. - */ - void setOutputSubDir(String outputSubDir) { - this.outputSubDir = outputSubDir - } - - /** - * Returns the relative outputDir for this plugin. If outputDir is not specified, name is used. - */ - @Input - public String getOutputSubDir() { - if (outputSubDir != null) { - return outputSubDir - } - return name - } - } - //=========================================================================== // protoc invocation logic //=========================================================================== - String getOutputDir(PluginOptions plugin) { + String getOutputDir(PluginSpec plugin) { return "${outputBaseDir.get()}/${plugin.outputSubDir}" } @@ -571,14 +449,16 @@ public abstract class GenerateProtoTask extends DefaultTask { @Internal @PackageScope Collection getOutputSourceDirectories() { + GenerateProtoTaskSpec spec = requireSpec() + Collection srcDirs = [] - builtins.each { builtin -> + spec.builtins.each { builtin -> File dir = new File(getOutputDir(builtin)) if (!dir.name.endsWith(".zip") && !dir.name.endsWith(".jar")) { srcDirs.add(dir) } } - plugins.each { plugin -> + spec.plugins.each { plugin -> File dir = new File(getOutputDir(plugin)) if (!dir.name.endsWith(".zip") && !dir.name.endsWith(".jar")) { srcDirs.add(dir) @@ -590,15 +470,16 @@ public abstract class GenerateProtoTask extends DefaultTask { @TaskAction void compile() { Preconditions.checkState(state == State.FINALIZED, 'doneConfig() has not been called') + GenerateProtoTaskSpec spec = requireSpec() - copyActionFacade.delete { spec -> - spec.delete(outputBaseDir) + copyActionFacade.delete { DeleteSpec deleteSpec -> + deleteSpec.delete(outputBaseDir) } // Sort to ensure generated descriptors have a canonical representation // to avoid triggering unnecessary rebuilds downstream List protoFiles = sourceDirs.asFileTree.files.sort() - [builtins, plugins]*.forEach { PluginOptions plugin -> + [spec.builtins, spec.plugins]*.forEach { PluginSpec plugin -> String outputPath = getOutputDir(plugin) File outputDir = new File(outputPath) // protoc is capable of output generated files directly to a JAR file @@ -621,14 +502,14 @@ public abstract class GenerateProtoTask extends DefaultTask { baseCmd.addAll(dirs) // Handle code generation built-ins - builtins.each { builtin -> + spec.builtins.each { builtin -> String outPrefix = makeOptionsPrefix(builtin.options) baseCmd += "--${builtin.name}_out=${outPrefix}${getOutputDir(builtin)}".toString() } Map executableLocations = toolsLocator.plugins.asMap // Handle code generation plugins - plugins.each { plugin -> + spec.plugins.each { PluginSpec plugin -> String name = plugin.name ExecutableLocator locator = executableLocations.get(name) if (locator != null) { @@ -640,7 +521,7 @@ public abstract class GenerateProtoTask extends DefaultTask { baseCmd += "--${name}_out=${pluginOutPrefix}${getOutputDir(plugin)}".toString() } - if (generateDescriptorSet) { + if (spec.generateDescriptorSet) { String path = getDescriptorPath() // Ensure that the folder for the descriptor exists; // the user may have set it to point outside an existing tree @@ -649,10 +530,10 @@ public abstract class GenerateProtoTask extends DefaultTask { folder.mkdirs() } baseCmd += "--descriptor_set_out=${path}".toString() - if (descriptorSetOptions.includeImports) { + if (spec.descriptorSetOptions.includeImports) { baseCmd += "--include_imports" } - if (descriptorSetOptions.includeSourceInfo) { + if (spec.descriptorSetOptions.includeSourceInfo) { baseCmd += "--include_source_info" } } @@ -663,29 +544,8 @@ public abstract class GenerateProtoTask extends DefaultTask { } } - /** - * Used to expose inputs to Gradle, not to be called directly. - */ - @Optional - @Nested - protected DescriptorSetOptions getDescriptorSetOptionsForCaching() { - return generateDescriptorSet ? descriptorSetOptions : null - } - - /** - * Used to expose inputs to Gradle, not to be called directly. - */ - @Nested - protected Collection getBuiltinsForCaching() { - return builtins - } - - /** - * Used to expose inputs to Gradle, not to be called directly. - */ - @Nested - protected Collection getPluginsForCaching() { - return plugins + private GenerateProtoTaskSpec requireSpec() { + return spec.get() } private static enum State { diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index c0c2bae5..1500d470 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -251,7 +251,7 @@ class ProtobufPlugin implements Plugin { Provider generateProtoTask = addGenerateProtoTask(protoSourceSet) { it.sourceSet = sourceSet it.doneInitializing() - it.builtins.maybeCreate("java") + it.spec.get().builtins.maybeCreate("java") } sourceSet.java.srcDirs(protoSourceSet.output) diff --git a/src/main/groovy/com/google/protobuf/gradle/internal/DefaultDescriptorSetSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultDescriptorSetSpec.groovy new file mode 100644 index 00000000..2e3956ad --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultDescriptorSetSpec.groovy @@ -0,0 +1,51 @@ +package com.google.protobuf.gradle.internal + +import com.google.protobuf.gradle.tasks.DescriptorSetSpec +import groovy.transform.CompileStatic +import org.gradle.api.model.ObjectFactory + +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +class DefaultDescriptorSetSpec implements DescriptorSetSpec { + private final ObjectFactory objects + private String path + private boolean includeSourceInfo + private boolean includeImports + + DefaultDescriptorSetSpec(ObjectFactory objects) { + this.objects = objects + this.path = null + this.includeSourceInfo = false + this.includeImports = false + } + + @Override + String getPath() { + return this.path + } + + @Override + void setPath(String value) { + this.path = value + } + + @Override + boolean getIncludeSourceInfo() { + return this.includeSourceInfo + } + + @Override + void setIncludeSourceInfo(boolean value) { + this.includeSourceInfo = value + } + + @Override + boolean getIncludeImports() { + return this.includeImports + } + + @Override + void setIncludeImports(boolean value) { + this.includeImports = value + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/internal/DefaultGenerateProtoTaskSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultGenerateProtoTaskSpec.groovy new file mode 100644 index 00000000..98f69216 --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultGenerateProtoTaskSpec.groovy @@ -0,0 +1,77 @@ +package com.google.protobuf.gradle.internal + +import com.google.protobuf.gradle.tasks.DescriptorSetSpec +import com.google.protobuf.gradle.tasks.GenerateProtoTaskSpec +import com.google.protobuf.gradle.tasks.PluginSpec +import groovy.transform.CompileStatic +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.NamedDomainObjectFactory +import org.gradle.api.model.ObjectFactory +import org.gradle.util.ConfigureUtil + +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +class DefaultGenerateProtoTaskSpec implements GenerateProtoTaskSpec { + private final NamedDomainObjectContainer plugins + private final NamedDomainObjectContainer builtins + private final DescriptorSetSpec descriptorSetSpec + private boolean generateDescriptorSet = false + + DefaultGenerateProtoTaskSpec(ObjectFactory objects) { + NamedDomainObjectFactory pluginSpecObjectFactory = new PluginSpecObjectFactory(objects) + this.plugins = objects.domainObjectContainer(PluginSpec, pluginSpecObjectFactory) + this.builtins = objects.domainObjectContainer(PluginSpec, pluginSpecObjectFactory) + this.descriptorSetSpec = new DefaultDescriptorSetSpec(objects) + } + + @Override + boolean getGenerateDescriptorSet() { + return generateDescriptorSet + } + + @Override + void setGenerateDescriptorSet(boolean enabled) { + this.generateDescriptorSet = enabled + } + + @Override + DescriptorSetSpec getDescriptorSetOptions() { + return this.descriptorSetSpec + } + + @Override + NamedDomainObjectContainer getPlugins() { + return this.plugins + } + + @Override + NamedDomainObjectContainer getBuiltins() { + return this.builtins + } + + @Override + boolean hasPlugin(String name) { + return plugins.findByName(name) != null + } + + @Override + void builtins(Action> configureAction) { + configureAction.execute(builtins) + } + + @Override + void builtins(Closure> closure) { + ConfigureUtil.configure(closure, builtins) + } + + @Override + void plugins(Action> configureAction) { + configureAction.execute(plugins) + } + + @Override + void plugins(Closure> closure) { + ConfigureUtil.configure(closure, plugins) + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/internal/DefaultPluginSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultPluginSpec.groovy new file mode 100644 index 00000000..8462519b --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/internal/DefaultPluginSpec.groovy @@ -0,0 +1,44 @@ +package com.google.protobuf.gradle.internal + +import com.google.protobuf.gradle.tasks.PluginSpec +import groovy.transform.CompileStatic +import org.gradle.api.model.ObjectFactory + +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +class DefaultPluginSpec implements PluginSpec { + private final ObjectFactory objects + private final List options = [] + private final String name + private String outputSubDir + + DefaultPluginSpec(ObjectFactory objects, String name) { + this.objects = objects + this.name = name + } + + DefaultPluginSpec option(String option) { + options.add(option) + return this + } + + List getOptions() { + return options + } + + @Override + String getName() { + return name + } + + void setOutputSubDir(String outputSubDir) { + this.outputSubDir = outputSubDir + } + + String getOutputSubDir() { + if (outputSubDir != null) { + return outputSubDir + } + return name + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/internal/PluginSpecObjectFactory.groovy b/src/main/groovy/com/google/protobuf/gradle/internal/PluginSpecObjectFactory.groovy new file mode 100644 index 00000000..db76537b --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/internal/PluginSpecObjectFactory.groovy @@ -0,0 +1,20 @@ +package com.google.protobuf.gradle.internal + +import com.google.protobuf.gradle.tasks.PluginSpec +import groovy.transform.CompileStatic +import org.gradle.api.NamedDomainObjectFactory +import org.gradle.api.model.ObjectFactory + +@CompileStatic +class PluginSpecObjectFactory implements NamedDomainObjectFactory { + private final ObjectFactory objects + + PluginSpecObjectFactory(ObjectFactory objects) { + this.objects = objects + } + + @Override + PluginSpec create(String name) { + return new DefaultPluginSpec(objects, name) + } +} diff --git a/src/main/groovy/com/google/protobuf/gradle/tasks/DescriptorSetSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/tasks/DescriptorSetSpec.groovy new file mode 100644 index 00000000..4edcc85d --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/tasks/DescriptorSetSpec.groovy @@ -0,0 +1,48 @@ +package com.google.protobuf.gradle.tasks + +import groovy.transform.CompileStatic +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFile + +import javax.annotation.Nullable + +/** + * Configuration object for descriptor generation details. + */ +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +interface DescriptorSetSpec { + /** + * If set, specifies an alternative location than the default for storing the descriptor + * set. + * + * Default: null + */ + @Nullable + @Optional + @OutputFile + String getPath() + + void setPath(String value) + + /** + * If true, source information (comments, locations) will be included in the descriptor set. + * + * Default: false + */ + @Input + boolean getIncludeSourceInfo() + + void setIncludeSourceInfo(boolean value) + + /** + * If true, imports are included in the descriptor set, such that it is self-containing. + * + * Default: false + */ + @Input + boolean getIncludeImports() + + void setIncludeImports(boolean value) +} diff --git a/src/main/groovy/com/google/protobuf/gradle/tasks/GenerateProtoTaskSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/tasks/GenerateProtoTaskSpec.groovy new file mode 100644 index 00000000..763d417b --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/tasks/GenerateProtoTaskSpec.groovy @@ -0,0 +1,67 @@ +package com.google.protobuf.gradle.tasks + +import groovy.transform.CompileStatic +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Nested + +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +interface GenerateProtoTaskSpec { + + /** + * If true, will set the protoc flag + * --descriptor_set_out="${outputBaseDir}/descriptor_set.desc" + * + * Default: false + */ + @Input + boolean getGenerateDescriptorSet() + + void setGenerateDescriptorSet(boolean enabled) + + @Nested + DescriptorSetSpec getDescriptorSetOptions() + + /** + * Returns the container of protoc plugins. + */ + @Nested + NamedDomainObjectContainer getPlugins() + + /** + * Returns the container of protoc builtins. + */ + @Nested + NamedDomainObjectContainer getBuiltins() + + /** + * Returns true if the task has a plugin with the given name, false otherwise. + */ + boolean hasPlugin(String name) + + /** + * Configures the protoc builtins in a closure, which will be manipulating a + * NamedDomainObjectContainer. + */ + void builtins(Action> configureAction) + + /** + * Configures the protoc builtins in a closure, which will be manipulating a + * NamedDomainObjectContainer. + */ + void builtins(Closure> closure) + + /** + * Configures the protoc plugins in a closure, which will be maniuplating a + * NamedDomainObjectContainer. + */ + void plugins(Action> configureAction) + + /** + * Configures the protoc plugins in a closure, which will be maniuplating a + * NamedDomainObjectContainer. + */ + void plugins(Closure> closure) +} diff --git a/src/main/groovy/com/google/protobuf/gradle/tasks/PluginSpec.groovy b/src/main/groovy/com/google/protobuf/gradle/tasks/PluginSpec.groovy new file mode 100644 index 00000000..a517ea5a --- /dev/null +++ b/src/main/groovy/com/google/protobuf/gradle/tasks/PluginSpec.groovy @@ -0,0 +1,39 @@ +package com.google.protobuf.gradle.tasks + +import groovy.transform.CompileStatic +import org.gradle.api.tasks.Input + +/** + * The container of command-line options for a protoc plugin or a built-in output. + */ +@CompileStatic +@SuppressWarnings("JUnitPublicNonTestMethod") // it is not a test class +interface PluginSpec { + + /** + * Adds a plugin option. + */ + PluginSpec option(String option) + + @Input + List getOptions() + + /** + * Returns the name of the plugin or builtin. + */ + @Input + String getName() + + /** + * Set the output directory for this plugin, + * relative to {@link GenerateProtoTask#outputBaseDir}. + */ + void setOutputSubDir(String outputSubDir) + + /** + * Returns the relative outputDir for this plugin. + * If outputDir is not specified, name is used. + */ + @Input + String getOutputSubDir() +} diff --git a/testProjectAndroidBase/build_base.gradle b/testProjectAndroidBase/build_base.gradle index 29f9fc16..40651d75 100644 --- a/testProjectAndroidBase/build_base.gradle +++ b/testProjectAndroidBase/build_base.gradle @@ -83,13 +83,21 @@ protobuf { } } generateProtoTasks { - all()*.plugins { - javalite { } + all().each { + it.spec { + plugins { + javalite { } + } + } } - ofNonTest()*.plugins { - grpc { - // Options added to --grpc_out - option 'lite' + ofNonTest().each { + it.spec { + plugins { + grpc { + // Options added to --grpc_out + option 'lite' + } + } } } } diff --git a/testProjectAndroidDependentBase/build_base.gradle b/testProjectAndroidDependentBase/build_base.gradle index 165aea5c..607717da 100644 --- a/testProjectAndroidDependentBase/build_base.gradle +++ b/testProjectAndroidDependentBase/build_base.gradle @@ -83,13 +83,21 @@ protobuf { } } generateProtoTasks { - all()*.plugins { - javalite { } + all().each { + it.spec { + plugins { + javalite {} + } + } } - ofNonTest()*.plugins { - grpc { - // Options added to --grpc_out - option 'lite' + ofNonTest().each { + it.spec { + plugins { + grpc { + // Options added to --grpc_out + option 'lite' + } + } } } } diff --git a/testProjectAndroidKotlinDsl/build.gradle.kts b/testProjectAndroidKotlinDsl/build.gradle.kts index cad04866..5c549fd8 100644 --- a/testProjectAndroidKotlinDsl/build.gradle.kts +++ b/testProjectAndroidKotlinDsl/build.gradle.kts @@ -106,15 +106,19 @@ protobuf { } generateProtoTasks { all().forEach { task -> - task.plugins { - id("javalite") { } + task.spec { + plugins { + id("javalite") { } + } } } ofNonTest().forEach { task -> - task.plugins { - id("grpc") { - // Options added to --grpc_out - option("lite") + task.spec { + plugins { + id("grpc") { + // Options added to --grpc_out + option("lite") + } } } } diff --git a/testProjectAndroidLibrary/build.gradle b/testProjectAndroidLibrary/build.gradle index 4539129c..4a5f061d 100644 --- a/testProjectAndroidLibrary/build.gradle +++ b/testProjectAndroidLibrary/build.gradle @@ -65,13 +65,21 @@ protobuf { } } generateProtoTasks { - all()*.plugins { - javalite { } + all().each { + it.spec { + plugins { + javalite {} + } + } } - ofNonTest()*.plugins { - grpc { - // Options added to --grpc_out - option 'lite' + ofNonTest().each { + it.spec { + plugins { + grpc { + // Options added to --grpc_out + option 'lite' + } + } } } } diff --git a/testProjectBase/build_base.gradle b/testProjectBase/build_base.gradle index 287e151d..6368aaba 100644 --- a/testProjectBase/build_base.gradle +++ b/testProjectBase/build_base.gradle @@ -46,12 +46,14 @@ protobuf { } generateProtoTasks { ofSourceSet('grpc').each { task -> - task.plugins { - grpc { - outputSubDir = 'grpc_output' + task.spec { + plugins { + grpc { + outputSubDir = 'grpc_output' + } } + generateDescriptorSet = true } - task.generateDescriptorSet = true } } } diff --git a/testProjectKotlinDslBase/build.gradle.kts b/testProjectKotlinDslBase/build.gradle.kts index ed2a37a5..4c125999 100644 --- a/testProjectKotlinDslBase/build.gradle.kts +++ b/testProjectKotlinDslBase/build.gradle.kts @@ -57,12 +57,14 @@ protobuf { } generateProtoTasks { ofSourceSet("grpc").forEach { task -> - task.plugins { - id("grpc") { - outputSubDir = "grpc_output" + task.spec { + plugins { + id("grpc") { + outputSubDir = "grpc_output" + } } + generateDescriptorSet = true } - task.generateDescriptorSet = true } } } diff --git a/testProjectLite/build.gradle b/testProjectLite/build.gradle index 62239c94..5ff1d07b 100644 --- a/testProjectLite/build.gradle +++ b/testProjectLite/build.gradle @@ -29,11 +29,13 @@ protobuf { } generateProtoTasks { all().each { task -> - task.builtins { - remove java - } - task.plugins { - javalite { } + task.spec { + builtins { + remove java + } + plugins { + javalite { } + } } } }