org.apache.tools.ant.taskdefs

Class Get

public class Get extends Task

Gets a particular file from a URL source. Options include verbose reporting, timestamp based fetches and controlling actions on failures. NB: access through a firewall only works if the whole Java runtime is correctly configured.

Since: Ant 1.1

UNKNOWN: category="network"

Nested Class Summary
protected static classGet.Base64Converter
Provide this for Backward Compatibility.
interfaceGet.DownloadProgress
Interface implemented for reporting progess of downloading.
static classGet.NullProgress
do nothing with progress info
static classGet.VerboseProgress
verbose progress system prints to some output stream
Method Summary
voidadd(ResourceCollection rc)
Adds URLs to get.
voidadd(FileNameMapper fileNameMapper)
Add a nested filenamemapper.
MappercreateMapper()
Define the mapper to map source to destination files.
booleandoGet(int logLevel, Get.DownloadProgress progress)
make a get request, with the supplied progress and logging info.
booleandoGet(URL source, File dest, int logLevel, Get.DownloadProgress progress)
make a get request, with the supplied progress and logging info.
voidexecute()
Does the work.
voidsetDest(File dest)
Where to copy the source file.
voidsetHttpUseCaches(boolean httpUseCache)
HTTP connections only - control caching on the HttpUrlConnection: httpConnection.setUseCaches(); if false, do not allow caching on the HttpUrlConnection.
voidsetIgnoreErrors(boolean v)
If true, log errors but do not treat as fatal.
voidsetMaxTime(long maxTime)
The time in seconds the download is allowed to take before being terminated.
voidsetPassword(String p)
password for the basic authentication.
voidsetRetries(int r)
The number of retries to attempt upon error, defaults to 3.
voidsetSkipExisting(boolean s)
Skip files that already exist locally.
voidsetSrc(URL u)
Set an URL to get.
voidsetUsername(String u)
Username for basic auth.
voidsetUseTimestamp(boolean v)
If true, conditionally download a file based on the timestamp of the local copy.
voidsetVerbose(boolean v)
If true, show verbose progress information.

Method Detail

add

public void add(ResourceCollection rc)
Adds URLs to get.

Since: Ant 1.8.0

add

public void add(FileNameMapper fileNameMapper)
Add a nested filenamemapper.

Parameters: fileNameMapper the mapper to add.

Since: Ant 1.8.0

createMapper

public Mapper createMapper()
Define the mapper to map source to destination files.

Returns: a mapper to be configured.

Throws: BuildException if more than one mapper is defined.

Since: Ant 1.8.0

doGet

public boolean doGet(int logLevel, Get.DownloadProgress progress)

Deprecated: only gets the first configured resource

make a get request, with the supplied progress and logging info. All the other config parameters are set at the task level, source, dest, ignoreErrors, etc.

Parameters: logLevel level to log at, see Project progress progress callback; null for no-callbacks

Returns: true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.

Throws: IOException for network trouble BuildException for argument errors, or other trouble when ignoreErrors is false.

doGet

public boolean doGet(URL source, File dest, int logLevel, Get.DownloadProgress progress)
make a get request, with the supplied progress and logging info. All the other config parameters like ignoreErrors are set at the task level.

Parameters: source the URL to get dest the target file logLevel level to log at, see Project progress progress callback; null for no-callbacks

Returns: true for a successful download, false otherwise. The return value is only relevant when ignoreErrors is true, as when false all failures raise BuildExceptions.

Throws: IOException for network trouble BuildException for argument errors, or other trouble when ignoreErrors is false.

Since: Ant 1.8.0

execute

public void execute()
Does the work.

Throws: BuildException Thrown in unrecoverable error.

setDest

public void setDest(File dest)
Where to copy the source file.

Parameters: dest Path to file.

setHttpUseCaches

public void setHttpUseCaches(boolean httpUseCache)
HTTP connections only - control caching on the HttpUrlConnection: httpConnection.setUseCaches(); if false, do not allow caching on the HttpUrlConnection.

Defaults to true (allow caching, which is also the HttpUrlConnection default value.

Since: Ant 1.8.0

setIgnoreErrors

public void setIgnoreErrors(boolean v)
If true, log errors but do not treat as fatal.

Parameters: v if "true" then don't report download errors up to ant

setMaxTime

public void setMaxTime(long maxTime)
The time in seconds the download is allowed to take before being terminated.

Since: Ant 1.8.0

setPassword

public void setPassword(String p)
password for the basic authentication.

Parameters: p password for authentication

setRetries

public void setRetries(int r)
The number of retries to attempt upon error, defaults to 3.

Parameters: r retry count

Since: Ant 1.8.0

setSkipExisting

public void setSkipExisting(boolean s)
Skip files that already exist locally.

Parameters: s "true" to skip existing destination files

Since: Ant 1.8.0

setSrc

public void setSrc(URL u)
Set an URL to get.

Parameters: u URL for the file.

setUsername

public void setUsername(String u)
Username for basic auth.

Parameters: u username for authentication

setUseTimestamp

public void setUseTimestamp(boolean v)
If true, conditionally download a file based on the timestamp of the local copy.

In this situation, the if-modified-since header is set so that the file is only fetched if it is newer than the local file (or there is no local file) This flag is only valid on HTTP connections, it is ignored in other cases. When the flag is set, the local copy of the downloaded file will also have its timestamp set to the remote file time.

Note that remote files of date 1/1/1970 (GMT) are treated as 'no timestamp', and web servers often serve files with a timestamp in the future by replacing their timestamp with that of the current time. Also, inter-computer clock differences can cause no end of grief.

Parameters: v "true" to enable file time fetching

setVerbose

public void setVerbose(boolean v)
If true, show verbose progress information.

Parameters: v if "true" then be verbose