org.apache.tools.ant.taskdefs
Class Get

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.Get
All Implemented Interfaces:
java.lang.Cloneable

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

Nested Class Summary
protected static class Get.Base64Converter
          Provide this for Backward Compatibility.
static interface Get.DownloadProgress
          Interface implemented for reporting progess of downloading.
static class Get.NullProgress
          do nothing with progress info
static class Get.VerboseProgress
          verbose progress system prints to some output stream
 
Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
Get()
           
 
Method Summary
 boolean doGet(int logLevel, Get.DownloadProgress progress)
          make a get request, with the supplied progress and logging info.
 void execute()
          Does the work.
 void setDest(java.io.File dest)
          Where to copy the source file.
 void setIgnoreErrors(boolean v)
          If true, log errors but do not treat as fatal.
 void setPassword(java.lang.String p)
          password for the basic authentication.
 void setSrc(java.net.URL u)
          Set the URL to get.
 void setUsername(java.lang.String u)
          Username for basic auth.
 void setUseTimestamp(boolean v)
          If true, conditionally download a file based on the timestamp of the local copy.
 void setVerbose(boolean v)
          If true, show verbose progress information.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Get

public Get()
Method Detail

execute

public void execute()
             throws BuildException
Does the work.

Overrides:
execute in class Task
Throws:
BuildException - Thrown in unrecoverable error.

doGet

public boolean doGet(int logLevel,
                     Get.DownloadProgress progress)
              throws java.io.IOException
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.log(String, int)
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:
java.io.IOException - for network trouble
BuildException - for argument errors, or other trouble when ignoreErrors is false.

setSrc

public void setSrc(java.net.URL u)
Set the URL to get.

Parameters:
u - URL for the file.

setDest

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

Parameters:
dest - Path to file.

setVerbose

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

Parameters:
v - if "true" then be verbose

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

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

setUsername

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

Parameters:
u - username for authentication

setPassword

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

Parameters:
p - password for authentication