On Tue, 2009-07-21 at 10:24 +0100, Russel Winder wrote:
> 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 :)

There is already a GradleVersion class (@author Hans Dockter :-) but it
seems there just to broker various strings.  It could perhaps become a
little more of a proactive thing?

I am guessing wildly here about the differing roles of
build.gradleVersion and GradleVersion.  I am happy to put in time to do
the evolution if the function below can't be slipped in comfortably, but
it would help if someone who knows the current rationale for the
build.gradleVersion and GradleVersion could put up a few sentences
explaining.

Thanks.

> 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