org.gradle.api.tasks
Class Exec

java.lang.Object
  extended by org.gradle.api.internal.AbstractTask
      extended by org.gradle.api.DefaultTask
          extended by org.gradle.api.internal.ConventionTask
              extended by org.gradle.api.tasks.Exec
All Implemented Interfaces:
Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, Task, BaseExecSpec, ExecSpec, ProcessForkOptions, org.gradle.util.Configurable<Task>

public class Exec
extends org.gradle.api.internal.ConventionTask
implements ExecSpec

A task for executing a command line process.


Field Summary
 
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
 
Constructor Summary
Exec()
           
 
Method Summary
 ExecSpec args(Iterable<?> args)
          Adds args for the command to be executed.
 Exec args(Object... args)
          Adds args for the command to be executed.
 ExecSpec commandLine(Iterable<?> args)
          Sets the command plus the args to be executed.
 Exec commandLine(Object... arguments)
          Sets the command plus the args to be executed.
 Exec copyTo(ProcessForkOptions target)
          Copies these options to the given target options.
 Exec environment(Map<String,?> environmentVariables)
          Adds some environment variables to the environment for this process.
 Exec environment(String name, Object value)
          Adds an environment variable to the environment for this process.
 Exec executable(Object executable)
          Sets the name of the executable to use.
 List<String> getArgs()
          Returns the args for the command to be executed
 List<String> getCommandLine()
          Returns the command plus its arguments.
 Map<String,Object> getEnvironment()
          The environment variables to use for the process.
 ExecResult getExecResult()
          Returns the ExecResult object for the command run by this task.
 String getExecutable()
          Returns the name of the executable to use.
 InputStream getStandardInput()
          Returns the standard input stream for the process executing the command.
 File getWorkingDir()
          Returns the working directory for the process.
 boolean isIgnoreExitValue()
          Returns whether an exit value different from zero should be ignored.
 Exec setArgs(Iterable<?> arguments)
          Sets the args for the command to be executed.
 void setEnvironment(Map<String,?> environmentVariables)
          Sets the environment variable to use for the process.
 Exec setErrorOutput(OutputStream outputStream)
          Sets the error output stream for the process executing the command.
 void setExecutable(Object executable)
          Sets the name of the executable to use.
 ExecSpec setIgnoreExitValue(boolean ignoreExitValue)
          Sets whether an exit value different from zero should be ignored.
 Exec setStandardInput(InputStream inputStream)
          Sets the standard input stream for the process executing the command.
 Exec setStandardOutput(OutputStream outputStream)
          Sets the standard output stream for the process executing the command.
 void setWorkingDir(Object dir)
          Sets the working directory for the process.
 Exec workingDir(Object dir)
          Sets the working directory for the process.
 
Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, getConventionMapping, setConventionMapping
 
Methods inherited from class org.gradle.api.internal.AbstractTask
captureStandardOutput, compareTo, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, disableStandardOutputCapture, doFirst, doFirst, doLast, doLast, equals, execute, getActions, getAdditionalProperties, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDidWork, getDynamicObjectHelper, getEnabled, getExecuter, getGroup, getInputs, getLogger, getLogging, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getStandardOutputCapture, getState, getTaskDependencies, getTemporaryDir, hashCode, hasProperty, injectIntoNewInstance, isEnabled, leftShift, onlyIf, onlyIf, property, setActions, setConvention, setDependsOn, setDescription, setDidWork, setEnabled, setExecuter, setGroup, setName, setOnlyIf, setOnlyIf, setProject, setProperty, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gradle.api.Task
captureStandardOutput, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, disableStandardOutputCapture, doFirst, doFirst, doLast, doLast, getActions, getAnt, getConvention, getDependsOn, getDescription, getDidWork, getEnabled, getGroup, getInputs, getLogger, getLogging, getName, getOutputs, getPath, getProject, getState, getTaskDependencies, getTemporaryDir, hasProperty, leftShift, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setEnabled, setGroup, setOnlyIf, setOnlyIf, setProperty
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

Exec

public Exec()
Method Detail

commandLine

public Exec commandLine(Object... arguments)
Sets the command plus the args to be executed.

Specified by:
commandLine in interface ExecSpec
Parameters:
arguments - the command plus the args to be executed
Returns:
this

commandLine

public ExecSpec commandLine(Iterable<?> args)
Sets the command plus the args to be executed.

Specified by:
commandLine in interface ExecSpec
Parameters:
args - the command plus the args to be executed
Returns:
this

args

public Exec args(Object... args)
Adds args for the command to be executed.

Specified by:
args in interface ExecSpec
Parameters:
args - args for the command
Returns:
this

args

public ExecSpec args(Iterable<?> args)
Adds args for the command to be executed.

