de.undercouch.gradle.tasks.download
Class DownloadAction

java.lang.Object
  extended by de.undercouch.gradle.tasks.download.DownloadAction
All Implemented Interfaces:
DownloadSpec

public class DownloadAction
extends java.lang.Object
implements DownloadSpec

Downloads a file and displays progress


Constructor Summary
DownloadAction(org.gradle.api.Project project)
          Creates a new download action
 
Method Summary
 void acceptAnyCertificate(boolean accept)
          Specifies if HTTPS certificate verification errors should be ignored and any certificate (even an invalid one) should be accepted.
 void authScheme(java.lang.Object authScheme)
          Sets the authentication scheme to use.
 void cachedETagsFile(java.lang.Object location)
          Sets the location of the file that keeps entity tags (ETags) received from the server
 void compress(boolean compress)
          Specifies if compression should be used during download
 void credentials(org.apache.http.auth.Credentials credentials)
          Sets the credentials used for authentication.
 void dest(java.lang.Object dest)
          Sets the download destination
 void downloadTaskDir(java.lang.Object dir)
          Specifies the directory where gradle-download-task stores information that should persist between builds
 void execute()
          Starts downloading
 org.apache.http.auth.AuthScheme getAuthScheme()
           
 java.io.File getCachedETagsFile()
           
 org.apache.http.auth.Credentials getCredentials()
           
 java.io.File getDest()
           
 java.io.File getDownloadTaskDir()
           
 java.lang.String getHeader(java.lang.String name)
           
 java.util.Map<java.lang.String,java.lang.String> getHeaders()
           
 java.util.List<java.io.File> getOutputFiles()
           
 java.lang.String getPassword()
           
 org.apache.http.HttpRequestInterceptor getRequestInterceptor()
           
 org.apache.http.HttpResponseInterceptor getResponseInterceptor()
           
 java.lang.Object getSrc()
           
 int getTimeout()
           
 java.lang.Object getUseETag()
           
 java.lang.String getUsername()
           
 void header(java.lang.String name, java.lang.String value)
          Sets an HTTP request header to use when downloading
 void headers(java.util.Map<java.lang.String,java.lang.String> headers)
          Sets the HTTP request headers to use when downloading
 boolean isAcceptAnyCertificate()
           
 boolean isCompress()
           
 boolean isOnlyIfModified()
           
 boolean isOnlyIfNewer()
          Get the onlyIfNewer flag.
 boolean isOverwrite()
           
 boolean isQuiet()
           
 boolean isTempAndMove()
           
 boolean isUpToDate()
           
 void onlyIfModified(boolean onlyIfModified)
          Sets the onlyIfModified flag
 void onlyIfNewer(boolean onlyIfNewer)
          Sets the onlyIfNewer flag.
 void overwrite(boolean overwrite)
          Sets the overwrite flag
 void password(java.lang.String password)
          Sets the password for Basic or Digest authentication
 void quiet(boolean quiet)
          Sets the quiet flag
 void requestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
          Specifies an interceptor that will be called when a request is about to be sent to the server.
 void responseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
          Specifies an interceptor that will be called when a response has been received from the server.
 void src(java.lang.Object src)
          Sets the download source URL
 void tempAndMove(boolean tempAndMove)
          Specifies whether the file should be downloaded to a temporary location and, upon successful execution, moved to the final location.
 void timeout(int milliseconds)
          Specifies a timeout in milliseconds which is the maximum time to wait until a connection is established or until the server returns data.
 void useETag(java.lang.Object useETag)
          Sets the useETag flag.
 void username(java.lang.String username)
          Sets the username for Basic or Digest authentication
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadAction

public DownloadAction(org.gradle.api.Project project)
Creates a new download action

Parameters:
project - the project to be built
Method Detail

execute

public void execute()
             throws java.io.IOException
Starts downloading

Throws:
java.io.IOException - if the file could not downloaded

isUpToDate

public boolean isUpToDate()
Returns:
true if the download destination is up to date

getOutputFiles

public java.util.List<java.io.File> getOutputFiles()
Returns:
a list of files created by this action (i.e. the destination files)

src

public void src(java.lang.Object src)
         throws java.net.MalformedURLException
Description copied from interface: DownloadSpec
Sets the download source URL

Specified by:
src in interface DownloadSpec
Parameters:
src - the URL
Throws:
java.net.MalformedURLException - if the download source is not a URL

dest

public void dest(java.lang.Object dest)
Description copied from interface: DownloadSpec
Sets the download destination

Specified by:
dest in interface DownloadSpec
Parameters:
dest - a file or directory where to store the retrieved file

quiet

public void quiet(boolean quiet)
Description copied from interface: DownloadSpec
Sets the quiet flag

Specified by:
quiet in interface DownloadSpec
Parameters:
quiet - true if download progress should not be logged

overwrite

public void overwrite(boolean overwrite)
Description copied from interface: DownloadSpec
Sets the overwrite flag

