|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD |
public interface Script
This interface is implemented by all Gradle scripts to add in some Gradle-specific methods. As your compiled script class will implement this interface, you can use the methods and properties declared by this interface directly in your script.
Generally, a Script object will have a delegate object attached to it. For example, a build script will have a Project instance attached to it, and an initialization script will have a Gradle instance attached to it. Any property reference or method call which is not found on this Script object is forwarded to the delegate object.
Method Summary | |
---|---|
void
|
apply(Closure closure)
|
void
|
apply(Map options)
|
void
|
buildscript(Closure configureClosure)
Configures the classpath for this script. |
WorkResult
|
copy(Closure closure)
Copy the specified files. |
CopySpec
|
copySpec(Closure closure)
Creates a CopySpec which can later be used to copy files or create an archive. |
boolean
|
delete(Object... paths)
Deletes files and directories. |
ExecResult
|
exec(Closure closure)
Executes an external command. |
File
|
file(Object path)
|
File
|
file(Object path, PathValidation validation)
|
ConfigurableFileTree
|
fileTree(Object baseDir)
|
ConfigurableFileTree
|
fileTree(Map args)
|
ConfigurableFileTree
|
fileTree(Closure closure)
|
ConfigurableFileTree
|
fileTree(Object baseDir, Closure configureClosure)
|
ConfigurableFileCollection
|
files(Object... paths)
|
ConfigurableFileCollection
|
files(Object paths, Closure configureClosure)
|
ScriptHandler
|
getBuildscript()
Returns the script handler for this script. |
Logger
|
getLogger()
Returns the logger for this script. |
LoggingManager
|
getLogging()
Returns the LoggingManager which can be used to control the logging level and standard output/error capture for this script. |
ResourceHandler
|
getResources()
Provides access to resource-specific utility methods, for example factory methods that create various resources. |
ExecResult
|
javaexec(Closure closure)
Executes a Java main class. |
File
|
mkdir(Object path)
Creates a directory and returns a file pointing to it. |
String
|
relativePath(Object path)
|
FileTree
|
tarTree(Object tarPath)
Creates a new FileTree which contains the contents of the given TAR file. |
URI
|
uri(Object path)
|
FileTree
|
zipTree(Object zipPath)
|
Method Detail |
---|
public void apply(Closure closure)
Configures the delegate object for this script using plugins or scripts.
The given closure is used to configure an ObjectConfigurationAction which is then used to configure the delegate object.
closure
- The closure to configure the ObjectConfigurationAction.
public void apply(Map options)
Configures the delegate object for this script using plugins or scripts.
The following options are available:
For more detail, see ObjectConfigurationAction.
options
- The options to use to configure the ObjectConfigurationAction.
public void buildscript(Closure configureClosure)
The given closure is executed against this script's ScriptHandler. The ScriptHandler is passed to the closure as the closure's delegate.
configureClosure
- the closure to use to configure the script classpath.
public WorkResult copy(Closure closure)
copy { from configurations.runtime into 'build/deploy/lib' }Note that CopySpecs can be nested:
copy { into 'build/webroot' exclude '**/.svn/**' from('src/main/webapp') { include '**/*.jsp' filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1']) } from('src/main/js') { include '**/*.js' } }
closure
- Closure to configure the CopySpec
public CopySpec copySpec(Closure closure)
closure
- Closure to configure the CopySpec
public boolean delete(Object... paths)
paths
- Any type of object accepted by Project.files
public ExecResult exec(Closure closure)
closure
- The closure for configuring the execution.
public File file(Object path)
Resolves a file path relative to the directory containing this script. This works as described for Project#file(Object)#file(Object)
path
- The object to resolve as a File.
public File file(Object path, PathValidation validation)
Resolves a file path relative to the directory containing this script and validates it using the given scheme. See PathValidation for the list of possible validations.
path
- An object to resolve as a File.validation
- The validation to perform on the file.
public ConfigurableFileTree fileTree(Object baseDir)
Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as per file(Object).
Note: to use a closure as the baseDir, you must explicitly cast the closure to Object to force the use of this method instead of fileTree(Closure). Example:
fileTree((Object){ someDir })
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
baseDir
- The base directory of the file tree. Evaluated as per file(Object).
public ConfigurableFileTree fileTree(Map args)
Creates a new ConfigurableFileTree using the provided map of arguments. The map will be applied as properties on the new file tree. Example:
fileTree(dir:'src', excludes:['**/ignore/**','**/.svn/**'])
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
args
- map of property assignments to ConfigurableFileTree object
public ConfigurableFileTree fileTree(Closure closure)
Creates a new ConfigurableFileTree using the provided closure. The closure will be used to configure the new file tree. The file tree is passed to the closure as its delegate. Example:
fileTree { from 'src' exclude '**/.svn/**' }.copy { into 'dest'}
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
closure
- Closure to configure the ConfigurableFileTree object
public ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure)
Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as per file(Object). The closure will be used to configure the new file tree. The file tree is passed to the closure as its delegate. Example:
fileTree('src') { exclude '**/.svn/**' }.copy { into 'dest'}
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
baseDir
- The base directory of the file tree. Evaluated as per file(Object).configureClosure
- Closure to configure the ConfigurableFileTree object.
public ConfigurableFileCollection files(Object... paths)
Returns a ConfigurableFileCollection containing the given files. This works as described for Project.files. Relative paths are resolved relative to the directory containing this script.
paths
- The paths to the files. May be empty.
public ConfigurableFileCollection files(Object paths, Closure configureClosure)
Creates a new ConfigurableFileCollection using the given paths. The file collection is configured using the given closure. This method works as described for Project.files. Relative paths are resolved relative to the directory containing this script.
paths
- The contents of the file collection. Evaluated as per files(Object...).configureClosure
- The closure to use to configure the file collection.
public ScriptHandler getBuildscript()
public Logger getLogger()
public LoggingManager getLogging()
public ResourceHandler getResources()
public ExecResult javaexec(Closure closure)
closure
- The closure for configuring the execution.
public File mkdir(Object path)
path
- The path for the directory to be created. Evaluated as per file(Object).
public String relativePath(Object path)
Returns the relative path from the directory containing this script to the given path. The given path object is (logically) resolved as described for file(Object), from which a relative path is calculated.
path
- The path to convert to a relative path.
public FileTree tarTree(Object tarPath)
Unless custom implementation of resources is passed, the tar tree attempts to guess the compression based on the file extension.
You can combine this method with the copy(groovy.lang.Closure) method to untar a TAR file:
task untar(type: Copy) { from tarTree('someCompressedTar.gzip') //tar tree attempts to guess the compression based on the file extension //however if you must specify the compression explicitly you can: from tarTree(resources.gzip('someTar.ext')) //in case you work with unconventionally compressed tars //you can provide your own implementation of a ReadableResource: //from tarTree(yourOwnResource as ReadableResource) into 'dest' }
tarPath
- The TAR file or an instance of Resource.
public URI uri(Object path)
Resolves a file path to a URI, relative to the directory containing this script. Evaluates the provided path object as described for file(Object), with the exception that any URI scheme is supported, not just 'file:' URIs.
path
- The object to resolve as a URI.
public FileTree zipTree(Object zipPath)
Creates a new FileTree which contains the contents of the given ZIP file. The given zipPath path is evaluated as per file(Object). You can combine this method with the copy(groovy.lang.Closure) method to unzip a ZIP file.
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
zipPath
- The ZIP file. Evaluated as per file(Object).
Gradle API 1.12