Package com.dua3.utility.lang
Record Class BuildInfo
java.lang.Object
java.lang.Record
com.dua3.utility.lang.BuildInfo
- Record Components:
version
- the versionbuildTime
- the build timestampkey
- the key associated with the build informationcommit
- the commit informationsystem
- the system information
public record BuildInfo(Version version, ZonedDateTime buildTime, String key, String commit, String system)
extends Record
A record class representing build information, including build time and version components.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Key to use for the build time in properties files.static final String
Key to use for the build version in properties files.static final String
Key to use for the commit in properties files.static final String
Key to use for the key in properties files.static final String
Key to use for the system in properties files. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thebuildTime
record component.commit()
Returns the value of thecommit
record component.static BuildInfo
create
(CharSequence versionString, CharSequence zonedDateTimeBuild, String key) Creates a new instance ofBuildInfo
using the provided version string, build timestamp, and key.static BuildInfo
create
(CharSequence versionString, CharSequence zonedDateTimeBuild, String key, String commit, String system) Creates a new instance ofBuildInfo
using the provided version string, build timestamp, key, commit, and system.static BuildInfo
Load properties from resource and return BuildInfo.static BuildInfo
create
(Properties properties) Create instance from properties.byte[]
digest()
Computes the SHA-256 hash of the concatenated string representation of the version and build time.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.key()
Returns the value of thekey
record component.system()
Returns the value of thesystem
record component.toString()
Returns a string representation of this record class.version()
Returns the value of theversion
record component.void
writeToPropertiesFile
(Path destination) Writes the build information as properties to the specified file destination.
-
Field Details
-
KEY_BUILD_VERSION
Key to use for the build version in properties files.- See Also:
-
KEY_BUILD_TIME
Key to use for the build time in properties files.- See Also:
-
KEY_PUBLIC_KEY
Key to use for the key in properties files.- See Also:
-
KEY_COMMIT
Key to use for the commit in properties files.- See Also:
-
KEY_SYSTEM
Key to use for the system in properties files.- See Also:
-
-
Constructor Details
-
BuildInfo
public BuildInfo(Version version, ZonedDateTime buildTime, String key, String commit, String system) Creates an instance of aBuildInfo
record class.
-
-
Method Details
-
create
public static BuildInfo create(CharSequence versionString, CharSequence zonedDateTimeBuild, String key, String commit, String system) Creates a new instance ofBuildInfo
using the provided version string, build timestamp, key, commit, and system.- Parameters:
versionString
- the version string to parse into aVersion
object, in the format "major.minor.patch" or "major.minor.patch-suffix"zonedDateTimeBuild
- the string representing the build timestamp, to be parsed as aZonedDateTime
key
- the key associated with the build informationcommit
- the commit informationsystem
- the system information- Returns:
- a new
BuildInfo
instance containing the parsed build time, version, key, commit, and system - Throws:
IllegalArgumentException
- if the version string is invalid or the build timestamp cannot be parsed
-
create
public static BuildInfo create(CharSequence versionString, CharSequence zonedDateTimeBuild, String key) Creates a new instance ofBuildInfo
using the provided version string, build timestamp, and key. Uses empty strings for commit and system.- Parameters:
versionString
- the version string to parse into aVersion
object, in the format "major.minor.patch" or "major.minor.patch-suffix"zonedDateTimeBuild
- the string representing the build timestamp, to be parsed as aZonedDateTime
key
- the key associated with the build information- Returns:
- a new
BuildInfo
instance containing the parsed build time, version, and key - Throws:
IllegalArgumentException
- if the version string is invalid or the build timestamp cannot be parsed
-
create
Create instance from properties.- Parameters:
properties
- the properties instance; use keys as described above- Returns:
- BuildInfo instance
-
create
Load properties from resource and return BuildInfo.- Parameters:
cls
- the class used to load the properties; typically the class whose package contains the resourceresource
- the name of the resource file to load the build information from- Returns:
- BuildInfo instance
- Throws:
IOException
- if buildinfo could not be loaded due to an I/O errorIllegalStateException
- if buildinfo could not be loaded due an invalid resource
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
digest
public byte[] digest()Computes the SHA-256 hash of the concatenated string representation of the version and build time.- Returns:
- a byte array containing the SHA-256 digest of the string representation of this
BuildInfo
object - Throws:
IllegalStateException
- if the SHA-256 algorithm is not available
-
writeToPropertiesFile
Writes the build information as properties to the specified file destination. Each field of the build information, such as version, build time, key, commit, and system, is written as a key-value pair into the generated properties file.- Parameters:
destination
- the path where the properties file should be written- Throws:
IOException
- if an I/O error occurs while writing to the specified destination
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
version
Returns the value of theversion
record component.- Returns:
- the value of the
version
record component
-
buildTime
Returns the value of thebuildTime
record component.- Returns:
- the value of the
buildTime
record component
-
key
Returns the value of thekey
record component.- Returns:
- the value of the
key
record component
-
commit
Returns the value of thecommit
record component.- Returns:
- the value of the
commit
record component
-
system
Returns the value of thesystem
record component.- Returns:
- the value of the
system
record component
-