Class VersionInfo


  • public class VersionInfo
    extends java.lang.Object
    Provides access to version information for HTTP components. Static methods are used to extract version information from property files that are automatically packaged with HTTP component release JARs.

    All available version information is provided in strings, where the string format is informal and subject to change without notice. Version information is provided for debugging output and interpretation by humans, not for automated processing in applications.

    Since:
    4.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String infoClassloader
      The classloader from which the version info was obtained.
      private java.lang.String infoModule
      The module from the version info.
      private java.lang.String infoPackage
      The package that contains the version information.
      private java.lang.String infoRelease
      The release from the version info.
      private java.lang.String infoTimestamp
      The timestamp from the version info.
      static java.lang.String PROPERTY_MODULE  
      static java.lang.String PROPERTY_RELEASE  
      static java.lang.String PROPERTY_TIMESTAMP  
      static java.lang.String UNAVAILABLE
      A string constant for unavailable information.
      static java.lang.String VERSION_PROPERTY_FILE
      The filename of the version information files.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected VersionInfo​(java.lang.String pckg, java.lang.String module, java.lang.String release, java.lang.String time, java.lang.String clsldr)
      Instantiates version information.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static VersionInfo fromMap​(java.lang.String pckg, java.util.Map<?,​?> info, java.lang.ClassLoader clsldr)
      Instantiates version information from properties.
      java.lang.String getClassloader()
      Obtains the classloader used to read the version information.
      java.lang.String getModule()
      Obtains the name of the versioned module or informal unit.
      java.lang.String getPackage()
      Obtains the package name.
      java.lang.String getRelease()
      Obtains the release of the versioned module or informal unit.
      java.lang.String getTimestamp()
      Obtains the timestamp of the versioned module or informal unit.
      static java.lang.String getUserAgent​(java.lang.String name, java.lang.String pkg, java.lang.Class<?> cls)
      Sets the user agent to "<name>/<release> (Java/<java.version>)".
      static VersionInfo[] loadVersionInfo​(java.lang.String[] pckgs, java.lang.ClassLoader clsldr)
      Loads version information for a list of packages.
      static VersionInfo loadVersionInfo​(java.lang.String pckg, java.lang.ClassLoader clsldr)
      Loads version information for a package.
      java.lang.String toString()
      Provides the version information in human-readable format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • UNAVAILABLE

        public static final java.lang.String UNAVAILABLE
        A string constant for unavailable information.
        See Also:
        Constant Field Values
      • VERSION_PROPERTY_FILE

        public static final java.lang.String VERSION_PROPERTY_FILE
        The filename of the version information files.
        See Also:
        Constant Field Values
      • PROPERTY_RELEASE

        public static final java.lang.String PROPERTY_RELEASE
        See Also:
        Constant Field Values
      • PROPERTY_TIMESTAMP

        public static final java.lang.String PROPERTY_TIMESTAMP
        See Also:
        Constant Field Values
      • infoPackage

        private final java.lang.String infoPackage
        The package that contains the version information.
      • infoModule

        private final java.lang.String infoModule
        The module from the version info.
      • infoRelease

        private final java.lang.String infoRelease
        The release from the version info.
      • infoTimestamp

        private final java.lang.String infoTimestamp
        The timestamp from the version info.
      • infoClassloader

        private final java.lang.String infoClassloader
        The classloader from which the version info was obtained.
    • Constructor Detail

      • VersionInfo

        protected VersionInfo​(java.lang.String pckg,
                              java.lang.String module,
                              java.lang.String release,
                              java.lang.String time,
                              java.lang.String clsldr)
        Instantiates version information.
        Parameters:
        pckg - the package
        module - the module, or null
        release - the release, or null
        time - the build time, or null
        clsldr - the class loader, or null
    • Method Detail

      • getPackage

        public final java.lang.String getPackage()
        Obtains the package name. The package name identifies the module or informal unit.
        Returns:
        the package name, never null
      • getModule

        public final java.lang.String getModule()
        Obtains the name of the versioned module or informal unit. This data is read from the version information for the package.
        Returns:
        the module name, never null
      • getRelease

        public final java.lang.String getRelease()
        Obtains the release of the versioned module or informal unit. This data is read from the version information for the package.
        Returns:
        the release version, never null
      • getTimestamp

        public final java.lang.String getTimestamp()
        Obtains the timestamp of the versioned module or informal unit. This data is read from the version information for the package.
        Returns:
        the timestamp, never null
      • getClassloader

        public final java.lang.String getClassloader()
        Obtains the classloader used to read the version information. This is just the toString output of the classloader, since the version information should not keep a reference to the classloader itself. That could prevent garbage collection.
        Returns:
        the classloader description, never null
      • toString

        public java.lang.String toString()
        Provides the version information in human-readable format.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string holding this version information
      • loadVersionInfo

        public static VersionInfo[] loadVersionInfo​(java.lang.String[] pckgs,
                                                    java.lang.ClassLoader clsldr)
        Loads version information for a list of packages.
        Parameters:
        pckgs - the packages for which to load version info
        clsldr - the classloader to load from, or null for the thread context classloader
        Returns:
        the version information for all packages found, never null
      • loadVersionInfo

        public static VersionInfo loadVersionInfo​(java.lang.String pckg,
                                                  java.lang.ClassLoader clsldr)
        Loads version information for a package.
        Parameters:
        pckg - the package for which to load version information, for example "org.apache.http". The package name should NOT end with a dot.
        clsldr - the classloader to load from, or null for the thread context classloader
        Returns:
        the version information for the argument package, or null if not available
      • fromMap

        protected static VersionInfo fromMap​(java.lang.String pckg,
                                             java.util.Map<?,​?> info,
                                             java.lang.ClassLoader clsldr)
        Instantiates version information from properties.
        Parameters:
        pckg - the package for the version information
        info - the map from string keys to string values, for example Properties
        clsldr - the classloader, or null
        Returns:
        the version information
      • getUserAgent

        public static java.lang.String getUserAgent​(java.lang.String name,
                                                    java.lang.String pkg,
                                                    java.lang.Class<?> cls)
        Sets the user agent to "<name>/<release> (Java/<java.version>)".

        For example:

        "Apache-HttpClient/4.3 (Java/1.6.0_35)"
        Parameters:
        name - the component name, like "Apache-HttpClient".
        pkg - the package for which to load version information, for example "org.apache.http". The package name should NOT end with a dot.
        cls - the class' class loader to load from, or null for the thread context class loader
        Since:
        4.3