Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions wire-gradle-plugin/api/wire-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ 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;
public final fun onlyVersion ()Ljava/lang/String;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -36,88 +38,93 @@ open class WireExtension(

internal val protoSourceProtoRootSets = mutableListOf<ProtoRootSet>()
internal val protoPathProtoRootSets = mutableListOf<ProtoRootSet>()
internal val roots = mutableSetOf<String>()
internal val prunes = mutableSetOf<String>()
internal val moves = mutableListOf<Move>()
internal val opaques = mutableSetOf<String>()
internal val eventListenerFactories = mutableSetOf<EventListener.Factory>()
internal val eventListenerFactoryClasses = mutableSetOf<String>()
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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun permitPackageCycles() = permitPackageCycles.get()
fun permitPackageCycles() = permitPackageCycles.set(true)


/**
* 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()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun loadExhaustively() = loadExhaustively.get()
fun loadExhaustively() = loadExhaustively.set(true)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a getter before, why do we wanna change it to a setter?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I misread the binary diff. Previously it returned a boolean (which is misread as void) and now it returns a boxed boolean. Do you want to fix that?


/**
* 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<String> = 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<WireOutput>()
val outputs: ListProperty<WireOutput> = objectFactory.listProperty(WireOutput::class.java)

/**
* True to emit `.proto` files into the output resources. Use this when your `.jar` file can be
Expand All @@ -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<Boolean> =
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.
Expand All @@ -137,13 +150,24 @@ open class WireExtension(
*
* If false, unused [roots] and [prunes] will be printed as warnings.
*/
var rejectUnusedRootsOrPrunes = true
val rejectUnusedRootsOrPrunes: Property<Boolean> =
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<Boolean> = 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
Expand All @@ -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) {
Expand Down Expand Up @@ -227,7 +251,7 @@ open class WireExtension(
fun java(action: Action<JavaOutput>) {
val javaOutput = objectFactory.newInstance(JavaOutput::class.java)
action.execute(javaOutput)
outputs += javaOutput
outputs.add(javaOutput)
}

/**
Expand All @@ -236,7 +260,7 @@ open class WireExtension(
fun kotlin(action: Action<KotlinOutput>) {
val kotlinOutput = objectFactory.newInstance(KotlinOutput::class.java)
action.execute(kotlinOutput)
outputs += kotlinOutput
outputs.add(kotlinOutput)
}

/**
Expand All @@ -245,7 +269,7 @@ open class WireExtension(
fun proto(action: Action<ProtoOutput>) {
val protoOutput = objectFactory.newInstance(ProtoOutput::class.java)
action.execute(protoOutput)
outputs += protoOutput
outputs.add(protoOutput)
}

/**
Expand All @@ -254,27 +278,27 @@ open class WireExtension(
fun custom(action: Action<CustomOutput>) {
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].
*/
fun move(action: Action<Move>) {
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())
}

/**
Expand Down Expand Up @@ -310,8 +334,8 @@ open class WireExtension(
files
}

internal val includes = mutableListOf<String>()
internal val excludes = mutableListOf<String>()
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].
Expand Down Expand Up @@ -395,15 +419,15 @@ open class WireExtension(
* Example: "com/example/important.proto".
*/
fun include(vararg includePaths: String) {
includes += includePaths
includes.addAll(includePaths.toList())
}

/**
* If set, all the files defined as excluded will be ignored.
* Example: "com/example/irrelevant.proto".
*/
fun exclude(vararg excludePaths: String) {
excludes += excludePaths
excludes.addAll(excludePaths.toList())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ internal val List<ProtoRootSet>.inputLocations: List<InputLocation>
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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class WirePlugin : Plugin<Project> {
project.plugins.withId("java-library", javaPluginHandler)

project.afterEvaluate {
if (extension.protoLibrary) {
val existingProtoOutput = extension.outputs.filterIsInstance<ProtoOutput>().singleOrNull()
if (extension.protoLibrary.get()) {
val existingProtoOutput = extension.outputs.get().filterIsInstance<ProtoOutput>().singleOrNull()
if (existingProtoOutput != null) {
// There exists a `proto {}` target already, we only set the output path if need be.
if (existingProtoOutput.out == null) {
Expand All @@ -99,7 +99,7 @@ class WirePlugin : Plugin<Project> {
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"
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class WirePlugin : Plugin<Project> {
extension: WireExtension,
source: WireSource,
) {
val outputs = extension.outputs
val outputs = extension.outputs.get()

val protoSourceProtoRootSets = extension.protoSourceProtoRootSets.toMutableList()
val protoPathProtoRootSets = extension.protoPathProtoRootSets.toMutableList()
Expand Down Expand Up @@ -198,10 +198,10 @@ class WirePlugin : Plugin<Project> {
}
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)
Expand All @@ -215,7 +215,7 @@ class WirePlugin : Plugin<Project> {
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)
}

Expand Down
Loading