Class VersionUtil
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckForVersionEquality(Context context, Class<?> dependerClass, Class<?> dependencyClass, String dependentName, String dependencyName) static voidcheckForVersionEquality(Context context, Class<?> dependerClass, String dependencyVersion, String dependentName, String dependencyName) static voidcheckForVersionEquality(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.static voidcompareExpectedAndFoundVersion(Context context, String actualDependencyVersion, Class<?> dependerClass, String dependerVersion, String dependerName, String dependencyName) static StringgetArtifactVersionBySelfDeclaredProperties(Class<?> aClass, String moduleName) Retrieves the version of a module using a properties file associated with the module.static StringgetVersionOfArtifact(Class<?> aClass) Retrieves the version of an artifact, such as logback-core.jar, logback-access-common.jar etc.static String
-
Constructor Details
-
VersionUtil
public VersionUtil()
-
-
Method Details
-
getVersionOfArtifact
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
-
getArtifactVersionBySelfDeclaredProperties
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
moduleNameparameter, in the same location, e.g. package, as theaClassparameter. 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 ismoduleName-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 packagemoduleName- 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
-
checkForVersionEquality
-
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 addeddependentVersion- the version string of the dependent componentdependencyVersion- the version string of the dependency componentdependentName- the name of the dependent componentdependencyName- the name of the dependency component- Since:
- 1.5.26
-
compareExpectedAndFoundVersion
-