Class VersionUtil

java.lang.Object
ch.qos.logback.core.util.VersionUtil

public class VersionUtil extends Object
Utility class for handling and validating version information of various artifacts.

It is used by logback-classic, logback-access-common, logback-access-jetty11, logback-access-tomcat, etc. to alert users about version discrepancies between dependent and dependee artifacts.

Since:
1.5.25
  • Constructor Details

  • Method Details

    • getVersionOfArtifact

      public static String getVersionOfArtifact(Class<?> aClass)
      Retrieves the version of an artifact, such as logback-core.jar, logback-access-common.jar etc.

      The aClass parameter is assumed to be part of the artifact.

      The method first attempts to get the version from the module information. If the module version is not available, it falls back to retrieving the implementation version from the package.

      Parameters:
      aClass - the class from which to retrieve the version information
      Returns:
      the version of the artifact where aClass is found, or null if the version cannot be determined
    • nonNull

      public static String nonNull(String input)
    • getArtifactVersionBySelfDeclaredProperties

      public static String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass, String moduleName)
      Retrieves the version of a module using a properties file associated with the module.

      Unfortunately, this code cannot be called by other modules. It needs to be duplicated.

      The method looks for a properties file with a name derived from the moduleName parameter, in the same location, e.g. package, as the aClass parameter. It attempts to load the properties file and fetch the version information using a specific key.

      The properties file is expected to be in the same package as the class provided, and named moduleName-version.properties. The properties file should contain a single key-value pair, where the key is moduleName-version, and the value is the module version.

      Parameters:
      aClass - the class used to locate the resource file, the properties file is expected to be in the same package
      moduleName - the name of the module, which is used to construct the properties file name and the key
      Returns:
      the version of the module as a string, or null if the version cannot be determined
      Since:
      1.5.26
    • checkForVersionEquality

      public static void checkForVersionEquality(Context context, Class<?> dependerClass, Class<?> dependencyClass, String dependentName, String dependencyName)
    • checkForVersionEquality

      public static void checkForVersionEquality(Context context, Class<?> dependerClass, String dependencyVersion, String dependentName, String dependencyName)
    • checkForVersionEquality

      public static void checkForVersionEquality(Context context, String dependentVersion, String dependencyVersion, String dependentName, String dependencyName)
      Compares the versions of a dependent and a dependency to determine if they are equal. Updates the context's status manager with version information and logs a warning if the versions differ.
      Parameters:
      context - the logging context to which status messages are added
      dependentVersion - the version string of the dependent component
      dependencyVersion - the version string of the dependency component
      dependentName - the name of the dependent component
      dependencyName - the name of the dependency component
      Since:
      1.5.26
    • compareExpectedAndFoundVersion

      public static void compareExpectedAndFoundVersion(Context context, String actualDependencyVersion, Class<?> dependerClass, String dependerVersion, String dependerName, String dependencyName)