Class VersionUtil

java.lang.Object
com.norconex.commons.lang.VersionUtil

public final class VersionUtil extends Object
Version-related convenience methods.
Since:
2.0.0
Author:
Pascal Essiembre
  • Method Details

    • getVersion

      public static String getVersion(Class<?> cls)

      Gets the version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.

      The manifest is often created when the code is packaged for distribution. For instance, if you use Maven, you can ask it to automaticall store implementation details with the manifest file when creating a jar file by setting addDefaultImplementationEntries set to true (see https://maven.apache.org/shared/maven-archiver/).

      If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.

      Parameters:
      cls - the class used to extract version
      Returns:
      the version number or null if not found
    • getVersion

      public static String getVersion(Class<?> cls, String fallback)

      Gets the version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.

      The manifest is often created when the code is packaged for distribution. For instance, if you use Maven, you can ask it to automaticall store implementation details with the manifest file when creating a jar file by setting addDefaultImplementationEntries set to true (see https://maven.apache.org/shared/maven-archiver/).

      If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.

      Parameters:
      cls - the class used to extract version
      fallback - text to return when no version could be found
      Returns:
      the version number or the fallback value if not found
    • getDetailedVersion

      public static String getDetailedVersion(Class<?> cls)

      Gets the detailed version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.

      The manifest is often created when the code is packaged for distribution. For instance, if you use Maven, you can ask it to automaticall store implementation details with the manifest file when creating a jar file by setting addDefaultImplementationEntries set to true (see https://maven.apache.org/shared/maven-archiver/).

      If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.

      Parameters:
      cls - the class used to extract version
      Returns:
      the version number or the fallback value if not found
    • getDetailedVersion

      public static String getDetailedVersion(Class<?> cls, String fallback)

      Gets the detailed version from the project or library the provided class belongs to. This method attempts to read that version information from the class package implementation details, normally found in jar manifest files.

      The manifest is often created when the code is packaged for distribution. For instance, if you use Maven, you can ask it to automatically store implementation details with the manifest file when creating a jar file by setting addDefaultImplementationEntries set to true (see https://maven.apache.org/shared/maven-archiver/).

      If developing (not yet packaged), an attempt is made to locate a pom.xml and load the version from it.

      Parameters:
      cls - the class used to extract version
      fallback - text to return when no version could be found
      Returns:
      the version number or the fallback value if not found