Skip to content
Merged
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
25 changes: 14 additions & 11 deletions wire-gradle-plugin/api/wire-gradle-plugin.api
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
public abstract class com/squareup/wire/gradle/CustomOutput : com/squareup/wire/gradle/WireOutput {
public fun <init> ()V
public final fun exclusive (Z)V
public final fun getExcludes ()Lorg/gradle/api/provider/ListProperty;
public final fun getExclusive ()Lorg/gradle/api/provider/Property;
public final fun getIncludes ()Lorg/gradle/api/provider/ListProperty;
public final fun getOptions ()Lorg/gradle/api/provider/MapProperty;
public final fun getSchemaHandlerFactory ()Lorg/gradle/api/provider/Property;
public final fun getSchemaHandlerFactoryClass ()Lorg/gradle/api/provider/Property;
public final fun options (Ljava/util/Map;)V
public final fun schemaHandlerFactoryClass (Ljava/lang/String;)V
public final fun getExcludes ()Ljava/util/List;
public final fun getExcludesProperty ()Lorg/gradle/api/provider/ListProperty;
public final fun getExclusive ()Z
public final fun getExclusiveProperty ()Lorg/gradle/api/provider/Property;
public final fun getIncludes ()Ljava/util/List;
public final fun getIncludesProperty ()Lorg/gradle/api/provider/ListProperty;
public final fun getOptions ()Ljava/util/Map;
public final fun getOptionsProperty ()Lorg/gradle/api/provider/MapProperty;
public final fun getSchemaHandlerFactory ()Lcom/squareup/wire/schema/SchemaHandler$Factory;
public final fun getSchemaHandlerFactoryClass ()Ljava/lang/String;
public final fun getSchemaHandlerFactoryClassProperty ()Lorg/gradle/api/provider/Property;
public final fun getSchemaHandlerFactoryProperty ()Lorg/gradle/api/provider/Property;
public final fun setExcludes (Ljava/util/List;)V
public final fun setExclusive (Z)V
public final fun setIncludes (Ljava/util/List;)V
Expand Down Expand Up @@ -164,8 +167,8 @@ public final class com/squareup/wire/gradle/WireExtension$ProtoRootSet {
public abstract class com/squareup/wire/gradle/WireOutput {
public fun <init> ()V
protected abstract fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public final fun getOut ()Lorg/gradle/api/provider/Property;
public final fun out (Ljava/lang/String;)V
public final fun getOut ()Ljava/lang/String;
public final fun getOutProperty ()Lorg/gradle/api/provider/Property;
public final fun setOut (Ljava/lang/String;)V
public abstract fun toTarget (Ljava/lang/String;)Lcom/squareup/wire/schema/Target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ abstract class WireOutput {
@get:Inject
protected abstract val objectFactory: ObjectFactory

val out: Property<String> by lazy(NONE) {
val outProperty: Property<String> by lazy(NONE) {
objectFactory.property(String::class.java)
}

/** Set this to override the default output directory for this [WireOutput]. */
fun setOut(value: String?) {
out.set(value)
}

fun out(value: String) {
out.set(value)
}
@Deprecated(
"Use outProperty to support Gradle lazy configuration",
ReplaceWith("outProperty"),
)
var out: String?
get() = outProperty.orNull
set(value) { outProperty.set(value) }

internal fun outputDirectory(
projectDir: File,
defaultOutputDirectory: Provider<String>,
): Provider<String> = out.map { relativizeOutputDirectory(it, projectDir) }.orElse(defaultOutputDirectory)
): Provider<String> = outProperty.map { relativizeOutputDirectory(it, projectDir) }.orElse(defaultOutputDirectory)

/**
* Transforms this [WireOutput] into a [Target] for which Wire will generate code. The [Target]
Expand Down Expand Up @@ -263,91 +263,101 @@ abstract class ProtoOutput @Inject constructor() : WireOutput() {
}

abstract class CustomOutput @Inject constructor() : WireOutput() {
val includes: ListProperty<String> by lazy(NONE) {
val includesProperty: ListProperty<String> by lazy(NONE) {
objectFactory.listProperty(String::class.java)
}

val excludes: ListProperty<String> by lazy(NONE) {
val excludesProperty: ListProperty<String> by lazy(NONE) {
objectFactory.listProperty(String::class.java)
}

val exclusive: Property<Boolean> by lazy(NONE) {
val exclusiveProperty: Property<Boolean> by lazy(NONE) {
objectFactory.property(Boolean::class.java).convention(true)
}

val options: MapProperty<String, String> by lazy(NONE) {
val optionsProperty: MapProperty<String, String> by lazy(NONE) {
objectFactory.mapProperty(String::class.java, String::class.java)
}

val schemaHandlerFactory: Property<SchemaHandler.Factory> by lazy(NONE) {
val schemaHandlerFactoryProperty: Property<SchemaHandler.Factory> by lazy(NONE) {
objectFactory.property(SchemaHandler.Factory::class.java)
}

val schemaHandlerFactoryClass: Property<String> by lazy(NONE) {
val schemaHandlerFactoryClassProperty: Property<String> by lazy(NONE) {
objectFactory.property(String::class.java)
}

/** See [com.squareup.wire.schema.Target.includes] */
fun setIncludes(values: List<String>?) {
includes.set(values)
}
@Deprecated(
"Use includesProperty to support Gradle lazy configuration",
ReplaceWith("includesProperty"),
)
var includes: List<String>?
get() = includesProperty.orNull
set(value) { includesProperty.set(value) }

/** See [com.squareup.wire.schema.Target.excludes] */
fun setExcludes(values: List<String>?) {
excludes.set(values)
}
@Deprecated(
"Use excludesProperty to support Gradle lazy configuration",
ReplaceWith("excludesProperty"),
)
var excludes: List<String>?
get() = excludesProperty.orNull
set(value) { excludesProperty.set(value) }

/** See [com.squareup.wire.schema.Target.exclusive] */
fun setExclusive(value: Boolean) {
exclusive.set(value)
}

fun exclusive(value: Boolean) {
exclusive.set(value)
}

/**
* Black boxed payload which a caller can set for the custom [SchemaHandler.Factory] to receive.
*/
fun options(value: Map<String, String>) {
options.set(value)
}

fun setOptions(value: Map<String, String>?) {
options.set(value)
}
@Deprecated(
"Use exclusiveProperty to support Gradle lazy configuration",
ReplaceWith("exclusiveProperty"),
)
var exclusive: Boolean
get() = exclusiveProperty.orElse(true).get()
set(value) { exclusiveProperty.set(value) }

/** Black boxed payload which a caller can set for the custom [SchemaHandler.Factory] to receive. */
@Deprecated(
"Use optionsProperty to support Gradle lazy configuration",
ReplaceWith("optionsProperty"),
)
var options: Map<String, String>?
get() = optionsProperty.orNull
set(value) { optionsProperty.set(value) }

/** Assign the schema handler factory instance. */
fun setSchemaHandlerFactory(value: SchemaHandler.Factory?) {
schemaHandlerFactory.set(value)
}
@Deprecated(
"Use schemaHandlerFactoryProperty to support Gradle lazy configuration",
ReplaceWith("schemaHandlerFactoryProperty"),
)
var schemaHandlerFactory: SchemaHandler.Factory?
get() = schemaHandlerFactoryProperty.orNull
set(value) { schemaHandlerFactoryProperty.set(value) }

/**
* Assign the schema handler factory by name. If you use a class name, that class must have a
* no-arguments constructor.
*/
fun setSchemaHandlerFactoryClass(value: String?) {
schemaHandlerFactoryClass.set(value)
}

fun schemaHandlerFactoryClass(value: String) {
schemaHandlerFactoryClass.set(value)
}
@Deprecated(
"Use schemaHandlerFactoryClassProperty to support Gradle lazy configuration",
ReplaceWith("schemaHandlerFactoryClassProperty"),
)
var schemaHandlerFactoryClass: String?
get() = schemaHandlerFactoryClassProperty.orNull
set(value) { schemaHandlerFactoryClassProperty.set(value) }

override fun toTarget(outputDirectory: String): CustomTarget {
val configuredSchemaHandlerFactory = schemaHandlerFactory.orNull
val configuredSchemaHandlerFactoryClass = schemaHandlerFactoryClass.orNull
val configuredSchemaHandlerFactory = schemaHandlerFactoryProperty.orNull
val configuredSchemaHandlerFactoryClass = schemaHandlerFactoryClassProperty.orNull

check(configuredSchemaHandlerFactory != null || configuredSchemaHandlerFactoryClass != null) {
"schemaHandlerFactory or schemaHandlerFactoryClass required"
}

return CustomTarget(
includes = includes.orNull ?: listOf("*"),
excludes = excludes.orNull ?: listOf(),
exclusive = exclusive.orElse(true).get(),
includes = includesProperty.orNull ?: listOf("*"),
excludes = excludesProperty.orNull ?: listOf(),
exclusive = exclusiveProperty.orElse(true).get(),
outDirectory = outputDirectory,
options = options.orNull ?: mapOf(),
options = optionsProperty.orNull ?: mapOf(),
schemaHandlerFactory = configuredSchemaHandlerFactory ?: newSchemaHandler(configuredSchemaHandlerFactoryClass!!),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class WirePlugin : Plugin<Project> {
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.isPresent) {
existingProtoOutput.out.set(File(project.libraryProtoOutputPath()).path)
if (!existingProtoOutput.outProperty.isPresent) {
existingProtoOutput.outProperty.set(File(project.libraryProtoOutputPath()).path)
}
} else {
extension.proto { protoOutput ->
protoOutput.out.set(File(project.libraryProtoOutputPath()).path)
protoOutput.outProperty.set(File(project.libraryProtoOutputPath()).path)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class WireOutputProviderTest {
val project = ProjectBuilder.builder().build()
val output = project.objects.newInstance(CustomOutput::class.java)

output.out.set(project.providers.provider { "build/generated/custom-wire" })
output.includes.set(project.providers.provider { listOf("squareup.dinosaurs.Dinosaur") })
output.excludes.set(project.providers.provider { listOf("squareup.geology.Period") })
output.exclusive.set(project.providers.provider { false })
output.options.set(project.providers.provider { mapOf("a" to "one", "b" to "two") })
output.schemaHandlerFactory.set(TestSchemaHandlerFactory())
output.outProperty.set(project.providers.provider { "build/generated/custom-wire" })
output.includesProperty.set(project.providers.provider { listOf("squareup.dinosaurs.Dinosaur") })
output.excludesProperty.set(project.providers.provider { listOf("squareup.geology.Period") })
output.exclusiveProperty.set(project.providers.provider { false })
output.optionsProperty.set(project.providers.provider { mapOf("a" to "one", "b" to "two") })
output.schemaHandlerFactoryProperty.set(TestSchemaHandlerFactory())

assertThat(output.out.orNull).isEqualTo("build/generated/custom-wire")
assertThat(output.outProperty.orNull).isEqualTo("build/generated/custom-wire")

val target = output.toTarget(output.out.get()) as CustomTarget
val target = output.toTarget(output.outProperty.get()) as CustomTarget

assertThat(target.outDirectory).isEqualTo("build/generated/custom-wire")
assertThat(target.includes).containsExactly("squareup.dinosaurs.Dinosaur")
Expand All @@ -59,9 +59,9 @@ class WireOutputProviderTest {
val project = ProjectBuilder.builder().build()
val output = project.objects.newInstance(CustomOutput::class.java)

output.exclusive.set(false)
output.exclusive.set(project.providers.gradleProperty("missing-exclusive").map(String::toBoolean))
output.schemaHandlerFactory.set(TestSchemaHandlerFactory())
output.exclusiveProperty.set(false)
output.exclusiveProperty.set(project.providers.gradleProperty("missing-exclusive").map(String::toBoolean))
output.schemaHandlerFactoryProperty.set(TestSchemaHandlerFactory())

val target = output.toTarget("build/generated/custom-wire") as CustomTarget

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ configure<WireExtension> {
sourcePath("src/main/proto")

custom {
out.set(providers.gradleProperty("wireOut"))
includes.set(providers.provider { listOf(providers.gradleProperty("includeType").get()) })
excludes.set(providers.provider { listOf(providers.gradleProperty("excludeType").get()) })
exclusive.set(providers.provider { providers.gradleProperty("exclusive").get().toBoolean() })
options.set(
outProperty.set(providers.gradleProperty("wireOut"))
includesProperty.set(providers.provider { listOf(providers.gradleProperty("includeType").get()) })
excludesProperty.set(providers.provider { listOf(providers.gradleProperty("excludeType").get()) })
exclusiveProperty.set(providers.provider { providers.gradleProperty("exclusive").get().toBoolean() })
optionsProperty.set(
providers.provider {
mapOf(
"a" to providers.gradleProperty("optionA").get(),
"b" to providers.gradleProperty("optionB").get(),
)
},
)
schemaHandlerFactoryClass.set(providers.gradleProperty("handlerClass"))
schemaHandlerFactoryClassProperty.set(providers.gradleProperty("handlerClass"))
}
}
Loading