Class Versions


  • public final class Versions
    extends Object
    Useful methods for retrieving versions from JARs and POMs associated with Class objects.
    Author:
    Curtis Rueden, Mark Hiner
    • Method Detail

      • of

        public static String of​(Class<?> c)
        Looks up the version of the specified class using any means available, appending the build number to any SNAPSHOT version. Will only search POMs in the base directory.
        Parameters:
        c - - Look up this class's version
        Returns:
        Version of specified Class or null if not found.
      • of

        public static String of​(Class<?> c,
                                String groupId,
                                String artifactId)
        Looks up the version of the specified class using any means available, appending the build number to any SNAPSHOT version. The groupId and artifactId parameters allow specification of the POM lookup path.
        Parameters:
        c - - Look up this class's version
        groupId - - Maven group ID containing class
        artifactId - - Maven artifact ID containing class
        Returns:
        Version of specified Class or null if not found.
      • fromManifest

        public static String fromManifest​(Class<?> c)
        Looks up the version of the specified class using a JAR manifest if available, appending the build number to any SNAPSHOT version.
        Parameters:
        c - - Look up this class's version
        Returns:
        Version of specified Class or null if not found.
      • fromPOM

        public static String fromPOM​(Class<?> c,
                                     String groupId,
                                     String artifactId)
        Looks up the version of the specified class using the specified POM, or base POM directory if groupId and artifactId are null.
        Parameters:
        c - - Look up this class's version
        groupId - - Maven group ID containing class
        artifactId - - Maven artifact ID containing class
        Returns:
        Version of specified Class or null if not found.
      • buildNumber

        public static String buildNumber​(Class<?> c)
        Looks up the build number (typically an SCM revision) of the specified class. This information is retrieved from the JAR manifest's Implementation-Build entry, or null if no such value exists.
        Parameters:
        c - - Look up this class's build number
        Returns:
        Build number of specified Class or null if not found.
      • compare

        public static int compare​(String v1,
                                  String v2)
        Compares two version strings.
        Parameters:
        v1 - The first version string.
        v2 - The second version string.
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.