Specified by:
overwrite in interface DownloadSpec
Parameters:
overwrite - true if existing files should be overwritten, false otherwise

onlyIfModified

public void onlyIfModified(boolean onlyIfModified)
Description copied from interface: DownloadSpec
Sets the onlyIfModified flag

Specified by:
onlyIfModified in interface DownloadSpec
Parameters:
onlyIfModified - true if the file should only be downloaded if it has been modified on the server since the last download

onlyIfNewer

public void onlyIfNewer(boolean onlyIfNewer)
Description copied from interface: DownloadSpec
Sets the onlyIfNewer flag. This method is an alias for DownloadSpec.onlyIfModified(boolean).

Specified by:
onlyIfNewer in interface DownloadSpec
Parameters:
onlyIfNewer - true if the file should only be downloaded if it has been modified on the server since the last download

compress

public void compress(boolean compress)
Description copied from interface: DownloadSpec
Specifies if compression should be used during download

Specified by:
compress in interface DownloadSpec
Parameters:
compress - true if compression should be enabled

username

public void username(java.lang.String username)
Description copied from interface: DownloadSpec
Sets the username for Basic or Digest authentication

Specified by:
username in interface DownloadSpec
Parameters:
username - the username

password

public void password(java.lang.String password)
Description copied from interface: DownloadSpec
Sets the password for Basic or Digest authentication

Specified by:
password in interface DownloadSpec
Parameters:
password - the password

authScheme

public void authScheme(java.lang.Object authScheme)
Description copied from interface: DownloadSpec

Sets the authentication scheme to use. This method accepts either a String (valid values are "Basic" and "Digest") or an instance of AuthScheme.

If username and password are set this method will only accept "Basic" or "Digest" as valid values. The default value will be "Basic" in this case.

Specified by:
authScheme in interface DownloadSpec
Parameters:
authScheme - the authentication scheme

credentials

public void credentials(org.apache.http.auth.Credentials credentials)
Description copied from interface: DownloadSpec
Sets the credentials used for authentication. Can be called as an alternative to DownloadSpec.username(String) and DownloadSpec.password(String). Allows for setting credentials for authentication schemes other than Basic or Digest.

Specified by:
credentials in interface DownloadSpec
Parameters:
credentials - the credentials

headers

public void headers(java.util.Map<java.lang.String,java.lang.String> headers)
Description copied from interface: DownloadSpec
Sets the HTTP request headers to use when downloading

Specified by:
headers in interface DownloadSpec
Parameters:
headers - a Map of header names to values

header

public void header(java.lang.String name,
                   java.lang.String value)
Description copied from interface: DownloadSpec
Sets an HTTP request header to use when downloading

Specified by:
header in interface DownloadSpec
Parameters:
name - name of the HTTP header
value - value of the HTTP header

acceptAnyCertificate

public void acceptAnyCertificate(boolean accept)
Description copied from interface: DownloadSpec
Specifies if HTTPS certificate verification errors should be ignored and any certificate (even an invalid one) should be accepted. By default certificates are validated and errors are not being ignored.

Specified by:
acceptAnyCertificate in interface DownloadSpec
Parameters:
accept - true if certificate errors should be ignored (default: false)

timeout

public void timeout(int milliseconds)
Description copied from interface: DownloadSpec
Specifies a timeout in milliseconds which is the maximum time to wait until a connection is established or until the server returns data. A value of zero means infinite timeout. A negative value is interpreted as undefined.

Specified by:
timeout in interface DownloadSpec
Parameters:
milliseconds - the timeout in milliseconds (default: -1)

downloadTaskDir

public void downloadTaskDir(java.lang.Object dir)
Description copied from interface: DownloadSpec
Specifies the directory where gradle-download-task stores information that should persist between builds

Specified by:
downloadTaskDir in interface DownloadSpec
Parameters:
dir - the directory (default: ${buildDir}/gradle-download-task)

tempAndMove

public void tempAndMove(boolean tempAndMove)
Description copied from interface: DownloadSpec
Specifies whether the file should be downloaded to a temporary location and, upon successful execution, moved to the final location. If the overwrite flag is set to false, this flag is useful to avoid partially downloaded files if Gradle is forcefully closed or the system crashes. Note that the plugin always deletes partial downloads on connection errors, regardless of the value of this flag. The default temporary location can be configured with the DownloadSpec.downloadTaskDir(Object);

Specified by:
tempAndMove in interface DownloadSpec
Parameters:
tempAndMove - true if the file should be downloaded to a temporary location and, upon successful execution, moved to the final location (default: false)

useETag

public void useETag(java.lang.Object useETag)
Description copied from interface: DownloadSpec

Sets the useETag flag. Possible values are:

Note that this flag is only effective if onlyIfModified is true.

Specified by:
useETag in interface DownloadSpec
Parameters:
useETag - the flag's new value

cachedETagsFile

