Class VersionUtils


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

      • VersionUtils

        public VersionUtils()
    • Method Detail

      • getVersion

        public static String getVersion​(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.
      • getVersion

        public static String getVersion​(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.
      • getVersionFromManifest

        public static String getVersionFromManifest​(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.
      • getVersionFromPOM

        public static String getVersionFromPOM​(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.
      • getBuildNumber

        public static String getBuildNumber​(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.