ForEachSourceTF

Properties:
configurators  
dependency  
disableHeaderLogging  
logFooter  
logHeader  
sources  
taskExecutor  
taskFactory  

Run action tasks for each entity in a collection.

Package:org.schmant.task.base
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 proxied task using the task factory. The created task is given a source entity and then run.

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

configuratorstop

A collection of Configurator:s. Configurator:s are used to configure a task right before it is run in a TaskExecutor with properties that are not available until all of the task's dependencies have been run.

Build scripts that don't use TaskExecutor:s don't have to use Configurator:s.

Setter method:
addConfigurator(Configurator cf)
where:
  cf – A configurator.
Add one configurator.
Setter method:
addConfigurators(Collection<? extends Configurator> c)
where:
  c – A collection of configurators.
Add a collection of configurators.
dependencytop

If a task executor is used, this property can be set to give all scheduled tasks a dependency.

Setter method:
setDependency(TaskDependency d)
where:
  d –  A dependency for all tasks.
See also:
taskExecutor
disableHeaderLoggingtop

Should header and footer logging from the nested tasks be disabled?

Setter method:
setDisableHeaderLogging(boolean b)
where:
  b – Disable header and footer logging?
Default value:
true (header and footer logging is disabled)
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(java.lang.String s)
where:
  s – The footer message.
Default value:
Empty (no footer message is logged.)
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(java.lang.String s)
where:
  s – The header message.
Default value:
A task class specific message.
sources (required)top

A collection of source entities to run action tasks for.

Setter method:
setSource(java.lang.Object o)
where:
  o – The source. The value is interpreted by the created action task.
Set one source and discard previously set sources.
Setter method:
addSource(java.lang.Object o)
where:
  o – The source. The value is interpreted by the created action task.
Add one source.
Setter method:
addSources(Collection<?> c)
where:
  c – A collection of sources. The values are interpreted by the created action tasks.
Add a collection of sources.
taskExecutortop

If this property is set, all created tasks are added to the executor instead of run right away.

If this task is added to an executor, all nested tasks will be run in the thread running this task. If a task executor is assigned to this property, the nested tasks will be distributed among all threads available to the executor.

Dependencies for the tasks can be set to the dependency property.

Setter method:
setTaskExecutor(TaskExecutor te)
where:
  te –  A task executor.
See also:
dependency
taskFactory (required)top

The factory for creating tasks. A new task object is created for each source entity. The following types of task factories are supported:

Setter method:
setTaskFactory(ActionTaskFactory<?, ?> f)
where:
  f –  The task factory.

Examples

Example 1

Copy every entity in the directory d that matches the glob pattern *.jar to the lib directory.

new ForEachSourceTF().
addSources(Directories.getAllFilesMatching(d, "*.jar")).
setTaskFactory(
new CopyTF().
setTarget(lib)).run();


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.