public void cachedETagsFile(java.lang.Object location)
Description copied from interface: DownloadSpec
Sets the location of the file that keeps entity tags (ETags) received from the server

Specified by:
cachedETagsFile in interface DownloadSpec
Parameters:
location - the location (default: ${downloadTaskDir}/etags.json)

requestInterceptor

public void requestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Description copied from interface: DownloadSpec
Specifies an interceptor that will be called when a request is about to be sent to the server. This is useful if you want to manipulate a request beyond the capabilities of the download task.

Specified by:
requestInterceptor in interface DownloadSpec
Parameters:
interceptor - the interceptor to set

responseInterceptor

public void responseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
Description copied from interface: DownloadSpec
Specifies an interceptor that will be called when a response has been received from the server. This is useful if you want to manipulate incoming data before it is handled by the download task.

Specified by:
responseInterceptor in interface DownloadSpec
Parameters:
interceptor - the interceptor to set

getSrc

public java.lang.Object getSrc()
Specified by:
getSrc in interface DownloadSpec
Returns:
the download source(s), either a URL or a list of URLs

getDest

public java.io.File getDest()
Specified by:
getDest in interface DownloadSpec
Returns:
the download destination

isQuiet

public boolean isQuiet()
Specified by:
isQuiet in interface DownloadSpec
Returns:
the quiet flag

isOverwrite

public boolean isOverwrite()
Specified by:
isOverwrite in interface DownloadSpec
Returns:
the overwrite flag

isOnlyIfModified

public boolean isOnlyIfModified()
Specified by:
isOnlyIfModified in interface DownloadSpec
Returns:
the onlyIfModified flag

isOnlyIfNewer

public boolean isOnlyIfNewer()
Description copied from interface: DownloadSpec
Get the onlyIfNewer flag. This method is an alias for DownloadSpec.isOnlyIfModified().

Specified by:
isOnlyIfNewer in interface DownloadSpec
Returns:
the onlyIfNewer flag

isCompress

public boolean isCompress()
Specified by:
isCompress in interface DownloadSpec
Returns:
true if compression is enabled

getUsername

public java.lang.String getUsername()
Specified by:
getUsername in interface DownloadSpec
Returns:
the username for Basic or Digest authentication

getPassword

public java.lang.String getPassword()
Specified by:
getPassword in interface DownloadSpec
Returns:
the password for Basic or Digest authentication

getAuthScheme

public org.apache.http.auth.AuthScheme getAuthScheme()
Specified by:
getAuthScheme in interface DownloadSpec
Returns:
the authentication scheme used (or null if no authentication is performed)

getCredentials

public org.apache.http.auth.Credentials getCredentials()
Specified by:
getCredentials in interface DownloadSpec
Returns:
the credentials used for authentication (or null if no authentication is performed)

getHeaders

public java.util.Map<java.lang.String,java.lang.String> getHeaders()
Specified by:
getHeaders in interface DownloadSpec
Returns:
the HTTP request headers to use when downloading

getHeader

public java.lang.String getHeader(java.lang.String name)
Specified by:
getHeader in interface DownloadSpec
Parameters:
name - name of the HTTP header
Returns:
the value of the HTTP header

isAcceptAnyCertificate

public boolean isAcceptAnyCertificate()
Specified by:
isAcceptAnyCertificate in interface DownloadSpec
Returns:
true if HTTPS certificate verification errors should be ignored, default value is false

getTimeout

public int getTimeout()
Specified by:
getTimeout in interface DownloadSpec
Returns:
the timeout in milliseconds which is the maximum time to wait until a connection is established or until the server returns data.

getDownloadTaskDir

public java.io.File getDownloadTaskDir()
Specified by:
getDownloadTaskDir in interface DownloadSpec
Returns:
the directory where gradle-download-task stores information that should persist between builds

isTempAndMove

public boolean isTempAndMove()
Specified by:
isTempAndMove in interface DownloadSpec
Returns:
true of if the file should be downloaded to a temporary location and, upon successful execution, moved to the final location.

getUseETag

public java.lang.Object getUseETag()
Specified by:
getUseETag in interface DownloadSpec
Returns:
the value of the useETag flag
See Also:
DownloadSpec.useETag(Object)

getCachedETagsFile

public java.io.File getCachedETagsFile()
Specified by:
getCachedETagsFile in interface DownloadSpec
Returns:
the location of the file that keeps entity tags (ETags) received from the server

getRequestInterceptor

public org.apache.http.HttpRequestInterceptor getRequestInterceptor()
Specified by:
getRequestInterceptor in interface DownloadSpec
Returns:
an interceptor that will be called when a request is about to be sent to the server (or null if no interceptor is specified)

getResponseInterceptor

public org.apache.http.HttpResponseInterceptor getResponseInterceptor()
Specified by:
getResponseInterceptor in interface DownloadSpec
Returns:
an interceptor that will be called when a response has been received from the server (or null if no interceptor is specified)