Move and/or rename one or several files and/or directories.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.io |
Category: | I/O tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory GeneratorTaskFactory ProcessTaskFactory |
Produces: | The moved entity if only one entity is moved, or the target directory if several entities are moved. |
See also: | RecursiveActionTF RecursiveProcessTF |
Description:
Move and/or rename one or several files and/or directories.
If the target is a directory all source entities are moved into it. If only one file or directory should be moved and also renamed, the target can be a nonexisting FutureEntity. If several entities should be moved and renamed, use a FutureEntityStrategy as target.
Often it is easier to call Entities.move directly. This can be used if a build script wants to schedule a task for moving an entity that has not been created yet, or together with a RecursiveActionTF to move files recursively.
Required properties
Properties
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
overwriteStrategy | top |
The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.
If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.
Non-empty directories are never overwritten, regardless of the chosen strategy.
- Setter method:
setOverwrite(boolean b)
Setting this to a value ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.b
– Should an existing entity be overwritten?- Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.parameters:strat
– The overwrite strategy.- Default value:
- DontOverwriteAndThrowException
- See also:
- target
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 files and/or directories to move.
- Setter method:
addSource(Object o)
Add one or several sources.parameters:o
– One source object or an array or collection of source objects.
Interpreted byInterpretAsEntityStrategy
.- Setter method:
addSources(Object o)
Add one or several sources.parameters:o
– One source object or an array or collection of source objects.
Interpreted byInterpretAsEntityStrategy
.- 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 object or an array or collection of source objects.
Interpreted byInterpretAsEntityStrategy
.- Setter method:
setSources(Object o)
Set one or several sources and discard previously set sources.parameters:o
– One source object or an array or collection of source objects.
Interpreted byInterpretAsEntityStrategy
.
target (required) | top |
The target. If only one entity is moved, this may be a target directory or the location where the entity should be moved (expressed as a File or a FutureEntity). If several entities are moved, this must be a File directory or a DirectoryView.
- Setter method:
setTarget(Object o)
parameters:o
– The target directory or future entity.
Interpreted byInterpretAsFutureEntityStrategy (one source) or InterpretAsDirectoryStrategy (several sources)
.
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
See RecursiveProcessTF for an example of how files in a directory hierarchy can be moved and renamed.Example 1
Move all Java files in the directory hierarchy under
d
to the jDir
directory.
JavaScript
Example 2
Move all Java files in the directory hierarchy under
d
to a directory hierarchy under jDir
.
The difference between this example and the previous example is that this
example uses a RecursiveProcessTF where the previous example used a
RecursiveActionTF. When using a RecursiveProcessTF, all processed
objects get their individual target location decided by that task's
targetStrategy
.
JavaScript
* 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.