Specified by:
args in interface ExecSpec
Parameters:
args - args for the command
Returns:
this

setArgs

public Exec setArgs(Iterable<?> arguments)
Sets the args for the command to be executed.

Specified by:
setArgs in interface ExecSpec
Parameters:
arguments - args for the command
Returns:
this

getArgs

public List<String> getArgs()
Returns the args for the command to be executed

Specified by:
getArgs in interface ExecSpec

getCommandLine

public List<String> getCommandLine()
Returns the command plus its arguments.

Specified by:
getCommandLine in interface BaseExecSpec

getExecutable

public String getExecutable()
Returns the name of the executable to use.

Specified by:
getExecutable in interface ProcessForkOptions
Returns:
The executable.

setExecutable

public void setExecutable(Object executable)
Sets the name of the executable to use.

Specified by:
setExecutable in interface ProcessForkOptions
Parameters:
executable - The executable. Must not be null.

executable

public Exec executable(Object executable)
Sets the name of the executable to use.

Specified by:
executable in interface ProcessForkOptions
Parameters:
executable - The executable. Must not be null.
Returns:
this

getWorkingDir

public File getWorkingDir()
Returns the working directory for the process. Defaults to the project directory.

Specified by:
getWorkingDir in interface ProcessForkOptions
Returns:
The working directory. Never returns null.

setWorkingDir

public void setWorkingDir(Object dir)
Sets the working directory for the process. The supplied argument is evaluated as for Project.file(Object).

Specified by:
setWorkingDir in interface ProcessForkOptions
Parameters:
dir - The working directory. Must not be null.

workingDir

public Exec workingDir(Object dir)
Sets the working directory for the process. The supplied argument is evaluated as for Project.file(Object).

Specified by:
workingDir in interface ProcessForkOptions
Parameters:
dir - The working directory. Must not be null.
Returns:
this

getEnvironment

public Map<String,Object> getEnvironment()
The environment variables to use for the process. Defaults to the environment of this process.

Specified by:
getEnvironment in interface ProcessForkOptions
Returns:
The environment. Returns an empty map when there are no environment variables.

setEnvironment

public void setEnvironment(Map<String,?> environmentVariables)
Sets the environment variable to use for the process.

Specified by:
setEnvironment in interface ProcessForkOptions
Parameters:
environmentVariables - The environment variables. Must not be null.

environment

public Exec environment(String name,
                        Object value)
Adds an environment variable to the environment for this process.

Specified by:
environment in interface ProcessForkOptions
Parameters:
name - The name of the variable.
value - The value for the variable. Must not be null.
Returns:
this

environment

public Exec environment(Map<String,?> environmentVariables)
Adds some environment variables to the environment for this process.

Specified by:
environment in interface ProcessForkOptions
Parameters:
environmentVariables - The environment variables. Must not be null.
Returns:
this

copyTo

public Exec copyTo(ProcessForkOptions target)
Copies these options to the given target options.

Specified by:
copyTo in interface ProcessForkOptions
Parameters:
target - The target options
Returns:
this

setStandardInput

public Exec setStandardInput(InputStream inputStream)
Sets the standard input stream for the process executing the command.

Specified by:
setStandardInput in interface BaseExecSpec
Parameters:
inputStream - The standard input stream for the command process.
Returns:
this

getStandardInput

public InputStream getStandardInput()
Returns the standard input stream for the process executing the command.

Specified by:
getStandardInput in interface BaseExecSpec

setStandardOutput

public Exec setStandardOutput(OutputStream outputStream)
Sets the standard output stream for the process executing the command.

Specified by:
setStandardOutput in interface BaseExecSpec
Parameters:
outputStream - The standard output stream for the command process.
Returns:
this

setErrorOutput

public Exec setErrorOutput(OutputStream outputStream)
Sets the error output stream for the process executing the command.

Specified by:
setErrorOutput in interface BaseExecSpec
Parameters:
outputStream - The standard output error stream for the command process.
Returns:
this

setIgnoreExitValue

public ExecSpec setIgnoreExitValue(boolean ignoreExitValue)
Sets whether an exit value different from zero should be ignored. In case it is not ignored, an exception is thrown in case of such an exit value.

Specified by:
setIgnoreExitValue in interface BaseExecSpec
Parameters:
ignoreExitValue - whether to ignore the exit value or not
Returns:
this

isIgnoreExitValue

public boolean isIgnoreExitValue()
Returns whether an exit value different from zero should be ignored. In case it is not ignored, an exception is thrown in case of such an exit value. Defaults to false.

Specified by:
isIgnoreExitValue in interface BaseExecSpec

getExecResult

public ExecResult getExecResult()
Returns the ExecResult object for the command run by this task. Returns null if the task has not been executed yet.