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 StringKey to use for the build time in properties files.static final StringKey to use for the build version in properties files.static final StringKey to use for the commit in properties files.static final StringKey to use for the key in properties files.static final StringKey to use for the system in properties files. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thebuildTimerecord component.commit()Returns the value of thecommitrecord component.static BuildInfocreate(CharSequence versionString, CharSequence zonedDateTimeBuild, String key) Creates a new instance ofBuildInfousing the provided version string, build timestamp, and key.static BuildInfocreate(CharSequence versionString, CharSequence zonedDateTimeBuild, String key, String commit, String system) Creates a new instance ofBuildInfousing the provided version string, build timestamp, key, commit, and system.static BuildInfoLoad properties from resource and return BuildInfo.static BuildInfocreate(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 booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.key()Returns the value of thekeyrecord component.system()Returns the value of thesystemrecord component.toString()Returns a string representation of this record class.version()Returns the value of theversionrecord component.voidwriteToPropertiesFile(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 aBuildInforecord class.
-
-
Method Details
-
create
public static BuildInfo create(CharSequence versionString, CharSequence zonedDateTimeBuild, String key, String commit, String system) Creates a new instance ofBuildInfousing the provided version string, build timestamp, key, commit, and system.- Parameters:
versionString- the version string to parse into aVersionobject, in the format "major.minor.patch" or "major.minor.patch-suffix"zonedDateTimeBuild- the string representing the build timestamp, to be parsed as aZonedDateTimekey- the key associated with the build informationcommit- the commit informationsystem- the system information- Returns:
- a new
BuildInfoinstance 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 ofBuildInfousing the provided version string, build timestamp, and key. Uses empty strings for commit and system.- Parameters:
versionString- the version string to parse into aVersionobject, in the format "major.minor.patch" or "major.minor.patch-suffix"zonedDateTimeBuild- the string representing the build timestamp, to be parsed as aZonedDateTimekey- the key associated with the build information- Returns:
- a new
BuildInfoinstance 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
BuildInfoobject - 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 theversionrecord component.- Returns:
- the value of the
versionrecord component
-
buildTime
Returns the value of thebuildTimerecord component.- Returns:
- the value of the
buildTimerecord component
-
key
Returns the value of thekeyrecord component.- Returns:
- the value of the
keyrecord component
-
commit
Returns the value of thecommitrecord component.- Returns:
- the value of the
commitrecord component
-
system
Returns the value of thesystemrecord component.- Returns:
- the value of the
systemrecord component
-