Skip to content

Commit

Permalink
Update docs to use ObjectFactory.fileCollection() instead of `Proje…
Browse files Browse the repository at this point in the history
…ctLayout.configurableFiles()`.
  • Loading branch information
adammurdoch committed Feb 4, 2019
1 parent b036a88 commit bce39d5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
23 changes: 15 additions & 8 deletions subprojects/docs/src/docs/release/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ Switch your build to use Gradle 5.3 by updating your wrapper properties:

Standalone downloads are available at [gradle.org/releases](https://gradle.org/releases).

## Improvements for plugin authors

- TBD - Abstract service injection getter methods
- TBD - Abstract mutable property
- TBD - Abstract `ConfigurableFileCollection` property
- TBD - Use an interface for Gradle instantiated types
- TBD - `ObjectFactory.configurableFiles()`

## Feature variants, aka optional dependencies

Gradle now provides a powerful model for declaring features a library provides, known as [feature variants](userguide/feature_variants.html) :
Expand All @@ -43,6 +35,21 @@ dependencies {

Long story short, this can be used to model [optional dependencies](https://github.com/gradle/gradle/issues/867)!

## Improvements for plugin authors

### Use abstract types

- TBD - Abstract service injection getter methods
- TBD - Abstract mutable property
- TBD - Abstract `ConfigurableFileCollection` property
- TBD - Use an interface for Gradle instantiated types

### Factory method for creating `ConfigurableFileCollection` instances using `ObjectFactory`

Plugin and task implementations often need to create instances of various useful types, to provide a configurable model and DSL that is consistent with other Gradle plugins. One such type is `ConfigurableFileCollection`. In previous releases, plugins could use `Project.files()` or `ProjectLayout.configurableFiles()` to create instance of this type. However, these interfaces are not always available, for example in a `Settings` plugin (rather than a `Project` plugin) or in a nested model object.

In this release, plugin authors can use the `ObjectFactory.fileCollection()` method to create instances. The `ObjectFactory` service is used by plugin and task implementations to create objects of various useful types. This now includes instances of `ConfigurableFileCollection`.

## Default JaCoCo version upgraded to 0.8.3

[The JaCoCo plugin](userguide/jacoco_plugin.html) has been upgraded to use [JaCoCo version 0.8.3](http://www.jacoco.org/jacoco/trunk/doc/changes.html) instead of 0.8.2 by default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ include::sample[dir="userguide/dependencyManagement/declaringDependencies/fileDe
As you can see in the code example, every dependency has to define its exact location in the file system.
The most prominent methods for creating a file reference are
link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)],
link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object...)],
link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(java.lang.Object...)], and
link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:fileTree(java.lang.Object)[Project.fileTree(java.lang.Object)]
link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object...)]
and link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:fileTree(java.lang.Object)[Project.fileTree(java.lang.Object)]
Alternatively, you can also define the source directory of one or many file dependencies in the form of a <<repository_types.adoc#sec:flat_dir_resolver,flat directory repository>>.

[[sec:declaring_project_dependency]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ link:{javadocPath}/org/gradle/api/file/DirectoryProperty.html[DirectoryProperty]

link:{javadocPath}/org/gradle/api/file/ConfigurableFileCollection.html[ConfigurableFileCollection]:: Unstructured collection of files
Factories;;
* link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(Object++...++)]
* link:{javadocPath}/org/gradle/api/model/ObjectFactory.html#fileCollection--[ObjectFactory.fileCollection()]

link:{javadocPath}/org/gradle/api/file/ConfigurableFileTree.html[ConfigurableFileTree]:: Hierarchy of files
Factories;;
Expand Down
8 changes: 4 additions & 4 deletions subprojects/docs/src/docs/userguide/more_about_tasks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ Things like strings and numbers. More generally, a simple value can have any typ

* Filesystem types
+
These consist of the standard `File` class but also derivatives of Gradle’s link:{javadocPath}/org/gradle/api/file/FileCollection.html[FileCollection] type and anything else that can be passed to either the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)[Project.file(java.lang.Object)] method - for single file/directory properties - or the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object++...++)], link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object...)], and link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(java.lang.Object...)] methods.
These consist of the standard `File` class but also derivatives of Gradle’s link:{javadocPath}/org/gradle/api/file/FileCollection.html[FileCollection] type and anything else that can be passed to either the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)[Project.file(java.lang.Object)] method - for single file/directory properties - or the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object++...++)] method.

