You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ke...@apache.org on 2006/05/26 06:16:47 UTC

svn commit: r409551 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Author: kevj
Date: Thu May 25 21:16:44 2006
New Revision: 409551

URL: http://svn.apache.org/viewvc?rev=409551&view=rev
Log:
implement DeweyDecimal versioning - strip alpha/beta/rc qualifiers from version string first

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java?rev=409551&r1=409550&r2=409551&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java Thu May 25 21:16:44 2006
@@ -19,6 +19,7 @@
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.optional.extension.DeweyDecimal;
 
 /**
  * An antversion condition
@@ -31,16 +32,16 @@
     
     public boolean eval() throws BuildException {
         validate();
-        float actual = getVersion();
+        DeweyDecimal actual = getVersion();
         if (null != atLeast) {
-            if (actual >= Versions.getVersion(atLeast)) {
+            if (actual.isGreaterThanOrEqual(new DeweyDecimal(atLeast))) {
                 return true;
             } else {
                 return false;
             }
         }
         if (null != exactly) {
-            if (actual == Versions.getVersion(exactly)) {
+            if (actual.isEqual(new DeweyDecimal(exactly))) {
                 return true;
             } else {
                 return false;
@@ -59,46 +60,22 @@
         }
     }
     
-    private float getVersion() {
+    private DeweyDecimal getVersion() {
         Project p = new Project();
         p.init();
         String versionString = p.getProperty("ant.version");
         String v = versionString.substring(versionString.indexOf("Ant version")+12, 
                 versionString.indexOf("compiled on")-1);
-        return Versions.getVersion(v);
-    }
-    
-    private static class Versions {
-        static float getVersion(String vs) {
-            if (vs.equals("1.1"))       return 11f;
-            if (vs.equals("1.2"))       return 12f;
-            if (vs.equals("1.3"))       return 13f;
-            if (vs.equals("1.4"))       return 14f;
-            if (vs.equals("1.4.1"))     return 14.1f;
-            if (vs.equals("1.5"))       return 15f;
-            if (vs.equals("1.5.1"))     return 15.1f;
-            if (vs.equals("1.5.2"))     return 15.2f;
-            if (vs.equals("1.5.3"))     return 15.3f;
-            if (vs.equals("1.5.4"))     return 15.4f;
-            if (vs.equals("1.5alpha"))  return 15.880f;
-            if (vs.equals("1.6beta1"))  return 15.991f;
-            if (vs.equals("1.6beta2"))  return 15.992f;
-            if (vs.equals("1.6beta3"))  return 15.993f;
-            if (vs.equals("1.6"))       return 16f;
-            if (vs.equals("1.6.0"))     return 16f;
-            if (vs.equals("1.6.1"))     return 16.1f;
-            if (vs.equals("1.6.2"))     return 16.2f;
-            if (vs.equals("1.6.3"))     return 16.3f;
-            if (vs.equals("1.6.4"))     return 16.4f;
-            if (vs.equals("1.6.5"))     return 16.5f;
-            if (vs.equals("1.7alpha"))  return 16.880f;
-            if (vs.equals("1.7beta"))   return 16.990f;
-            if (vs.equals("1.7"))       return 17f;
-            if (vs.equals("1.7.0"))     return 17f;
-            if (vs.equals("1.7.1"))     return 17.1f;
-            if (vs.equals("1.7.2"))     return 17.2f;
-            return 0f;
+        char[] cs = v.toCharArray();
+        int end = cs.length;
+        for (int i = cs.length; i > 0; i--) {
+            if (!Character.isLetter(cs[i-1])) {
+                end = i;
+                break;
+            }
         }
+        v = v.substring(0, end);
+        return new DeweyDecimal(v);
     }
     
     public String getAtLeast() {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r409551 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Posted by Kev Jackson <fo...@gmail.com>.
On 29 May 2006, at 11:25, Stefan Bodewig wrote:

> On Mon, 29 May 2006, Kev Jackson <fo...@gmail.com> wrote:
>> On 29 May 2006, at 11:05, Stefan Bodewig wrote:
>>
>>> suggest you take the meat of DeweyDecimal and move it to
>>> org.apache.tools.ant.util so that your (core) condition doesn't
>>> depend on an optional jar.
>>
>> Do you mean to basically create a new class in the util package
>> called DeweyDecimal?  With the same basic abilities/properties?
>
> Maybe even move the whole implementation and have the original
> DeweyDecimal class extend it.

Yeah that would retain bc without having to duplicate the code.

I'll do this now before I forget.
Thanks
Kev

--
"All governments are in equal measure good and evil.  The best ideal  
is anarchy." - Leo Tolstoy


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r409551 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 29 May 2006, Kev Jackson <fo...@gmail.com> wrote:
> On 29 May 2006, at 11:05, Stefan Bodewig wrote:
> 
>> suggest you take the meat of DeweyDecimal and move it to
>> org.apache.tools.ant.util so that your (core) condition doesn't
>> depend on an optional jar.
> 
> Do you mean to basically create a new class in the util package
> called DeweyDecimal?  With the same basic abilities/properties?

Maybe even move the whole implementation and have the original
DeweyDecimal class extend it.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r409551 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Posted by Kev Jackson <fo...@gmail.com>.
On 29 May 2006, at 11:05, Stefan Bodewig wrote:

> suggest you take the meat of DeweyDecimal and move it to
> org.apache.tools.ant.util so that your (core) condition doesn't depend
> on an optional jar.

Do you mean to basically create a new class in the util package  
called DeweyDecimal?  With the same basic abilities/properties?

I understand the need to make the condition independent of the  
optional class.  I guess it wouldn't be possible to simply 'move'  
DeweyDecimal to util as that would break bc somewhere else right?

Kev

--
"It is through disobedience that progress has been made, through  
disobedience and through rebellion" - Oscar Wilde


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r409551 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 26 May 2006, <ke...@apache.org> wrote:

> +import
> +org.apache.tools.ant.taskdefs.optional.extension.DeweyDecimal;

I'd suggest you take the meat of DeweyDecimal and move it to
org.apache.tools.ant.util so that your (core) condition doesn't depend
on an optional jar.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org