diff --git a/wire-gradle-plugin/api/wire-gradle-plugin.api b/wire-gradle-plugin/api/wire-gradle-plugin.api index 2a9296203d..c947120db2 100644 --- a/wire-gradle-plugin/api/wire-gradle-plugin.api +++ b/wire-gradle-plugin/api/wire-gradle-plugin.api @@ -108,14 +108,14 @@ public class com/squareup/wire/gradle/WireExtension { public final fun eventListenerFactory (Lcom/squareup/wire/schema/EventListener$Factory;)V public final fun eventListenerFactoryClass (Ljava/lang/String;)V public final fun eventListenerFactoryClasses ()Ljava/util/Set; - public final fun getDryRun ()Z - public final fun getOutputs ()Ljava/util/List; - public final fun getProtoLibrary ()Z - public final fun getRejectUnusedRootsOrPrunes ()Z - public final fun getRules ()Ljava/lang/String; + public final fun getDryRun ()Lorg/gradle/api/provider/Property; + public final fun getOutputs ()Lorg/gradle/api/provider/ListProperty; + public final fun getProtoLibrary ()Lorg/gradle/api/provider/Property; + public final fun getRejectUnusedRootsOrPrunes ()Lorg/gradle/api/provider/Property; + public final fun getRules ()Lorg/gradle/api/provider/Property; public final fun java (Lorg/gradle/api/Action;)V public final fun kotlin (Lorg/gradle/api/Action;)V - public final fun loadExhaustively ()Z + public final fun loadExhaustively ()Ljava/lang/Boolean; public final fun loadExhaustively (Z)V public final fun move (Lorg/gradle/api/Action;)V public final fun moves ()Ljava/util/List; @@ -123,7 +123,7 @@ public class com/squareup/wire/gradle/WireExtension { public final fun onlyVersion (Ljava/lang/String;)V public final fun opaque ([Ljava/lang/String;)V public final fun opaques ()Ljava/util/Set; - public final fun permitPackageCycles ()Z + public final fun permitPackageCycles ()Ljava/lang/Boolean; public final fun permitPackageCycles (Z)V public final fun proto (Lorg/gradle/api/Action;)V public final fun protoPath (Lorg/gradle/api/Action;)V diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireExtension.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireExtension.kt index d4504f1e70..c8e9de4e00 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireExtension.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireExtension.kt @@ -26,6 +26,8 @@ import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.internal.catalog.DelegatingProjectDependency +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderConvertible @@ -36,88 +38,93 @@ open class WireExtension( internal val protoSourceProtoRootSets = mutableListOf() internal val protoPathProtoRootSets = mutableListOf() - internal val roots = mutableSetOf() - internal val prunes = mutableSetOf() - internal val moves = mutableListOf() - internal val opaques = mutableSetOf() - internal val eventListenerFactories = mutableSetOf() - internal val eventListenerFactoryClasses = mutableSetOf() - internal var onlyVersion: String? = null - internal var sinceVersion: String? = null - internal var untilVersion: String? = null - internal var permitPackageCycles: Boolean = false - internal var loadExhaustively: Boolean = false - - fun roots() = roots.toSet() + internal val roots = objectFactory.setProperty(String::class.java) + internal val prunes = objectFactory.setProperty(String::class.java) + internal val moves = objectFactory.listProperty(Move::class.java) + internal val opaques = objectFactory.setProperty(String::class.java) + internal val eventListenerFactories = objectFactory.setProperty(EventListener.Factory::class.java) + internal val eventListenerFactoryClasses = objectFactory.setProperty(String::class.java) + internal val onlyVersion = objectFactory.property(String::class.java) + internal val sinceVersion = objectFactory.property(String::class.java) + internal val untilVersion = objectFactory.property(String::class.java) + internal val permitPackageCycles = objectFactory.property(Boolean::class.java).convention(false) + internal val loadExhaustively = objectFactory.property(Boolean::class.java).convention(false) + + fun roots() = roots.get().toSet() /** * See [com.squareup.wire.schema.WireRun.treeShakingRoots]. */ fun root(vararg roots: String) { - this.roots.addAll(roots) + this.roots.addAll(roots.toList()) } - fun prunes() = prunes.toSet() + fun prunes() = prunes.get().toSet() /** * See [com.squareup.wire.schema.WireRun.treeShakingRubbish]. */ fun prune(vararg prunes: String) { - this.prunes.addAll(prunes) + this.prunes.addAll(prunes.toList()) } - fun sinceVersion() = sinceVersion + fun sinceVersion() = sinceVersion.orNull /** * See [com.squareup.wire.schema.WireRun.sinceVersion]. */ fun sinceVersion(sinceVersion: String) { - this.sinceVersion = sinceVersion + this.sinceVersion.set(sinceVersion) } - fun untilVersion() = untilVersion + fun untilVersion() = untilVersion.orNull /** * See [com.squareup.wire.schema.WireRun.untilVersion]. */ fun untilVersion(untilVersion: String) { - this.untilVersion = untilVersion + this.untilVersion.set(untilVersion) } - fun onlyVersion() = onlyVersion + fun onlyVersion() = onlyVersion.orNull /** * See [com.squareup.wire.schema.WireRun.onlyVersion]. */ fun onlyVersion(onlyVersion: String) { - this.onlyVersion = onlyVersion + this.onlyVersion.set(onlyVersion) } - fun permitPackageCycles() = permitPackageCycles + fun permitPackageCycles() = permitPackageCycles.get() /** * See [com.squareup.wire.schema.WireRun.permitPackageCycles]. */ fun permitPackageCycles(permitPackageCycles: Boolean) { - this.permitPackageCycles = permitPackageCycles + this.permitPackageCycles.set(permitPackageCycles) } - fun loadExhaustively() = loadExhaustively + fun loadExhaustively() = loadExhaustively.get() /** * See [com.squareup.wire.schema.WireRun.loadExhaustively]. */ fun loadExhaustively(loadExhaustively: Boolean) { - this.loadExhaustively = loadExhaustively + this.loadExhaustively.set(loadExhaustively) } /** * A user-provided file listing [roots] and [prunes]. */ - var rules: String? = null + val rules: Property = objectFactory.property(String::class.java) + + /** For Groovy DSL assignment: `rules = "path/to/rules.txt"`. */ + fun setRules(value: String?) { + rules.set(value) + } /** Specified what types to output where. Maps to [com.squareup.wire.schema.Target] */ - val outputs = mutableListOf() + val outputs: ListProperty = objectFactory.listProperty(WireOutput::class.java) /** * True to emit `.proto` files into the output resources. Use this when your `.jar` file can be @@ -126,7 +133,13 @@ open class WireExtension( * Note that only the `.proto` files used in the library will be included, and these files will * have tree-shaking applied. */ - var protoLibrary = false + val protoLibrary: Property = + objectFactory.property(Boolean::class.java).convention(false) + + /** For Groovy DSL assignment: `protoLibrary = true`. */ + fun setProtoLibrary(value: Boolean) { + protoLibrary.set(value) + } /** * If true, Wire will fail if not all [roots] and [prunes] are used when tree-shaking the schema. @@ -137,13 +150,24 @@ open class WireExtension( * * If false, unused [roots] and [prunes] will be printed as warnings. */ - var rejectUnusedRootsOrPrunes = true + val rejectUnusedRootsOrPrunes: Property = + objectFactory.property(Boolean::class.java).convention(true) + + /** For Groovy DSL assignment: `rejectUnusedRootsOrPrunes = false`. */ + fun setRejectUnusedRootsOrPrunes(value: Boolean) { + rejectUnusedRootsOrPrunes.set(value) + } /** * True to not write generated types to disk, but emit the names of the source files that would * otherwise be generated. */ - var dryRun = false + val dryRun: Property = objectFactory.property(Boolean::class.java).convention(false) + + /** For Groovy DSL assignment: `dryRun = true`. */ + fun setDryRun(value: Boolean) { + dryRun.set(value) + } /** * Source paths for local jars and directories, as well as remote binary dependencies @@ -164,14 +188,14 @@ open class WireExtension( action.execute(addProtoSourceProtoRootSet()) } - fun eventListenerFactories() = eventListenerFactories.toSet() + fun eventListenerFactories() = eventListenerFactories.get().toSet() /** Add a [EventListener.Factory]. */ fun eventListenerFactory(eventListenerFactory: EventListener.Factory) { this.eventListenerFactories.add(eventListenerFactory) } - fun eventListenerFactoryClasses() = eventListenerFactoryClasses.toSet() + fun eventListenerFactoryClasses() = eventListenerFactoryClasses.get().toSet() /** Add a [EventListener.Factory] by name. The referred class must have a no-arguments constructor. */ fun eventListenerFactoryClass(eventListenerFactoryClass: String) { @@ -227,7 +251,7 @@ open class WireExtension( fun java(action: Action) { val javaOutput = objectFactory.newInstance(JavaOutput::class.java) action.execute(javaOutput) - outputs += javaOutput + outputs.add(javaOutput) } /** @@ -236,7 +260,7 @@ open class WireExtension( fun kotlin(action: Action) { val kotlinOutput = objectFactory.newInstance(KotlinOutput::class.java) action.execute(kotlinOutput) - outputs += kotlinOutput + outputs.add(kotlinOutput) } /** @@ -245,7 +269,7 @@ open class WireExtension( fun proto(action: Action) { val protoOutput = objectFactory.newInstance(ProtoOutput::class.java) action.execute(protoOutput) - outputs += protoOutput + outputs.add(protoOutput) } /** @@ -254,10 +278,10 @@ open class WireExtension( fun custom(action: Action) { val customOutput = objectFactory.newInstance(CustomOutput::class.java) action.execute(customOutput) - outputs += customOutput + outputs.add(customOutput) } - fun moves() = moves.toList() + fun moves() = moves.get().toList() /** * See [com.squareup.wire.schema.WireRun.moves]. @@ -265,16 +289,16 @@ open class WireExtension( fun move(action: Action) { val move = objectFactory.newInstance(Move::class.java) action.execute(move) - moves += move + moves.add(move) } - fun opaques() = opaques.toSet() + fun opaques() = opaques.get().toSet() /** * See [com.squareup.wire.schema.WireRun.opaqueTypes]. */ fun opaque(vararg opaques: String) { - this.opaques.addAll(opaques) + this.opaques.addAll(opaques.toList()) } /** @@ -310,8 +334,8 @@ open class WireExtension( files } - internal val includes = mutableListOf() - internal val excludes = mutableListOf() + internal val includes = project.objects.listProperty(String::class.java) + internal val excludes = project.objects.listProperty(String::class.java) /** * Adds a set of source. The given paths are evaluated as per [Project.files][org.gradle.api.Project.files]. @@ -395,7 +419,7 @@ open class WireExtension( * Example: "com/example/important.proto". */ fun include(vararg includePaths: String) { - includes += includePaths + includes.addAll(includePaths.toList()) } /** @@ -403,7 +427,7 @@ open class WireExtension( * Example: "com/example/irrelevant.proto". */ fun exclude(vararg excludePaths: String) { - excludes += excludePaths + excludes.addAll(excludePaths.toList()) } } } diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt index ff13310f66..afb7446c71 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt @@ -28,11 +28,13 @@ internal val List.inputLocations: List get() = map { rootSet -> rootSet.inputLocation() } private fun ProtoRootSet.inputLocation(): InputLocation { - val includes = when { - includes.isEmpty() && excludes.isEmpty() -> listOf("**/*.proto") - else -> includes + val includesList = includes.get() + val excludesList = excludes.get() + val resolvedIncludes = when { + includesList.isEmpty() && excludesList.isEmpty() -> listOf("**/*.proto") + else -> includesList } - return InputLocation(configuration, includes, excludes) + return InputLocation(configuration, resolvedIncludes, excludesList) } /** diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt index 3a5f0ce6d2..037c35303d 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt @@ -81,8 +81,8 @@ class WirePlugin : Plugin { project.plugins.withId("java-library", javaPluginHandler) project.afterEvaluate { - if (extension.protoLibrary) { - val existingProtoOutput = extension.outputs.filterIsInstance().singleOrNull() + if (extension.protoLibrary.get()) { + val existingProtoOutput = extension.outputs.get().filterIsInstance().singleOrNull() if (existingProtoOutput != null) { // There exists a `proto {}` target already, we only set the output path if need be. if (existingProtoOutput.out == null) { @@ -99,7 +99,7 @@ class WirePlugin : Plugin { applyWirePlugin() } - val outputs = extension.outputs + val outputs = extension.outputs.get() check(outputs.isNotEmpty()) { "At least one target must be provided for project '${project.path}\n" + "See our documentation for details: https://square.github.io/wire/wire_compiler/#customizing-output" } @@ -133,7 +133,7 @@ class WirePlugin : Plugin { extension: WireExtension, source: WireSource, ) { - val outputs = extension.outputs + val outputs = extension.outputs.get() val protoSourceProtoRootSets = extension.protoSourceProtoRootSets.toMutableList() val protoPathProtoRootSets = extension.protoPathProtoRootSets.toMutableList() @@ -198,10 +198,10 @@ class WirePlugin : Plugin { } task.sourceInput.set(project.provider { protoSourceProtoRootSets.inputLocations }) task.protoInput.set(project.provider { protoPathProtoRootSets.inputLocations }) - task.roots.set(extension.roots.toList()) - task.prunes.set(extension.prunes.toList()) - task.moves.set(extension.moves.toList()) - task.opaques.set(extension.opaques.toList()) + task.roots.set(extension.roots) + task.prunes.set(extension.prunes) + task.moves.set(extension.moves) + task.opaques.set(extension.opaques) task.sinceVersion.set(extension.sinceVersion) task.untilVersion.set(extension.untilVersion) task.onlyVersion.set(extension.onlyVersion) @@ -215,7 +215,7 @@ class WirePlugin : Plugin { task.projectDirProperty.set(project.layout.projectDirectory) task.buildDirProperty.set(project.layout.buildDirectory) - val factories = extension.eventListenerFactories + extension.eventListenerFactoryClasses().map(::newEventListenerFactory) + val factories = extension.eventListenerFactories.get() + extension.eventListenerFactoryClasses.get().map(::newEventListenerFactory) task.eventListenerFactories.set(factories) }