Run an action task for each entity returned when iterating recursively over a set of source entities.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.meta |
Category: | Meta tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory |
See also: | ForEachSourceTF RecursiveProcessTF ReplaceSourceFileTF |
Description:
Run an action task for each entity returned when iterating recursively over a set of source entities.
The sources property is configured with one or more source directories. When the task is run, it iterates the directories recursively. For each entity (file or directory) it finds, it creates a new task using the task factory. The created task is configured with the found entity as its source.
By default, created tasks are run in the thread running this task. They may also be run by an optional task executor.
Entities in a source directory hierarchy that a proxied task should not be run for can be ignored either by using a DirectoryView that hides the unwanted entities or by using a DirectoryAndFilter. The difference between the two approaches is that when using a DirectoryView, the recursive action task does not iterate down into directories that do not pass the view's EntityFilter(s).
This task is also described in the Schmant User's Guide.
Required properties
Properties
dependency | top |
If a task executor
is used, this property can be set
to give all scheduled tasks a dependency.
- Setter method:
setDependency(TaskDependency d)
parameters:d
– A dependency for all tasks.- See also:
- taskExecutor
disableHeaderLogging | top |
Should header and footer logging from the nested tasks be disabled?
- Setter method:
setDisableHeaderLogging(boolean b)
parameters:b
– Disable header and footer logging?- Default value:
true
(header and footer logging is disabled)
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sources (required) | top |
A collection of source directories and/or files to run recursive action tasks for.
There are two ways that EntityFilter:s can be used to exclude files or directories from being used as source entities to the proxied task:
- Using a DirectoryView as source: This task will only use files and directories that match the view's filter. Furthermore, it will only recurse down into child directories that match the filter.
- Using a DirectoryAndFilter as source: This task will only use files and directories that match the view's filter. It will however recurse down into all child directories of a processed directory.
- Setter method:
addSource(Object o)
Add one or several source files and/or directories.parameters:o
– One source file or directory or several source files and/or directories.
Interpreted byInterpretAsDirectoryStrategy or InterpretAsEFileStrategy
.- Setter method:
addSources(Object o)
Add one or several source files and/or directories.parameters:o
– One source file or directory or several source files and/or directories.
Interpreted byInterpretAsDirectoryStrategy or InterpretAsEFileStrategy
.- Setter method:
clearSources()
Discard all sources.- Setter method:
setSource(Object o)
Set one or several source files and/or directories and discard previously set sources.parameters:o
– One source file or directory or several source files and/or directories.
Interpreted byInterpretAsDirectoryStrategy or InterpretAsEFileStrategy
.- Setter method:
setSources(Object o)
Set one or several source files and/or directories and discard previously set sources.parameters:o
– One source file or directory or several source files and/or directories.
Interpreted byInterpretAsDirectoryStrategy or InterpretAsEFileStrategy
.
taskExecutor | top |
If this property is set, all created tasks are added to the executor instead of run right away.
If this property is not set and this task is added to an executor, all tasks created by this task will be run in the same thread as the task. If this property is set, the tasks will be distributed among all threads that are available to the executor.
Dependencies for the tasks can be set in the dependency
property.
Note: When letting this task schedule tasks that it creates in a task executor, this task object cannot be used as a dependency for the tasks depending on the scheduled tasks. Use the dependency object returned from Task.getDependencyForTasksScheduledByThisTask() instead.
- Setter method:
setTaskExecutor(TaskExecutor te)
parameters:te
– A task executor.- See also:
- dependency
taskFactory (required) | top |
An action task factory or a closure.
If this is an action task factory, a new task object is created for each processed entity.
If this is a closure, the same closure instance will be run for each processed entity. The closure is called with one argument of the type ClosureParameters.
- Setter method:
setTaskFactory(java.lang.Object f)
parameters:
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
Examples
Example 1
Make all script files in a directory hierarchy under
d1
executable.
JavaScript
Example 2
Replace "!!!VERSION!!!" for the contents of the variable
version
in all text files in a directory hierarchy under
d1
. The TextReplaceTF would normally need a
RecursiveProcessTF to be run recursively, but the
ReplaceSourceFileTF is used to apply the modifications directly to
the source files, making the operation an "action" rather than a "process".
JavaScript
Example 3
This does the same as the previous example, but schedules the tasks in a TaskExecutor instead of running them right away.
JavaScript
Example 4
Compress all text and html files in a directory hierarchy
under the directory d
using gzip compression.
Groovy
JavaScript
JRuby
Jython
Example 5
Use a closure to compress all text and html files in a
directory hierarchy under the directory d
using gzip compression,
and then delete the original files.
Groovy
JavaScript
JRuby
Jython
* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.