Record Class BuildInfo

java.lang.Object
java.lang.Record
com.dua3.utility.lang.BuildInfo
Record Components:
version - the version
buildTime - the build timestamp
key - the key associated with the build information
commit - the commit information
system - 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 Details

    • KEY_BUILD_VERSION

      public static final String KEY_BUILD_VERSION
      Key to use for the build version in properties files.
      See Also:
    • KEY_BUILD_TIME

      public static final String KEY_BUILD_TIME
      Key to use for the build time in properties files.
      See Also:
    • KEY_PUBLIC_KEY

      public static final String KEY_PUBLIC_KEY
      Key to use for the key in properties files.
      See Also:
    • KEY_COMMIT

      public static final String KEY_COMMIT
      Key to use for the commit in properties files.
      See Also:
    • KEY_SYSTEM

      public static final String 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 a BuildInfo record class.
      Parameters:
      version - the value for the version record component
      buildTime - the value for the buildTime record component
      key - the value for the key record component
      commit - the value for the commit record component
      system - the value for the system record component
  • Method Details

    • create

      public static BuildInfo create(CharSequence versionString, CharSequence zonedDateTimeBuild, String key, String commit, String system)
      Creates a new instance of BuildInfo using the provided version string, build timestamp, key, commit, and system.
      Parameters:
      versionString - the version string to parse into a Version object, in the format "major.minor.patch" or "major.minor.patch-suffix"
      zonedDateTimeBuild - the string representing the build timestamp, to be parsed as a ZonedDateTime
      key - the key associated with the build information
      commit - the commit information
      system - 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 of BuildInfo using the provided version string, build timestamp, and key. Uses empty strings for commit and system.
      Parameters:
      versionString - the version string to parse into a Version object, in the format "major.minor.patch" or "major.minor.patch-suffix"
      zonedDateTimeBuild - the string representing the build timestamp, to be parsed as a ZonedDateTime
      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

      public static BuildInfo create(Properties properties)
      Create instance from properties.
      Parameters:
      properties - the properties instance; use keys as described above
      Returns:
      BuildInfo instance
    • create

      public static BuildInfo create(Class<?> cls, String resource) throws IOException
      Load properties from resource and return BuildInfo.
      Parameters:
      cls - the class used to load the properties; typically the class whose package contains the resource
      resource - 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 error
      IllegalStateException - if buildinfo could not be loaded due an invalid resource
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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

      public void writeToPropertiesFile(Path destination) throws IOException
      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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • version

      public Version version()
      Returns the value of the version record component.
      Returns:
      the value of the version record component
    • buildTime

      public ZonedDateTime buildTime()
      Returns the value of the buildTime record component.
      Returns:
      the value of the buildTime record component
    • key

      public String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • commit

      public String commit()
      Returns the value of the commit record component.
      Returns:
      the value of the commit record component
    • system

      public String system()
      Returns the value of the system record component.
      Returns:
      the value of the system record component