diff --git a/wire-gradle-plugin/api/wire-gradle-plugin.api b/wire-gradle-plugin/api/wire-gradle-plugin.api index 5081b9b627..b9313b1b0a 100644 --- a/wire-gradle-plugin/api/wire-gradle-plugin.api +++ b/wire-gradle-plugin/api/wire-gradle-plugin.api @@ -1,14 +1,17 @@ public abstract class com/squareup/wire/gradle/CustomOutput : com/squareup/wire/gradle/WireOutput { public fun ()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 @@ -164,8 +167,8 @@ public final class com/squareup/wire/gradle/WireExtension$ProtoRootSet { public abstract class com/squareup/wire/gradle/WireOutput { public fun ()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; } diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt index dbbda368ff..0b81414dff 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt @@ -43,23 +43,23 @@ abstract class WireOutput { @get:Inject protected abstract val objectFactory: ObjectFactory - val out: Property by lazy(NONE) { + val outProperty: Property 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, - ): Provider = out.map { relativizeOutputDirectory(it, projectDir) }.orElse(defaultOutputDirectory) + ): Provider = outProperty.map { relativizeOutputDirectory(it, projectDir) }.orElse(defaultOutputDirectory) /** * Transforms this [WireOutput] into a [Target] for which Wire will generate code. The [Target] @@ -263,91 +263,101 @@ abstract class ProtoOutput @Inject constructor() : WireOutput() { } abstract class CustomOutput @Inject constructor() : WireOutput() { - val includes: ListProperty by lazy(NONE) { + val includesProperty: ListProperty by lazy(NONE) { objectFactory.listProperty(String::class.java) } - val excludes: ListProperty by lazy(NONE) { + val excludesProperty: ListProperty by lazy(NONE) { objectFactory.listProperty(String::class.java) } - val exclusive: Property by lazy(NONE) { + val exclusiveProperty: Property by lazy(NONE) { objectFactory.property(Boolean::class.java).convention(true) } - val options: MapProperty by lazy(NONE) { + val optionsProperty: MapProperty by lazy(NONE) { objectFactory.mapProperty(String::class.java, String::class.java) } - val schemaHandlerFactory: Property by lazy(NONE) { + val schemaHandlerFactoryProperty: Property by lazy(NONE) { objectFactory.property(SchemaHandler.Factory::class.java) } - val schemaHandlerFactoryClass: Property by lazy(NONE) { + val schemaHandlerFactoryClassProperty: Property by lazy(NONE) { objectFactory.property(String::class.java) } /** See [com.squareup.wire.schema.Target.includes] */ - fun setIncludes(values: List?) { - includes.set(values) - } + @Deprecated( + "Use includesProperty to support Gradle lazy configuration", + ReplaceWith("includesProperty"), + ) + var includes: List? + get() = includesProperty.orNull + set(value) { includesProperty.set(value) } /** See [com.squareup.wire.schema.Target.excludes] */ - fun setExcludes(values: List?) { - excludes.set(values) - } + @Deprecated( + "Use excludesProperty to support Gradle lazy configuration", + ReplaceWith("excludesProperty"), + ) + var excludes: List? + 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) { - options.set(value) - } - - fun setOptions(value: Map?) { - 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? + 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!!), ) } 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 fbff3d7eba..0969536ca6 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 @@ -84,12 +84,12 @@ class WirePlugin : Plugin { 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.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) } } } diff --git a/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WireOutputProviderTest.kt b/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WireOutputProviderTest.kt index 73abf8a78c..16054d6d82 100644 --- a/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WireOutputProviderTest.kt +++ b/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WireOutputProviderTest.kt @@ -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") @@ -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 diff --git a/wire-gradle-plugin/src/test/projects/custom-output-provider-kotlin-dsl/build.gradle.kts b/wire-gradle-plugin/src/test/projects/custom-output-provider-kotlin-dsl/build.gradle.kts index 29b1fb1d77..799d71d12c 100644 --- a/wire-gradle-plugin/src/test/projects/custom-output-provider-kotlin-dsl/build.gradle.kts +++ b/wire-gradle-plugin/src/test/projects/custom-output-provider-kotlin-dsl/build.gradle.kts @@ -23,11 +23,11 @@ configure { 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(), @@ -35,6 +35,6 @@ configure { ) }, ) - schemaHandlerFactoryClass.set(providers.gradleProperty("handlerClass")) + schemaHandlerFactoryClassProperty.set(providers.gradleProperty("handlerClass")) } }