Package com.mooltiverse.oss.nyx.state
Class State
- java.lang.Object
-
- com.mooltiverse.oss.nyx.state.State
-
public class State extends Object implements Root
The State class holds a number of attributes resulting from the execution of one or more command and so represents the current status of a release process at a certain point in time. Each command updates the state object with new or modified attributes so the same state instance is shared among all commands. There must be only one instance of this class for every execution and it's retrieved byNyx.state()
.
-
-
Constructor Summary
Constructors Constructor Description State()
Deprecated.State(Configuration configuration)
Standard constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getBump()
Returns the version identifier bumped on the previous release to produce the new release, if any.Configuration
getConfiguration()
Returns the configuration object.File
getDirectory()
Returns the directory used as the working directory as it's defined by the configuration.Map<String,String>
getInternals()
Returns the live map of internal attributes.ReleaseScope
getReleaseScope()
Returns the object modelling the attributes defining the scope of the release.Scheme
getScheme()
Returns the versioning scheme used as it's defined by the configuration.Long
getTimestamp()
Returns the current timestamp.String
getVersion()
Returns the version inferred by Nyx, if any.static State
resume(File stateFile, Configuration configuration)
Loads the state attributes from a previously saved state file.void
setBump(String bump)
Sets the version identifier bumped on the previous release to produce the new release, if any.void
setTimestamp(Long timestamp)
Sets the state timestamp.void
setVersion(String version)
Sets the version inferred by Nyx.Long
touchTimestamp()
Updates the current timestamp and returns the updated value.
-
-
-
Constructor Detail
-
State
@Deprecated public State()
Deprecated.Default constructor. DO NOT USE THIS CONSTRUCTOR AS IT EXISTS ONLY FOR INTERNAL USE WHEN UNMARSHALLING
-
State
public State(Configuration configuration) throws DataAccessException, IllegalPropertyException
Standard constructor.- Parameters:
configuration
- the configuration object held by this state- Throws:
NullPointerException
- if the given argument isnull
DataAccessException
- in case the state file is configured but cannot be read or accessed when resuming from a previously saved state.IllegalPropertyException
- in case the state file is configured but has incorrect values or it can't be resolved when resuming from a previously saved state
-
-
Method Detail
-
resume
public static State resume(File stateFile, Configuration configuration) throws DataAccessException, IllegalPropertyException
Loads the state attributes from a previously saved state file. Note that not all attributes are loaded from the state file as many of them will still be retrieved live from the configuration.- Parameters:
stateFile
- the file to load the state fromconfiguration
- the configuration object to read values from. This object will be set as thegetConfiguration()
of the newly instantiated object too.- Returns:
- the new state object deserialized from the given state file
- Throws:
DataAccessException
- in case the state file cannot be read or accessed.IllegalPropertyException
- in case the state file has incorrect values.
-
getBump
public String getBump() throws DataAccessException, IllegalPropertyException
Returns the version identifier bumped on the previous release to produce the new release, if any. This value is only available afterNyx.infer()
has run.- Specified by:
getBump
in interfaceRoot
- Returns:
- the version identifier bumped on the previous release to produce the new release, if any.
It may be
null
if no identifier has been bumped (i.e. because no significant changes have been detected in the release scope or because inference was inhibited by values overridden by user). - Throws:
DataAccessException
- in case the attribute cannot be read or accessed.IllegalPropertyException
- in case the attribute has been defined but has incorrect values or it can't be resolved.- See Also:
Root.getReleaseScope()
,ReleaseScope.getSignificant()
-
setBump
public void setBump(String bump)
Sets the version identifier bumped on the previous release to produce the new release, if any.- Parameters:
bump
- the version identifier bumped on the previous release to produce the new release, if any. It may benull
.- See Also:
getBump()
-
getConfiguration
public Configuration getConfiguration()
Returns the configuration object. The configuration is a live reference.- Specified by:
getConfiguration
in interfaceRoot
- Returns:
- the configuration object.
-
getDirectory
public File getDirectory() throws DataAccessException, IllegalPropertyException
Returns the directory used as the working directory as it's defined by the configuration.- Specified by:
getDirectory
in interfaceRoot
- Returns:
- the current value for this attribute.
- Throws:
DataAccessException
- in case the attribute cannot be read or accessed.IllegalPropertyException
- in case the attribute has been defined but has incorrect values or it can't be resolved.- See Also:
Configuration.getDirectory()
-
getInternals
public Map<String,String> getInternals()
Returns the live map of internal attributes. Internal attributes are not documented so they must not be used by users as the implementation may change them at any time. Commands and other implementation objects are free to store and remove their own attributes here (i.e. for caching or store their internal state). When handling these attributes, entities must make sure the names (keys) do not overlap, unless for shared attributes. This object takes no control over the values stored in this map. Sensitive informations must not be stored here as they would be exposed when marshalling the attributes to files.- Specified by:
getInternals
in interfaceRoot
- Returns:
- the live map of internal attributes. The returned map is never
null
-
getReleaseScope
public ReleaseScope getReleaseScope()
Returns the object modelling the attributes defining the scope of the release.- Specified by:
getReleaseScope
in interfaceRoot
- Returns:
- the current value for this attribute.
-
getScheme
public Scheme getScheme() throws DataAccessException, IllegalPropertyException
Returns the versioning scheme used as it's defined by the configuration.- Specified by:
getScheme
in interfaceRoot
- Returns:
- the current value for this attribute.
- Throws:
DataAccessException
- in case the attribute cannot be read or accessed.IllegalPropertyException
- in case the attribute has been defined but has incorrect values or it can't be resolved.
-
getTimestamp
public Long getTimestamp()
Returns the current timestamp.- Specified by:
getTimestamp
in interfaceRoot
- Returns:
- the current timestamp.
-
setTimestamp
public void setTimestamp(Long timestamp)
Sets the state timestamp.- Parameters:
timestamp
- the state timestamp.
-
getVersion
public String getVersion() throws DataAccessException, IllegalPropertyException
Returns the version inferred by Nyx, if any. If the version was overridden by configuration this will be the same asConfiguration.getVersion()
. This value is only available afterNyx.infer()
has run.- Specified by:
getVersion
in interfaceRoot
- Returns:
- the current version inferred by Nyx. This is
null
untilNyx.infer()
has run. - Throws:
DataAccessException
- in case the attribute cannot be read or accessed.IllegalPropertyException
- in case the attribute has been defined but has incorrect values or it can't be resolved.- See Also:
Configuration.getVersion()
,Nyx.infer()
,Infer
-
setVersion
public void setVersion(String version)
Sets the version inferred by Nyx.- Parameters:
version
- the version inferred by Nyx.
-
touchTimestamp
public Long touchTimestamp()
Updates the current timestamp and returns the updated value.- Returns:
- the updated timestamp.
- See Also:
getTimestamp()
-
-