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 BuildInfoLoad properties from a resource and return BuildInfo.static BuildInfoCreates a newBuildInfoinstance using the given version string, key, and commit.static BuildInfocreate(String versionString, ZonedDateTime buildTime, String key) Creates a new instance ofBuildInfousing the provided version string, build timestamp, and key.static BuildInfoCreates a new instance ofBuildInfousing the provided version string, build timestamp, key, commit, and system.static BuildInfocreate(Properties properties) Create an instance from properties.byte[]digest()Computes the SHA-256 hash of the concatenated string representation of all fields of this instance.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()Generates a string representation of theBuildInfoobject.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) Canonical record constructor.- Parameters:
version- the versionbuildTime- the build timestampkey- the key associated with the build informationcommit- the commit informationsystem- the system information
-
-
Method Details
-
create
Creates a newBuildInfoinstance using the given version string, key, and commit. The current timestamp and system information are automatically generated.Note: This method is intended to be called from the build script.
- Parameters:
versionString- the version string to be parsed into aVersionobject. The format should be "major.minor.patch" or "major.minor.patch-suffix".key- the key associated with the build information.commit- the commit information associated with the build.- Returns:
- a new
BuildInfoinstance containing the parsed version, current timestamp, the provided key, the provided commit, and the current system information. - Throws:
IllegalArgumentException- if the version string is invalid.
-
create
public static BuildInfo create(String versionString, ZonedDateTime buildTime, 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"buildTime- the build time and datekey- the key associated with the build informationcommit- the commit informationsystem- the system information- Returns:
- a new
BuildInfoinstance containing the build time, version, key, commit, and system - Throws:
IllegalArgumentException- if the version string is invalid
-
create
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"buildTime- the build timestampkey- 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
-
create
Create an instance from properties.The following keys are required:
- "build.version" - The version number in format major.minor.patch or major.minor.patch-suffix
- "build.time" - The build timestamp
- "build.key" - The public key associated with this build
- "build.commit" - The version control commit identifier
- "build.system" - The system information where the build was created
- Parameters:
properties- the properties instance; use keys as described above- Returns:
- BuildInfo instance
- Throws:
IllegalStateException- if the BuildInfo instance cannot be created from the supplied properties
-
create
Load properties from a 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:
MissingResourceException- if the resource can not be foundIOException- if the BuildInfo could not be loaded due to an I/O errorIllegalStateException- if the BuildInfo could not be loaded due an invalid resource
-
toString
Generates a string representation of theBuildInfoobject. The representation includes version and build time in the format "version (buildTime)". Optional fields, such as commit and system, are included if they are not blank. -
digest
public byte[] digest()Computes the SHA-256 hash of the concatenated string representation of all fields of this instance.- 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
-