Run an action task for each entity in a collection.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.meta |
Category: | Meta tasks |
Since: | 0.6 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory |
See also: | RecursiveActionTF RecursiveProcessTF |
Description:
Run an action task for each entity in a source collection.
For each entity (file or directory), it creates a new task
using the task factory. The entity is
assigned to the created task's source
property.
By default, nested tasks are run in the thread running this task. They may also be run by an optional task executor.
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 entities to run 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 sources.parameters:o
– One source or an array or collection of sources. The value is interpreted by the created action task.- Setter method:
addSources(Object o)
Add one or several sources.parameters:o
– One source or an array or collection of sources. The value is interpreted by the created action task.- Setter method:
clearSources()
Discard all sources.- Setter method:
setSource(Object o)
Set one or several sources and discard previously set sources.parameters:o
– One source or an array or collection of sources. The value is interpreted by the created action task.- Setter method:
setSources(Object o)
Set one or several sources and discard previously set sources.parameters:o
– One source or an array or collection of sources. The value is interpreted by the created action task.
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 |
The factory for creating tasks, or a closure to run for each processed entity.
If this is a task factory, a new task object is created for each source entity. The following types of task factories are supported:
- ActionTaskFactory
- ProcessTaskFactory with
its
target
property set.
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:f
– A task factory or a closure.
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
Copy every entity in the directory d
that
matches the glob pattern *.jar
to the lib
directory.
JavaScript
Example 2
Copy every entity in the directory d
that
matches the glob pattern *.jar
to the lib
directory,
using a closure.
Groovy
JavaScript
JRuby
* 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.