* Nested values
+
Expand Down Expand Up @@ -660,7 +660,7 @@ Using a file tree turns <<build_cache.adoc#sec:task_output_caching, caching>> of
====
[horizontal]
+++*+++::
In fact, `File` can be any type accepted by link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)[Project.file(java.lang.Object)] and `Iterable&lt;File&gt;` can be any type accepted by link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)], link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object++...++)], or link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(java.lang.Object++...++)].
In fact, `File` can be any type accepted by link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)[Project.file(java.lang.Object)] and `Iterable&lt;File&gt;` can be any type accepted by link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)].
This includes instances of `Callable`, such as closures, allowing for lazy evaluation of the property values.
Be aware that the types `FileCollection` and `FileTree` are ``Iterable&lt;File&gt;``s.
+++**+++::
Expand Down Expand Up @@ -1049,7 +1049,7 @@ include::{samplesPath}/userguide/tasks/incrementalBuild/incrementalBuildAdvanced
----
====

Alternatively, you can get Gradle to access the appropriate property itself by using one of `project.files()`, `project.layout.files()` or `project.layout.configurableFiles()` in place of `project.fileTree()`:
Alternatively, you can get Gradle to access the appropriate property itself by using one of `project.files()`, `project.layout.files()` or `project.objects.fileCollection()` in place of `project.fileTree()`:

.Setting up an inferred task dependency with `layout.files()`
====
Expand All @@ -1063,7 +1063,7 @@ include::{samplesPath}/userguide/tasks/incrementalBuild/incrementalBuildAdvanced
----
====

Remember that `files()`, `layout.files()` and `layout.configurableFiles()` can take tasks as arguments, whereas `fileTree()` cannot.
Remember that `files()`, `layout.files()` and `objects.fileCollection()` can take tasks as arguments, whereas `fileTree()` cannot.

The downside of this approach is that all file outputs of the source task become the input files of the target - `instrumentClasses` in this case. That’s fine as long as the source task only has a single file-based output, like the `JavaCompile` task. But if you have to link just one output property among several, then you need to explicitly tell Gradle which task generates the input files using the `builtBy` method:

Expand Down
4 changes: 2 additions & 2 deletions subprojects/docs/src/docs/userguide/working_with_files.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ As with filtering, you can also apply renaming to a subset of files by configuri
== Deleting files and directories

You can easily delete files and directories using either the link:{groovyDslPath}/org.gradle.api.tasks.Delete.html[Delete] task or the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:delete(org.gradle.api.Action)[Project.delete(org.gradle.api.Action)] method.
In both cases, you specify which files and directories to delete in a way supported by the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)], link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object...)], and link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(java.lang.Object...)] methods.
In both cases, you specify which files and directories to delete in a way supported by the link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)] method.

For example, the following task deletes the entire contents of a build's output directory:

Expand Down Expand Up @@ -525,7 +525,7 @@ Not only does `from()` accept multiple arguments, it also allows several differe
* A `FileCollection` or `FileTree` — all files in the collection are included in the copy
* A task — the files or directories that form a task's <<more_about_tasks.adoc#sec:task_inputs_outputs,defined outputs>> are included

In fact, `from()` accepts all the same arguments as link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)], link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#files-java.lang.Object++...++-[ProjectLayout.files(java.lang.Object...)], and link:{javadocPath}/org/gradle/api/file/ProjectLayout.html#configurableFiles-java.lang.Object++...++-[ProjectLayout.configurableFiles(java.lang.Object...)], so see those methods for a more detailed list of acceptable types.
In fact, `from()` accepts all the same arguments as link:{groovyDslPath}/org.gradle.api.Project.html#org.gradle.api.Project:files(java.lang.Object++[]++)[Project.files(java.lang.Object...)] so see that method for a more detailed list of acceptable types.

Something else to consider is what type of thing a file path refers to:

Expand Down

0 comments on commit bce39d5

Please sign in to comment.