Copy one or several files 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 target. See below. |
See also: | MoveTF TreeCopyTF RecursiveProcessTF |
Description:
Copy one or several files or directories. Directories are not copied recursively. (See TreeCopyTF.)
This task works as a copy
command. It copies files and directories
according to the following algorithm:
- If one source is set, and
- The target is a directory: copy the source to a new entity of the same type and with the same name as the source in the target directory. The produced object is the new entity.
- The target is a file: Overwrite the target file if our overwrite strategy lets us. The produced object is the overwritten file.
- The target is the name of a nonexisting entity in an existing directory: Create a new entity in the target directory and copy the contents of the source entity to it. The produced object is the new entity.
- If several sources are set, the target must be a directory. Copy the source entities to new entities with the same names in the target directory. The produced object is the target directory.
The overwrite strategy decides if existing entities may be overwritten.
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
preserveAttributes | top |
Should attributes of the source entity, such as its latest modification time, be copied to the target entity?
- Setter method:
setPreserveAttributes(boolean b)
parameters:b
– Should attributes be preserved?- Default value:
false
(attributes are not preserved)
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.
source (required) | top |
The sources of the copy operation.
- Setter method:
addSource(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsReadOnlyEntityStrategy
.- Setter method:
addSources(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsReadOnlyEntityStrategy
.- Setter method:
clearSources()
Clear all sources.- Setter method:
setSource(Object o)
Set one or several sources, discarding all previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsReadOnlyEntityStrategy
.- Setter method:
setSources(Object o)
Set one or several sources, discarding all previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byInterpretAsReadOnlyEntityStrategy
.
target (required) | top |
The target of the copy operation.
- Setter method:
setTarget(Object o)
Set the target.parameters:o
– The target.
Interpreted byInterpretAsFutureEntityStrategy (one source), or |ai:ai_directory:InterpretAsDirectoryStrategy| (several sources)
.- See also:
- overwriteStrategy
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 the file f
to the directory
d
. f
may be an EntityFS EFile or a
Java File. d
may be an EntityFS Directory or
a Java File directory.
JavaScript
Example 2
Copy the file f
to a future entity in a
subdirectory under the directory d
. All nonexisting parent
directories will be created.
Example 3
Copy the file f
to the directory
d
, represented as a FutureDirectory
(this does exactly
the same as example 1)
JavaScript
Example 4
Copy the directory src
to the directory
d
. No child entities in src
will be copied. (This is
just a lengthy way of creating src
in d
.)
JavaScript
Example 5
Copy all files from the directory hierarchy under
d
to the directory flat_d
. (See
ErrorIgnoringTF for a
similar example.)
JavaScript
Example 6
Copy the contents of the URL http://www.vecka.nu/
to the file vecka.html
in the directory d
.
JavaScript
Example 7
Create a property file with information about
the current build. The file is created in the bin/org/example
directory. This can for instance be used by an application to publish
information on how it was built.
JavaScript
Example 8
Copy the files f1
and f2
to the directory
d
. The files may be EntityFS EFile:s or
Java File:s. d
may be an EntityFS Directory or
a Java File directory.
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.