Class ParseVersionMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="parse-version",
          defaultPhase=VALIDATE,
          threadSafe=true)
    public class ParseVersionMojo
    extends AbstractDefinePropertyMojo
    Parse a version string and set properties containing the component parts of the version. This mojo sets the following properties:
       [propertyPrefix].majorVersion
       [propertyPrefix].minorVersion
       [propertyPrefix].incrementalVersion
       [propertyPrefix].qualifier
       [propertyPrefix].buildNumber
     
    Where the propertyPrefix is the string set in the mojo parameter. The parsing of the above is based on the following format of the version:
      <majorversion [> . <minorversion [> . <incrementalversion ] ] [> - <buildnumber | qualifier ]>
     
    It will be tried to parse the version as an OSGi version. It this is successful the following property will be set accordingly. If this is not possible a warning will be emitted.
       [propertyPrefix].osgiVersion
     
    This goal also sets the following properties:
       [propertyPrefix].nextMajorVersion
       [propertyPrefix].nextMinorVersion
       [propertyPrefix].nextIncrementalVersion
       [propertyPrefix].nextBuildNumber
     
    This goal also sets the following properties:
       [formattedPropertyPrefix].majorVersion
       [formattedPropertyPrefix].minorVersion
       [formattedPropertyPrefix].incrementalVersion
       [formattedPropertyPrefix].buildNumber
     
    This goal also sets the following properties:
       [formattedPropertyPrefix].nextMajorVersion
       [formattedPropertyPrefix].nextMinorVersion
       [formattedPropertyPrefix].nextIncrementalVersion
       [formattedPropertyPrefix].nextBuildNumber
     
    There is another property set which is named [propertyPrefix].qualifier and furthermore another property which is named [propertyPrefix].qualifier? which contains a prefix - if the qualifier contains anything otherwise the whole property is simply empty.
     mvn build-helper:parse-version versions:set \
       -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.\${parsedVersion.incrementalVersion}\${parsedVersion.qualifier?}
     
    The above properties contain simply incremented versions of the parsed version informations. Those can now be used to update the version of your project via the following to the next Major version:
       mvn build-helper:parse-version versions:set \
          -DnewVersion=\${parsedVersion.nextMajorVersion}.0.0 \
          versions:commit
     
    It can of course being used to increment the minor version:
       mvn build-helper:parse-version versions:set \
          -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0 \
          versions:commit
     
    This can make an upgrade of the versions of your project very convenient.
    Since:
    1.3
    Version:
    $Id$
    • Field Detail

      • versionString

        @Parameter(defaultValue="${project.version}")
        private java.lang.String versionString
        The version string to parse.
      • propertyPrefix

        @Parameter(defaultValue="parsedVersion")
        private java.lang.String propertyPrefix
        Prefix string to use for the set of version properties.
      • formattedPropertyPrefix

        @Parameter(defaultValue="formattedVersion")
        private java.lang.String formattedPropertyPrefix
        Prefix string to use for the set of formatted version properties.
        Since:
        3.0.0
      • formatMajor

        @Parameter(defaultValue="%02d")
        private java.lang.String formatMajor
        This can be used to make a particular format of the major number possible like padding it with zeros etc.
        Since:
        3.0.0
      • formatMinor

        @Parameter(defaultValue="%02d")
        private java.lang.String formatMinor
        Since:
        3.0.0
      • formatIncremental

        @Parameter(defaultValue="%02d")
        private java.lang.String formatIncremental
        Since:
        3.0.0
      • formatBuildNumber

        @Parameter(defaultValue="%02d")
        private java.lang.String formatBuildNumber
        Since:
        3.0.0
      • qualifierPrefix

        @Parameter(defaultValue="-")
        private java.lang.String qualifierPrefix
        By using qualifierPrefix you can change the prefix which is used to prefix the qualifier if not empty.
        Since:
        3.1.0
    • Constructor Detail

      • ParseVersionMojo

        public ParseVersionMojo()
    • Method Detail

      • execute

        public void execute()
        Execute the mojo. This sets the version properties on the project.
      • defineVersionProperty

        private void defineVersionProperty​(java.lang.String name,
                                           java.lang.String value)
      • defineFormattedVersionProperty

        private void defineFormattedVersionProperty​(java.lang.String name,
                                                    java.lang.String value)
      • defineVersionProperty

        private void defineVersionProperty​(java.lang.String name,
                                           int value)
      • defineVersionProperty

        private void defineVersionProperty​(java.lang.String name,
                                           long value)
      • parseVersion

        public void parseVersion​(java.lang.String version)
        Parse a version String and add the components to a properties object.
        Parameters:
        version - the version to parse
      • setPropertyPrefix

        public void setPropertyPrefix​(java.lang.String prefix)
        Set property name prefix.
        Parameters:
        prefix - The prefix to be used.
      • setFormattedPropertyPrefix

        public void setFormattedPropertyPrefix​(java.lang.String formattedPropertyPrefix)
        Parameters:
        formattedPropertyPrefix - The prefix used for formatted properties.
      • setFormatMajor

        public void setFormatMajor​(java.lang.String formatMajor)
        Parameters:
        formatMajor - Set the format for major part.
      • setFormatMinor

        public void setFormatMinor​(java.lang.String formatMinor)
        Parameters:
        formatMinor - Set the format for minor part.
      • setFormatIncremental

        public void setFormatIncremental​(java.lang.String formatIncremental)
        Parameters:
        formatIncremental - Set format for incremental part.
      • setFormatBuildNumber

        public void setFormatBuildNumber​(java.lang.String formatBuildNumber)
        Parameters:
        formatBuildNumber - Set the format for the buildNumber part.