Class FileTreeBuilder
- All Implemented Interfaces:
Generator, Renamable, ResourceProvider
A provider that generates a FileTree from existing file trees.
In general, copying file trees should be avoided. However, in some
situations a resource provider and a consumer cannot be configured
so that the output of the former can be used directly by the latter.
The provider generates a FileTree in the directory specified
with into(Path) by copying files from the sources defined with one
of the source-methods. The class is not named Copier
because the specification of FileTreeBuilder.Sources supports transformations
beyond simply copying.
The provider generates the FileTree in response to a request that
matches the one set with requestForResult. The content of the
generated file tree is returned using the type specified in the
request.
A request for Cleanliness deletes the directory specified with
into(Path).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescribes a source that contributes files to the generated tree. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(Stream<FileTreeBuilder.Source> sources) Adds the givenStreamofFileTreeBuilder.Sourcespecifications.add(FileTreeBuilder.Source source) Adds the givenFileTreeBuilder.Sourcespecification.protected <T extends Resource>
Collection<T> doProvide(ResourceRequest<T> request) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.Sets the destination directory for the generated file tree.provideResources(ResourceRequest<? extends FileTree<?>> proto) Configures the request that this builder responds to by providing the generated file tree.Convenience method for adding aFileTreeBuilder.Sourcewithout renaming or filter to the sources.source(Path root, String pattern, Function<Path, Path> renamer, BiConsumer<InputStream, OutputStream> filter) Convenience method for adding aFileTreeBuilder.Sourcewith optional renaming and filtering to the sources.Methods inherited from class AbstractGenerator
cleanup, name, project, toStringMethods inherited from class AbstractProvider
context, name, of, rename, vavrStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
context, name, of, resources
-
Constructor Details
-
FileTreeBuilder
Initializes a new file tree builder.- Parameters:
project- the project
-
-
Method Details
-
add
Adds the givenStreamofFileTreeBuilder.Sourcespecifications.- Parameters:
sources- the sources- Returns:
- the file tree builder
-
add
Adds the givenFileTreeBuilder.Sourcespecification.- Parameters:
source- the source- Returns:
- the file tree builder
-
source
Convenience method for adding aFileTreeBuilder.Sourcewithout renaming or filter to the sources. Ifrootis a relative path, it is resolved against the project's directory.- Parameters:
root- the rootpattern- the pattern- Returns:
- the file tree builder
-
source
public FileTreeBuilder source(Path root, String pattern, Function<Path, Path> renamer, BiConsumer<InputStream, OutputStream> filter) Convenience method for adding aFileTreeBuilder.Sourcewith optional renaming and filtering to the sources. Ifrootis a relative path, it is resolved against the project's directory.- Parameters:
root- the rootpattern- the patternrenamer- the renamer (may benull)filter- the filter (may benull)- Returns:
- the file tree builder
-
into
Sets the destination directory for the generated file tree. If the destination is relative, it is resolved against the project's directory.- Parameters:
destination- the destination- Returns:
- the file tree builder
-
provideResources
Configures the request that this builder responds to by providing the generated file tree.- Parameters:
proto- a prototype request describing the requests that the provider should respond to- Returns:
- the file tree builder
-
doProvide
Description copied from class:AbstractProviderInvoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.- Specified by:
doProvidein classAbstractProvider- Type Parameters:
T- the generic type- Parameters:
request- the request for resources- Returns:
- the stream
-