Package com.mooltiverse.oss.nyx.gradle
Class CoreTask
- java.lang.Object
-
- org.gradle.api.internal.AbstractTask
-
- org.gradle.api.DefaultTask
-
- com.mooltiverse.oss.nyx.gradle.CoreTask
-
- All Implemented Interfaces:
Comparable<Task>
,org.gradle.api.internal.DynamicObjectAware
,org.gradle.api.internal.TaskInternal
,ExtensionAware
,Task
,org.gradle.util.Configurable<Task>
- Direct Known Subclasses:
ArrangeTask
,CleanTask
,InferTask
,MakeTask
,MarkTask
,PublishTask
public abstract class CoreTask extends DefaultTask
The abstract superclass for all Nyx core tasks. Core tasks, as opposite toLifecycleTask
are those performing some concrete actions.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gradle.api.Task
Task.Namer
-
-
Field Summary
Fields Modifier and Type Field Description static String
GROUP
The group the tasks belong to.static String
NYX_INSTANCE_PROPERTY
The name used to store and retrieve the extra property that holds the shared backing Nyx instance that can be used by all tasks.-
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
-
-
Constructor Summary
Constructors Constructor Description CoreTask()
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
configure(com.mooltiverse.oss.nyx.gradle.AbstractTask task)
Configures the task by defining properties common to all core tasks.protected static <T extends Task>
TaskProvider<T>define(Project project, String name, Class<T> type, Action<? super T> configurationAction)
Registers the task into the given project.protected static TaskProvider<Task>
findTask(Project project, String name)
Returns the provider for the task with the given name ornull
if no task has been registered or created with such name in the given project.protected boolean
hasSharedProperty(String name)
Returnstrue
if there is a project with the given name stored for the project.protected Nyx
nyx()
Returns a shared backing Nyx instance to be used by all tasks within the project.protected NyxExtension
retrieveExtension()
Returns the instance of the extension for the task.protected static NyxExtension
retrieveExtension(Project project)
Returns the instance of the extension for the given project.protected Object
retrieveSharedProperty(String name)
Retrieves the shared project property with the given name.State
state()
Returns the state of the shared backing Nyx instance.protected void
storeSharedProperty(String name, Object value)
Stores the given value as a shared project property with the given name.-
Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService
-
Methods inherited from class org.gradle.api.internal.AbstractTask
appendParallelSafeAction, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getOnlyIf, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, prependParallelSafeAction, setImpliesSubProjects, setLoggerMessageRewriter
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.gradle.api.Task
getConvention
-
-
-
-
Field Detail
-
NYX_INSTANCE_PROPERTY
public static final String NYX_INSTANCE_PROPERTY
The name used to store and retrieve the extra property that holds the shared backing Nyx instance that can be used by all tasks.
-
GROUP
public static final String GROUP
The group the tasks belong to.- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
protected static void configure(com.mooltiverse.oss.nyx.gradle.AbstractTask task)
Configures the task by defining properties common to all core tasks. Also invokes the same method from superclass method. Child classes should invoke this method during the configuration phase.- Parameters:
task
- the task to configure- See Also:
AbstractTask.configure(AbstractTask)
-
retrieveExtension
protected static NyxExtension retrieveExtension(Project project)
Returns the instance of the extension for the given project.- Parameters:
project
- the project to return the extension for- Returns:
- the extension for the given project
-
retrieveExtension
protected NyxExtension retrieveExtension()
Returns the instance of the extension for the task.- Returns:
- the extension for the task
-
hasSharedProperty
protected boolean hasSharedProperty(String name)
Returnstrue
if there is a project with the given name stored for the project.- Parameters:
name
- the name of the property to look up- Returns:
true
if there is a project with the given name stored for the project
-
storeSharedProperty
protected void storeSharedProperty(String name, Object value)
Stores the given value as a shared project property with the given name. The name makes the property unique within the entire project.- Parameters:
name
- the name of the property to storevalue
- the value of the property to store
-
retrieveSharedProperty
protected Object retrieveSharedProperty(String name)
Retrieves the shared project property with the given name. The name makes the property unique within the entire project.- Parameters:
name
- the name of the property to retrieve- Returns:
- the value of the shared property with the given name, if any, or
null
if no property with such name is available
-
nyx
protected Nyx nyx() throws DataAccessException, IllegalPropertyException
Returns a shared backing Nyx instance to be used by all tasks within the project. The returned instance is already configured with the values coming from theNyxExtension
. This method also stores the instance as a shared project property so that all subsequent calls can retrieve the same instance to avoid creating multiple instances and saving configuration time. On the other hand, the instance is lazily created upon the first invocation so the Nyx instance is only created when needed.- Returns:
- a shared backing Nyx instance to be used by all tasks within the project.
- Throws:
DataAccessException
- in case the configuration can't be loaded for some reason.IllegalPropertyException
- in case the configuration has some illegal options.
-
state
public State state() throws DataAccessException, IllegalPropertyException
Returns the state of the shared backing Nyx instance.- Returns:
- the state of the shared backing Nyx instance.
- Throws:
DataAccessException
- in case the configuration can't be loaded for some reason.IllegalPropertyException
- in case the configuration has some illegal options.- See Also:
nyx()
-
findTask
protected static TaskProvider<Task> findTask(Project project, String name)
Returns the provider for the task with the given name ornull
if no task has been registered or created with such name in the given project. The returned provider can also be used to set a property and is used for lazy instantiation so the task represented by the provider will only be created when it's actually needed. This is the same asTaskCollection.named(String)
but in case there is no such task returnsnull
instead of throwing an exception. For this reason this method does not trigger the creation of the task if it was only registered, according to Configuration Avoidance.- Parameters:
project
- the project to look up the task intoname
- the name of the task to look up- Returns:
- the provider for the given task or
null
if there is no such task
-
define
protected static <T extends Task> TaskProvider<T> define(Project project, String name, Class<T> type, Action<? super T> configurationAction)
Registers the task into the given project. Once the task is registered it's not yet instantiated but, instead, a provider object is returned. The provider can also be used to set properties. What's important is that the provider does not instantiate the task until it's actually needed and this prevents unnecessary load. The task is defined lazily so it will be actually created by Gradle only when needed, according to the Configuration Avoidance. For this reasonTaskContainer.register(String, Class, Action)
is used instead ofTaskContainer.create(String, Class, Action)
internally.- Type Parameters:
T
- the task class- Parameters:
project
- the project to define the task forname
- the name to register the task withtype
- the task classconfigurationAction
- the optional action used to configure the task upon creation. It may benull
- Returns:
- the task provider used for the deferred task instantiation
-
-