Package com.mooltiverse.oss.nyx.command
Class AbstractCommand
- java.lang.Object
-
- com.mooltiverse.oss.nyx.command.AbstractCommand
-
- All Implemented Interfaces:
Command
public abstract class AbstractCommand extends Object implements Command
The common superclass for Nyx commands. This class is not meant to be used in multi-threaded environments. All implementing classes must have a public constructor that accept aStateand aRepositoryparameter.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCommand(State state, Repository repository)Standard constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringgetCurrentBranch()Returns the name of the current branch or a commit SHA-1 if the repository is in the detached head state.protected StringgetInternalAttribute(String attributeName)Retrieves the attribute with the given name from the internal attributes map.protected StringgetLatestCommit()Returns the SHA-1 identifier of the last commit in the current branch.protected booleanisInternalAttributeUpToDate(String attributeName, Object expectedValue)Returnstrueif the internal attributes map contains an attribute with the given name and its value equals the given expected value.protected booleanisRepositoryClean()Returnstrueif the repository is in a clean state (no uncommitted changes).protected voidputInternalAttribute(String attributeName, Object attributeValue)Stores the attribute with the given name to the internal attributes map.protected StringrenderTemplate(String template)Renders the given template using the internalStateobject as the context.protected BooleanrenderTemplateAsBoolean(String template)Renders the given template using the internalStateobject as the context, returning the boolean value, according toTemplates.toBoolean(String).protected IntegerrenderTemplateAsInteger(String template)Renders the given template using the internalStateobject as the context, returning the integer value, according toTemplates.toInteger(String).Repositoryrepository()Returns the repository object.protected ReleaseTyperesolveReleaseType()Selects the right release type among those configured based on their matching attributes.Statestate()Returns the state object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.mooltiverse.oss.nyx.command.Command
isUpToDate, run
-
-
-
-
Constructor Detail
-
AbstractCommand
protected AbstractCommand(State state, Repository repository)
Standard constructor.- Parameters:
state- the state referencerepository- the repository reference- Throws:
NullPointerException- if a given argument isnull
-
-
Method Detail
-
state
public final State state()
Returns the state object.- Specified by:
statein interfaceCommand- Returns:
- the state object that was passed in the constructor (never
null, even when or afterCommand.run()returnsnull).
-
repository
public final Repository repository()
Returns the repository object.- Returns:
- the repository object.
-
getCurrentBranch
protected String getCurrentBranch() throws GitException
Returns the name of the current branch or a commit SHA-1 if the repository is in the detached head state.- Returns:
- the name of the current branch or a commit SHA-1 if the repository is in the detached head state.
- Throws:
GitException- in case of unexpected issues when accessing the Git repository.- See Also:
repository()
-
getLatestCommit
protected String getLatestCommit() throws GitException
Returns the SHA-1 identifier of the last commit in the current branch.- Returns:
- the SHA-1 identifier of the last commit in the current branch or
codeif the repository has no commits yet. - Throws:
GitException- in case of unexpected issues when accessing the Git repository.- See Also:
repository()
-
isRepositoryClean
protected boolean isRepositoryClean() throws GitExceptionReturnstrueif the repository is in a clean state (no uncommitted changes).- Returns:
trueif the repository is in a clean state (no uncommitted changes).- Throws:
GitException- in case of unexpected issues when accessing the Git repository.- See Also:
repository()
-
isInternalAttributeUpToDate
protected boolean isInternalAttributeUpToDate(String attributeName, Object expectedValue)
Returnstrueif the internal attributes map contains an attribute with the given name and its value equals the given expected value. The comparison is always performed using theObject.toString()method of the expected value.- Parameters:
attributeName- the name of the attribute to check. It can't benullexpectedValue- the expected value of the attribute. It may benull- Returns:
trueif the internal attributes map contains an attribute with the given name and its value equals the given expected value.
-
getInternalAttribute
protected String getInternalAttribute(String attributeName)
Retrieves the attribute with the given name from the internal attributes map. The returned value is always theObject.toString()representation of the stored value.- Parameters:
attributeName- the name of the attribute to store. It can't benull- Returns:
- the value of the attribute, if available, otherwise
null
-
putInternalAttribute
protected void putInternalAttribute(String attributeName, Object attributeValue)
Stores the attribute with the given name to the internal attributes map. The stored value is always performed theObject.toString()of the given value.- Parameters:
attributeName- the name of the attribute to store. It can't benullattributeValue- the value of the attribute. It may benull
-
renderTemplate
protected String renderTemplate(String template) throws IllegalPropertyException
Renders the given template using the internalStateobject as the context.- Parameters:
template- the string template to render.- Returns:
- the rendered template. It is
nullif the given template isnull. - Throws:
IllegalPropertyException- in case the given template can't be rendered.
-
renderTemplateAsBoolean
protected Boolean renderTemplateAsBoolean(String template) throws IllegalPropertyException
Renders the given template using the internalStateobject as the context, returning the boolean value, according toTemplates.toBoolean(String).- Parameters:
template- the string template to render.- Returns:
- the rendered template as boolean. It is
falseif the given template isnull. - Throws:
IllegalPropertyException- in case the given template can't be rendered.
-
renderTemplateAsInteger
protected Integer renderTemplateAsInteger(String template) throws IllegalPropertyException
Renders the given template using the internalStateobject as the context, returning the integer value, according toTemplates.toInteger(String).- Parameters:
template- the string template to render.- Returns:
- the rendered template as integer. It is
0if the given template isnull. - Throws:
IllegalPropertyException- in case the given template can't be rendered.
-
resolveReleaseType
protected ReleaseType resolveReleaseType() throws DataAccessException, IllegalPropertyException, GitException, ReleaseException
Selects the right release type among those configured based on their matching attributes.- Returns:
- the resolved release type. Never
null. - Throws:
DataAccessException- in case the configuration can't be loaded for some reason.IllegalPropertyException- in case the configuration has some illegal options.GitException- in case of unexpected issues when accessing the Git repository.ReleaseException- if the task is unable to complete for reasons due to the release process.
-
-