Index: subprojects/docs/src/docs/userguide/custom_gradle_types.adoc =================================================================== diff -u -N -ra8cbd0b8de09ef184d16b7cfd1ceba66337880b8 -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/docs/userguide/custom_gradle_types.adoc (.../custom_gradle_types.adoc) (revision a8cbd0b8de09ef184d16b7cfd1ceba66337880b8) +++ subprojects/docs/src/docs/userguide/custom_gradle_types.adoc (.../custom_gradle_types.adoc) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -99,7 +99,7 @@ Note that for a property to be considered a read only managed property, _all_ of the property's getter methods must be `abstract` and have `public` or `protected` visibility. The property must not have any setter methods. -In addition, the property must have one of the following types: +In addition, the property type must have one of the following: - `Property` - `RegularFileProperty` @@ -124,25 +124,25 @@ This pattern is useful when a custom type has a nested complex type which has the same lifecycle. If the lifecycle is different, consider using `Property` instead. -Here is an example of a task type with a `resource` property: +Here is an example of a task type with a `resource` property. The `Resource` type is also a custom Gradle type and defines some managed properties: .Read-only managed nested property ==== [source.multi-language-sample,java] .Download.java ---- -include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Download.java[tags=url-process] -include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Resource.java[tags=host-and-path] +include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Download.java[tags=download] +include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Resource.java[tags=resource] ---- [source.multi-language-sample,kotlin] .Download.kt ---- -include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/kotlin/buildSrc/src/main/kotlin/Download.kt[tags=url-process] +include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/kotlin/buildSrc/src/main/kotlin/Download.kt[tags=download] ---- [source.multi-language-sample,groovy] .Download.groovy ---- -include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/groovy/buildSrc/src/main/groovy/Download.groovy[tags=url-process] +include::{samplesPath}/userguide/plugins/readOnlyNestedProperty/groovy/buildSrc/src/main/groovy/Download.groovy[tags=download] ---- ==== @@ -163,7 +163,7 @@ Each decorated instance implements link:{javadocPath}/org/gradle/api/plugins/ExtensionAware.html[ExtensionAware], and so can have extension objects attached to it. -Note that plugins and container elements are currently not decorated, due to backwards compatibility issues. +Note that plugins and the elements of containers created using link:{javadocPath}/org/gradle/api/Project.html#container-java.lang.Class-[Project.container()] are currently not decorated, due to backwards compatibility issues. [[service_injection]] == Service injection @@ -181,7 +181,7 @@ - link:{javadocPath}/org/gradle/api/file/ProjectLayout.html[ProjectLayout] - Provides access to key project locations. See <> for more details. - link:{javadocPath}/org/gradle/api/provider/ProviderFactory.html[ProviderFactory] - Creates `Provider` instances. See <> for more details. - link:{javadocPath}/org/gradle/workers/WorkerExecutor.html[WorkerExecutor] - Allows a task to run work in parallel. See <> for more details. -- link:{javadocPath}/org/gradle/api/files/FileSystemOperations.html[FileSystemOperations] - Allows a task to run operations on the filesystem such as deleting files, copying files or syncing directories. +- link:{javadocPath}/org/gradle/api/file/FileSystemOperations.html[FileSystemOperations] - Allows a task to run operations on the filesystem such as deleting files, copying files or syncing directories. - link:{javadocPath}/org/gradle/process/ExecOperations.html[ExecOperations] - Allows a task to run external processes with dedicated support for running external `java` programs. === Constructor injection @@ -247,29 +247,32 @@ == Creating nested objects A custom Gradle type can use the link:{javadocPath}/org/gradle/api/model/ObjectFactory.html[ObjectFactory] service to create instances of Gradle types to use for its property values. -These instances can make use of the features discussed in this chapter, allowing you to create 'nested' instances and a nested DSL. +These instances can make use of the features discussed in this chapter, allowing you to create 'nested' object and a nested DSL. You can also have Gradle create nested objects for you by using a <>. In the following example, a project extension receives an `ObjectFactory` instance through its constructor. -The constructor uses this to create a nested `Resources` object (also a custom Gradle type) and makes this object available through the `resources` property. +The constructor uses this to create a nested `Resource` object (also a custom Gradle type) and makes this object available through the `resource` property. .Nested object creation ==== [source.multi-language-sample,java] .DownloadExtension.java ---- include::{samplesPath}/userguide/plugins/nestedObjects/java/buildSrc/src/main/java/DownloadExtension.java[] +include::{samplesPath}/userguide/plugins/nestedObjects/java/buildSrc/src/main/java/Resource.java[tags=resource] ---- [source.multi-language-sample,kotlin] .DownloadExtension.kt ---- include::{samplesPath}/userguide/plugins/nestedObjects/kotlin/buildSrc/src/main/kotlin/DownloadExtension.kt[] +include::{samplesPath}/userguide/plugins/nestedObjects/kotlin/buildSrc/src/main/kotlin/Resource.kt[tags=resource] ---- [source.multi-language-sample,groovy] .DownloadExtension.groovy ---- include::{samplesPath}/userguide/plugins/nestedObjects/groovy/buildSrc/src/main/groovy/DownloadExtension.groovy[] +include::{samplesPath}/userguide/plugins/nestedObjects/groovy/buildSrc/src/main/groovy/Resource.groovy[tags=resource] ---- ==== @@ -305,16 +308,19 @@ .DownloadExtension.java ---- include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/java/buildSrc/src/main/java/DownloadExtension.java[] +include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/java/buildSrc/src/main/java/Resource.java[tags=resource] ---- [source.multi-language-sample,kotlin] .DownloadExtension.kt ---- include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/kotlin/buildSrc/src/main/kotlin/DownloadExtension.kt[] +include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/kotlin/buildSrc/src/main/kotlin/Resource.kt[tags=resource] ---- [source.multi-language-sample,groovy] .DownloadExtension.groovy ---- include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/groovy/buildSrc/src/main/groovy/DownloadExtension.groovy[] +include::{samplesPath}/userguide/plugins/namedDomainObjectContainer/groovy/buildSrc/src/main/groovy/Resource.groovy[tags=resource] ---- ==== Index: subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/groovy/buildSrc/src/main/groovy/Resource.groovy =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/groovy/buildSrc/src/main/groovy/Resource.groovy (.../Resource.groovy) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/groovy/buildSrc/src/main/groovy/Resource.groovy (.../Resource.groovy) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,10 +1,14 @@ +// tag::resource[] class Resource { + // Type must have a 'name' property, which should be read-only final String name URI uri String userName + // Type must have a public constructor that takes the element name as a parameter Resource(String name) { this.name = name } } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/java/buildSrc/src/main/java/Resource.java =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,32 +1,34 @@ import java.net.URI; +// tag::resource[] public class Resource { private final String name; private URI uri; private String userName; + // Type must have a public constructor that takes the element name as a parameter public Resource(String name) { this.name = name; } + // Type must have a 'name' property, which should be read-only public String getName() { return name; } public URI getUri() { return uri; } - public void setUri(URI uri) { this.uri = uri; } public String getUserName() { return userName; } - public void setUserName(String userName) { this.userName = userName; } } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/kotlin/buildSrc/src/main/kotlin/Resource.kt =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/kotlin/buildSrc/src/main/kotlin/Resource.kt (.../Resource.kt) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/namedDomainObjectContainer/kotlin/buildSrc/src/main/kotlin/Resource.kt (.../Resource.kt) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,6 +1,10 @@ import java.net.URI +// tag::resource[] +// Type must have a public constructor that takes the element name as a parameter +// Type must have a 'name' property, which should be read-only open class Resource(val name: String) { var uri: URI? = null var userName: String? = null } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/nestedObjects/groovy/buildSrc/src/main/groovy/Resource.groovy =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/nestedObjects/groovy/buildSrc/src/main/groovy/Resource.groovy (.../Resource.groovy) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/nestedObjects/groovy/buildSrc/src/main/groovy/Resource.groovy (.../Resource.groovy) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,4 +1,6 @@ +// tag::resource[] class Resource { URI uri } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/nestedObjects/java/buildSrc/src/main/java/Resource.java =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/nestedObjects/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/nestedObjects/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,13 +1,14 @@ import java.net.URI; +// tag::resource[] public class Resource { private URI uri; public URI getUri() { return uri; } - public void setUri(URI uri) { this.uri = uri; } } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/nestedObjects/kotlin/buildSrc/src/main/kotlin/Resource.kt =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/nestedObjects/kotlin/buildSrc/src/main/kotlin/Resource.kt (.../Resource.kt) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/nestedObjects/kotlin/buildSrc/src/main/kotlin/Resource.kt (.../Resource.kt) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,5 +1,7 @@ import java.net.URI +// tag::resource[] open class Resource { var uri: URI? = null } +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/groovy/buildSrc/src/main/groovy/Download.groovy =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/groovy/buildSrc/src/main/groovy/Download.groovy (.../Download.groovy) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/groovy/buildSrc/src/main/groovy/Download.groovy (.../Download.groovy) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -4,7 +4,7 @@ import org.gradle.api.tasks.Nested import org.gradle.api.tasks.TaskAction -// tag::url-process[] +// tag::download[] abstract class Download extends DefaultTask { // Use an abstract getter method annotated with @Nested @Nested @@ -23,4 +23,4 @@ @Input Property getPath() } -// end::url-process[] +// end::download[] Index: subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Download.java =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Download.java (.../Download.java) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Download.java (.../Download.java) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -2,7 +2,7 @@ import org.gradle.api.tasks.Nested; import org.gradle.api.tasks.TaskAction; -// tag::url-process[] +// tag::download[] public abstract class Download extends DefaultTask { // Use an abstract getter method annotated with @Nested @Nested @@ -14,4 +14,4 @@ System.out.println("Downloading https://" + getResource().getHostName().get() + "/" + getResource().getPath().get()); } } -// end::url-process[] +// end::download[] Index: subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Resource.java =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/java/buildSrc/src/main/java/Resource.java (.../Resource.java) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -1,12 +1,11 @@ import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; +// tag::resource[] -// tag::host-and-path[] - public interface Resource { @Input Property getHostName(); @Input Property getPath(); } -// end::host-and-path[] +// end::resource[] Index: subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/kotlin/buildSrc/src/main/kotlin/Download.kt =================================================================== diff -u -N -r2ea4b1f849ca163e9169fa232b034008666b5f8d -rcbb8f5f78c3f033e7180c2b452a80b90e2b515fc --- subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/kotlin/buildSrc/src/main/kotlin/Download.kt (.../Download.kt) (revision 2ea4b1f849ca163e9169fa232b034008666b5f8d) +++ subprojects/docs/src/samples/userguide/plugins/readOnlyNestedProperty/kotlin/buildSrc/src/main/kotlin/Download.kt (.../Download.kt) (revision cbb8f5f78c3f033e7180c2b452a80b90e2b515fc) @@ -4,7 +4,7 @@ import org.gradle.api.tasks.Nested import org.gradle.api.tasks.TaskAction -// tag::url-process[] +// tag::download[] abstract class Download : DefaultTask() { // Use an abstract getter method annotated with @Nested @get:Nested @@ -23,4 +23,4 @@ @get:Input val path: Property } -// end::url-process[] +// end::download[]