Source Code

Functions and Task wrappers to copy / delete files and directories.

Delete

This module provides two functions to delete files and directories.

  • deletePath: function to delete files / directories that can be used in your own tasks
  • delete: function creating a wrapper Task for deletePath function

Here is an example of a task which will delete "modules" directory.

Task cleanTarget = delete {
    path = parsePath("modules");
};

A filter can be added to that task to only delete files with extensions "car" and "car.sha1"

Task cleanTarget = delete {
    path = parsePath("modules");
    filter = extensions("car", "car.sha1");
};

Copy

This module provides two functions to copy files and directories.

  • copyFiles: function to copy files / directories that can be used in your own tasks
  • copy: function creating a wrapper Task for copyFiles function

Here is an example of a task which will copy file "modules/mymodule/1.0.0/module-1.0.0.car" to "container/modules".

Task deploy = copy {
    source = parsePath("modules/mymodule/1.0.0/module-1.0.0.car");
    destination = parsePath("container/modules");
};

Note that copy acts the same way as the cp Unix command when a single file is given in input

  • If the destination is a directory, it will copy the file under the destination directory. (modules/mymodule/1.0.0/module-1.0.0.car -> "container/modules/module-1.0.0.car in our example)
  • If the destination is a file it will overwrite it or fail depending of overwrite configuration (modules/mymodule/1.0.0/module-1.0.0.car -> "container/modules" in our example)
  • If the destination doesn't exist, it will use copy input file to destination (modules/mymodule/1.0.0/module-1.0.0.car -> "container/modules" in our example)

A directory can also be copied recursively as below

Task deploy = copy {
    source = parsePath("modules");
    destination = parsePath("container/modules");
    filter = extensions("car");
};
License: [ASL 2.0](http://www.apache.org/licenses/LICENSE-2.0)
Packages
ceylon.build.tasks.file

Tasks to delete / copy files and folders

Dependencies
ceylon.build.task1.0.0
ceylon.file1.0.0

Tasks to delete / copy files and folders

Aliases
FileFilterSource Code
shared FileFilter=> Boolean(File)

A FileFilter is a function that returns true when the file given in input match the filter

See also: extensions
Values
allFilesSource Code
shared FileFilter allFiles

Returns a FileFilter that will match all files

Functions
copySource Code
shared Task copy(Path source, Path destination, Boolean overwrite = false, FileFilter filter = ...)

Returns a Task to copy files and directories from source to destination using copyFiles

Parameters:
  • source

    Source path from where files will be taken

  • destination

    Destination path where files will be copied

  • overwrite = false

    If true, will overwrite already existing files. If false and a file with a same name already exist in destination, FileCopyException will be raised

  • filter = allFiles

    Copy FileFilter has to return true to copy files, false not to copy them

See also: copyFiles
copyFilesSource Code
shared void copyFiles(Path source, Path destination, Boolean overwrite = false, FileFilter filter = ...)

Copies files and directories from source to destination

All files in source matching filter will be copied to same relative path from source into destination.

If destination doesn't exist, it will attempt to create missing directories.

This function acts the same way as the cp Unix command does when a single file is given in input. This means that if destination exists and is a directory, source file will be copied under that directory. Otherwise, it will be copied directly to destination path.

This has implications on missing directories creation process:

  • In case source is a Directory: will create destination directory.

For example, if destination is set to "foo/bar/baz" but only "foo" exists, directories "foo/bar" and "foo/bar/baz" will be created.

  • In case source is a File: will create missing directories until destination's parent directory included.

For example, if destination is set to "foo/bar/baz" but only "foo" exists, directory "foo/bar" will be created.

Parameters:
  • source

    Source path from where files will be taken

  • destination

    Destination path where files will be copied

  • overwrite = false

    If true, will overwrite already existing files. If false and a file with a same name already exist in destination, FileCopyException will be raised

  • filter = allFiles

    Copy FileFilter has to return true to copy files, false not to copy them

Throws:
  • FileCopyException

    When files with same names already exists in destination and overwrite is set to false

  • CreateDirectoryException

    If destination doesn't exist and can't be created because parent element in path is not a Directory

createDirectorySource Code
shared void createDirectory(Resource directory)

Recursivley create directory

Throws:
deleteSource Code
shared Task delete(Path path, FileFilter filter = ...)

Returns a Task to delete files and directories inside path (path included) using deletePath

Parameters:
  • path

    Path to recursively delete

  • filter = allFiles

    Delete FileFilter has to return true to delete files, false to keep them

deletePathSource Code
shared void deletePath(Path path, FileFilter filter = ...)

Delete files and directories inside path (path included)

All files in path matching filter will be deleted.

If some files in a directory don't match filter, those files won't be deleted. As a consequence, parent directory will not be deleted too

Parameters:
  • path

    Path to recursively delete

  • filter = allFiles

    Delete FileFilter has to return true to delete files, false to keep them

extensionsSource Code
shared FileFilter extensions(String[] extensions)

Returns a FileFilter that will return true when given file extension is in extensions

Exceptions
CreateDirectoryExceptionSource Code

Exception thrown when a directory cannot be created

FileCopyExceptionSource Code

Exception thrown when a file cannot be copied

IOExceptionSource Code

Base IO exception