On Tue, 2009-07-21 at 10:50 +0200, Hans Dockter wrote:
[ . . . ]
> Good point. Could you write a Jira to provide such a Version class? An  
> implementation would also be excellent :)

I wonder if we actually need a full class (though that would probably be
a better solution).  We could just add a function to compare to the
current string as below.

Clearly amending to a class instead of a string would be a bigger
change, but then where would a function such as below need to go?

Let me know what your preference is.

        /**
         *  Gradle version number comparator.
         *
         *  <p>Gradle release version numbers are of the form X.Y.Z, whereas 
development versions are of the form
         *  X.Y-ZZZZZZZZZZZZZZ+ZZZZ.  Nothing should ever depend on the bug-fix 
release number, so we only need to
         *  care about the major and minor numbers. This means we can interpret 
version numbers as real numbers and
         *  thus obtain a total order.</p>
         *
         *  @param expected The version number to compare the current version 
against. Maybe a {...@code String} or a
         *  {...@code Number}.
         *  @return -1 if the actual is less than the expected, 0 if they are 
equal and +1 if the actual is greater
         *  than the expected.
         *
         *  @author Russel Winder <[email protected]>
         *  @version 2009-07-21_01
         */
        def compareGradleVersionNumberTo ( expected ) {
          def actual = build.gradleVersion.split ( '-' ) [0] as Double
          assert actual instanceof Number
          if ( expected instanceof String ) {
            expected = expected.split ( '\\.' )
            assert expected.size ( ) >= 2
            expected = ( expected[0] + '.' + expected[1] ) as Double
          }
          assert expected instanceof Number
          actual.compareTo ( expected )
        }


-- 
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: [email protected]
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:[email protected]
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to