public abstract class AbstractTask extends Object implements TaskInternal, DynamicObjectAware
Task.NamerTASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
addValidator(TaskValidator validator) |
int |
compareTo(Task otherTask) |
Task |
configure(Closure closure)
Applies the statements of the closure against this task object.
|
Task |
deleteAllActions()
Removes all the actions of this task.
|
Task |
dependsOn(Object... paths)
Adds the given dependencies to this task.
|
boolean |
dependsOnTaskDidWork()
Checks if any of the tasks that this task depends on
didWork. |
Task |
doFirst(Action<? super Task> action)
Adds the given
Action to the beginning of this task's action list. |
Task |
doFirst(Closure action)
Adds the given closure to the beginning of this task's action list.
|
Task |
doLast(Action<? super Task> action)
Adds the given
Action to the end of this task's action list. |
Task |
doLast(Closure action)
Adds the given closure to the end of this task's action list.
|
void |
execute() |
void |
executeWithoutThrowingTaskFailure() |
List<Action<? super Task>> |
getActions()
Returns the sequence of
Action objects which will be executed by this task, in the order of
execution. |
AntBuilder |
getAnt()
Returns the
AntBuilder for this task. |
DynamicObject |
getAsDynamicObject()
Returns a
DynamicObject for this object. |
Convention |
getConvention()
Returns the
Convention object for this task. |
Set<Object> |
getDependsOn()
Returns the dependencies of this task.
|
String |
getDescription()
Returns the description of this task.
|
boolean |
getDidWork()
Checks if the task actually did any work.
|
DynamicObjectHelper |
getDynamicObjectHelper() |
boolean |
getEnabled()
Returns if this task is enabled or not.
|
TaskExecuter |
getExecuter() |
ExtensionContainer |
getExtensions()
The container of extensions.
|
String |
getGroup()
Returns the task group which this task belongs to.
|
TaskInputs |
getInputs()
Returns the inputs of this task.
|
Logger |
getLogger()
Returns the logger for this task.
|
LoggingManager |
getLogging()
Returns the
LoggingManager which can be used to control the logging level and
standard output/error capture for this task. |
String |
getName()
Returns the name of this task.
|
Spec<? super TaskInternal> |
getOnlyIf() |
TaskOutputsInternal |
getOutputs()
Returns the outputs of this task.
|
String |
getPath()
Returns the path of the task, which is a fully qualified name for the task.
|
Project |
getProject()
Returns the
Project which this task belongs to. |
protected ServiceRegistry |
getServices() |
StandardOutputCapture |
getStandardOutputCapture() |
TaskState |
getState()
Returns the execution state of this task.
|
TaskDependencyInternal |
getTaskDependencies()
Returns a
TaskDependency which contains all the tasks that this task depends on. |
File |
getTemporaryDir()
Returns a directory which this task can use to write temporary files to.
|
Factory<File> |
getTemporaryDirFactory()
The returned factory is expected to return the same file each time.
|
List<TaskValidator> |
getValidators() |
boolean |
hasProperty(String propertyName)
Determines if this task has the given property.
|
static <T extends Task> |
injectIntoNewInstance(ProjectInternal project,
String name,
Callable<T> factory) |
boolean |
isEnabled() |
Task |
leftShift(Closure action)
Adds the given closure to the end of this task's action list.
|
void |
onlyIf(Closure onlyIfClosure)
Execute the task only if the given closure returns true.
|
void |
onlyIf(Spec<? super Task> onlyIfSpec)
Execute the task only if the given spec is satisfied.
|
Object |
property(String propertyName)
Returns the value of the given property of this task.
|
void |
setActions(List<Action<? super Task>> actions)
Sets the sequence of
Action objects which will be executed by this task. |
void |
setDependsOn(Iterable<?> dependsOn)
Sets the dependencies of this task.
|
void |
setDescription(String description)
Sets a description for this task.
|
void |
setDidWork(boolean didWork)
Sets whether the task actually did any work.
|
void |
setEnabled(boolean enabled)
Set the enabled state of a task.
|
void |
setExecuter(TaskExecuter executer) |
void |
setGroup(String group)
Sets the task group which this task belongs to.
|
void |
setName(String name) |
void |
setOnlyIf(Closure onlyIfClosure)
Execute the task only if the given closure returns true.
|
void |
setOnlyIf(Spec<? super Task> spec)
Execute the task only if the given spec is satisfied.
|
void |
setProject(Project project) |
void |
setProperty(String name,
Object value)
Sets a property of this task.
|
String |
toString() |
public static <T extends Task> T injectIntoNewInstance(ProjectInternal project, String name, Callable<T> factory)
public TaskState getState()
Taskpublic AntBuilder getAnt()
TaskReturns the AntBuilder for this task. You can use this in your build file to execute ant
tasks.
public Project getProject()
TaskReturns the Project which this task belongs to.
getProject in interface Taskpublic void setProject(Project project)
public String getName()
TaskReturns the name of this task. The name uniquely identifies the task within its Project.
public void setName(String name)
public List<Action<? super Task>> getActions()
TaskReturns the sequence of Action objects which will be executed by this task, in the order of
execution.
getActions in interface Taskpublic void setActions(List<Action<? super Task>> actions)
TaskSets the sequence of Action objects which will be executed by this task.
setActions in interface Taskactions - The actions.public TaskDependencyInternal getTaskDependencies()
TaskReturns a TaskDependency which contains all the tasks that this task depends on.
getTaskDependencies in interface Taskpublic Set<Object> getDependsOn()
TaskReturns the dependencies of this task.
getDependsOn in interface Taskpublic void setDependsOn(Iterable<?> dependsOn)
TaskSets the dependencies of this task. See here for a description of the types of objects which can be used as task dependencies.
setDependsOn in interface TaskdependsOn - The set of task paths.public void onlyIf(Closure onlyIfClosure)
TaskExecute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.
You may add multiple such predicates. The task is skipped if any of the predicates return false.
Typical usage:myTask.onlyIf{ dependsOnTaskDidWork() }
public void onlyIf(Spec<? super Task> onlyIfSpec)
TaskExecute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
You may add multiple such predicates. The task is skipped if any of the predicates return false.
Typical usage (from Java):
myTask.onlyIf(new Spec<Task>() {
boolean isSatisfiedBy(Task task) {
return task.dependsOnTaskDidWork();
}
});
public void setOnlyIf(Spec<? super Task> spec)
TaskExecute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
The given predicate replaces all such predicates for this task.
public void setOnlyIf(Closure onlyIfClosure)
TaskExecute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.
The given predicate replaces all such predicates for this task.
public Spec<? super TaskInternal> getOnlyIf()
getOnlyIf in interface TaskInternalpublic boolean getDidWork()
TaskChecks if the task actually did any work. Even if a Task executes, it may determine that it has nothing to do. For example, the Compile task may determine that source files have not changed since the last time a the task was run.
getDidWork in interface Taskpublic void setDidWork(boolean didWork)
TaskThis is useful when combined with onlyIf { dependsOnTaskDidWork() }.
setDidWork in interface TaskdidWork - indicates if the task did any workpublic boolean isEnabled()
public boolean getEnabled()
TaskReturns if this task is enabled or not.
getEnabled in interface TaskTask.setEnabled(boolean)public void setEnabled(boolean enabled)
TaskSet the enabled state of a task. If a task is disabled none of the its actions are executed. Note that disabling a task does not prevent the execution of the tasks which this task depends on.
setEnabled in interface Taskenabled - The enabled state of this task (true or false)public String getPath()
TaskReturns the path of the task, which is a fully qualified name for the task. The path of a task is the path of
its Project plus the name of the task, separated by :.
public Task deleteAllActions()
TaskRemoves all the actions of this task.
deleteAllActions in interface Taskpublic final void execute()
execute in interface TaskInternalpublic void executeWithoutThrowingTaskFailure()
executeWithoutThrowingTaskFailure in interface TaskInternalpublic TaskExecuter getExecuter()
getExecuter in interface TaskInternalpublic void setExecuter(TaskExecuter executer)
setExecuter in interface TaskInternalpublic Task dependsOn(Object... paths)
TaskAdds the given dependencies to this task. See here for a description of the types of objects which can be used as task dependencies.
dependsOn in interface Taskpaths - The dependencies to add to this task. The path can be defined by:
String, CharSequence or groovy.lang.GString task path or name. A relative path is interpreted relative to the task's Project. This
allows you to refer to tasks in other projects.Task.Task as parameter. It may return any of the types listed here. Its
return value is recursively converted to tasks. A null return value is treated as an empty collection.TaskDependency object.Buildable object.Iterable, Collection, Map or array. May contain any of the types listed here. The elements of the
iterable/collection/map/array are recursively converted to tasks.Callable. The call() method may return any of the types listed here. Its return value is
recursively converted to tasks. A null return value is treated as an empty collection.Object. The object's toString() method is interpreted as a task path or name. The support for custom Objects
has been deprecated and will be removed in the next version of Gradle.public Task doFirst(Action<? super Task> action)
TaskAdds the given Action to the beginning of this task's action list.
public Task doLast(Action<? super Task> action)
TaskAdds the given Action to the end of this task's action list.
public int compareTo(Task otherTask)
compareTo in interface Comparable<Task>public Logger getLogger()
TaskReturns the logger for this task. You can use this in your build file to write log messages.
public LoggingManager getLogging()
TaskLoggingManager which can be used to control the logging level and
standard output/error capture for this task. By default, System.out is redirected to the Gradle logging system at
the QUIET log level, and System.err is redirected at the ERROR log level.getLogging in interface Taskpublic StandardOutputCapture getStandardOutputCapture()
getStandardOutputCapture in interface TaskInternalpublic DynamicObjectHelper getDynamicObjectHelper()
public Object property(String propertyName) throws MissingPropertyException
TaskReturns the value of the given property of this task. This method locates a property as follows:
MissingPropertyExceptionproperty in interface TaskpropertyName - The name of the property.MissingPropertyException - When the given property is unknown.public boolean hasProperty(String propertyName)
TaskDetermines if this task has the given property. See here for details of the properties which are available for a task.
hasProperty in interface TaskpropertyName - The name of the property to locate.public void setProperty(String name, Object value)
TaskSets a property of this task. This method searches for a property with the given name in the following locations, and sets the property on the first location where it finds the property.
enabled project property.If the property is not found in any of these locations, it is added to the project's additional properties.
setProperty in interface Taskname - The name of the propertyvalue - The value of the propertypublic Convention getConvention()
TaskReturns the Convention object for this task. A Plugin can use the convention object to
contribute properties and methods to this task.
getConvention in interface Taskpublic ExtensionContainer getExtensions()
ExtensionAwaregetExtensions in interface ExtensionAwarepublic DynamicObject getAsDynamicObject()
DynamicObjectAwareDynamicObject for this object.getAsDynamicObject in interface DynamicObjectAwarepublic String getDescription()
TaskgetDescription in interface Taskpublic void setDescription(String description)
Taskgradle tasks is called.setDescription in interface Taskdescription - The description of the task. Might be null.public String getGroup()
Taskpublic void setGroup(String group)
Taskpublic TaskInputs getInputs()
TaskReturns the inputs of this task.
public TaskOutputsInternal getOutputs()
TaskReturns the outputs of this task.
getOutputs in interface TaskInternalgetOutputs in interface Taskprotected ServiceRegistry getServices()
public boolean dependsOnTaskDidWork()
TaskChecks if any of the tasks that this task depends on didWork.
dependsOnTaskDidWork in interface Taskpublic Task doFirst(Closure action)
TaskAdds the given closure to the beginning of this task's action list. The closure is passed this task as a parameter when executed.
public Task doLast(Closure action)
TaskAdds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.
public Task leftShift(Closure action)
TaskAdds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed. You can call this method from your build script using the << left shift operator.
public Task configure(Closure closure)
TaskApplies the statements of the closure against this task object. The delegate object for the closure is set to this task.
configure in interface Taskconfigure in interface Configurable<Task>closure - The closure to be applied (can be null).public File getTemporaryDir()
TaskReturns a directory which this task can use to write temporary files to. Each task instance is provided with a separate temporary directory. There are no guarantees that the contents of this directory will be kept beyond the execution of the task.
getTemporaryDir in interface Taskpublic Factory<File> getTemporaryDirFactory()
TaskInternalThe getTemporaryDir() method creates the directory which can be problematic. Use this to delay that creation.
getTemporaryDirFactory in interface TaskInternalpublic void addValidator(TaskValidator validator)
addValidator in interface TaskInternalpublic List<TaskValidator> getValidators()
getValidators in interface TaskInternalCopyright © 2013. All rights reserved