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 aState
and aRepository
parameter.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCommand(State state, Repository repository)
Standard constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
getLatestCommit()
Returns the SHA-1 identifier of the last commit in the current branch.protected boolean
isInternalAttributeUpToDate(String attributeName, Object expectedValue)
Returnstrue
if the internal attributes map contains an attribute with the given name and its value equals the given expected value.protected boolean
isRepositoryClean()
Returnstrue
if the repository is in a clean state (no uncommitted changes).Repository
repository()
Returns the repository object.State
state()
Returns the state object.protected void
storeInternalAttribute(String attributeName, Object attributeValue)
Stores the attribute with the given name to the internal attributes map.-
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:
state
in 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.
-
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
code
if 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 GitException
Returnstrue
if the repository is in a clean state (no uncommitted changes).- Returns:
true
if 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)
Returnstrue
if 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 benull
expectedValue
- the expected value of the attribute. It may benull
- Returns:
true
if the internal attributes map contains an attribute with the given name and its value equals the given expected value.
-
storeInternalAttribute
protected void storeInternalAttribute(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 benull
attributeValue
- the value of the attribute. It may benull
-
-