Package com.mooltiverse.oss.nyx.command
Class Mark
java.lang.Object
com.mooltiverse.oss.nyx.command.Mark
- All Implemented Interfaces:
Command
The Mark command takes care of tagging and committing into the Git repository.
This class is not meant to be used in multi-threaded environments.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns 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 StringReturns 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 booleanReturnstrueif the repository is in a clean state (no uncommitted changes).booleanReturnstrueif this command is up to date, which means that the internal state (Command.state()) would not change by running (Command.run()) the command again.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).final RepositoryReturns the repository object.protected ReleaseServiceresolveReleaseService(String name) Returns theReleaseServicewith the given configuration name and also resolves its configuration option templates.protected ReleaseTypeSelects the right release type among those configured based on their matching attributes.resolveServiceOptions(Map<String, String> options) Resolves the given options by rendering each value of the given map as a template.run()Commits pending changes to the Git repository, applies release tags and pushes changes to remotes.final Statestate()Returns the state object.
-
Constructor Details
-
Mark
Standard constructor.- Parameters:
state- the state referencerepository- the repository reference- Throws:
NullPointerException- if a given argument isnull
-
-
Method Details
-
isUpToDate
Returnstrueif this command is up to date, which means that the internal state (Command.state()) would not change by running (Command.run()) the command again. It other words, when this method returnstrueany invocation of the (Command.run()) method is needless and idempotent about the state. This method uses the quickest method to verify whether the state is up to date or not. This method must not rely on dependencies and it must always evaluate its own status independently. As a general rule this method checks if its inputs (i.e. from the configuration) have changed since the last run.- Returns:
trueif this command is up to date- 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.- See Also:
-
run
public State run() throws DataAccessException, IllegalPropertyException, GitException, ReleaseExceptionCommits pending changes to the Git repository, applies release tags and pushes changes to remotes.
Inputs to this task are:
- the Git repository and the commit history;
- thereleaseTypeCommand.state()attribute group, bringing flags for operations (commit, tag, push) to be performed or not. More specifically these attributes arereleaseType/gitCommit,releaseType/gitTag, andreleaseType/gitPush, plusreleaseType/gitCommitMessageandreleaseType/gitTagMessagetelling the format of messages - thereleaseScope/initialCommitwith the SHA-1 of the initial commit in the release scope; ifnullthis task just exits taking no act - thenewVersionCommand.state()flag, that must betruefor this task to run, otherwise it just skips
Outputs from this task are operations executed on the Git repository plus some attributes stored in the State object with more detail:
- thereleaseScope/finalCommitis defined with the SHA-1 of the last commit, which may be a new commit created by this task (if pending changes are found and if configured to do so) or the most recent commit that in the current branch; if the user overrides the version by configuration this value remainsnull- Returns:
- the updated reference to the state object. The returned object is the same instance passed in the constructor.
- 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.- See Also:
-
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
Returns the repository object.- Returns:
- the repository object.
-
getCurrentBranch
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:
-
getLatestCommit
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:
-
isRepositoryClean
Returnstrueif 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:
-
isInternalAttributeUpToDate
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
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 get. It can't benull- Returns:
- the value of the attribute, if available, otherwise
null
-
putInternalAttribute
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
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
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
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.
-
resolveServiceOptions
protected Map<String,String> resolveServiceOptions(Map<String, String> options) throws IllegalPropertyExceptionResolves the given options by rendering each value of the given map as a template. Keys are left unchanged.- Parameters:
options- the options to resolve.- Returns:
- a new map with the same keys as the input map but values resolved as templates.
- Throws:
IllegalPropertyException- in case the given values can't be rendered as templates.
-
resolveReleaseService
protected ReleaseService resolveReleaseService(String name) throws DataAccessException, IllegalPropertyException, ReleaseException, UnsupportedOperationException Returns theReleaseServicewith the given configuration name and also resolves its configuration option templates.- Parameters:
name- the name of the service configuration.- Returns:
- the resolved service. Returns
nullif no service with such configuration name exists. - Throws:
DataAccessException- in case the configuration can't be loaded for some reason.IllegalPropertyException- in case the configuration has some illegal options.ReleaseException- if the task is unable to complete for reasons due to the release process.UnsupportedOperationException- if the service configuration exists but the service class does notsupporttheService.Feature.RELEASESfeature.
-
resolveReleaseType
protected ReleaseType resolveReleaseType() throws DataAccessException, IllegalPropertyException, GitException, ReleaseExceptionSelects 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.
-