ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r437907 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java
Date Tue, 29 Aug 2006 01:51:48 GMT
Author: kevj
Date: Mon Aug 28 18:51:47 2006
New Revision: 437907

URL: http://svn.apache.org/viewvc?rev=437907&view=rev
Log:
as requested a refactoring that doesn't use indexOf - test passes with 1.7.0Beta1

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=437907&r1=437906&r2=437907&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 Mon Aug
28 18:51:47 2006
@@ -58,24 +58,36 @@
         if (null == atLeast && null == exactly) {
             throw new BuildException("One of atleast or exactly must be set.");
         }
+        try {
+            if (atLeast != null) {
+                new DeweyDecimal(atLeast);
+            } else {
+                new DeweyDecimal(exactly);
+            }
+        } catch (NumberFormatException e) {
+            throw new BuildException("The argument is not a Dewey Decimal eg 1.1.0");
+        }
     }
-    
+        
     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("Ant version")+17);
-        char[] cs = v.toCharArray();
-        int end = cs.length;
-        for (int i = cs.length; i > 0; i--) {
-            if (!Character.isLetter(cs[i-1])) {
-                end = i;
+        char[] versionString = p.getProperty("ant.version").toCharArray();
+        StringBuffer sb = new StringBuffer();
+        boolean foundFirstDigit = false;
+        for (int i=0; i<versionString.length; i++) {
+            if (Character.isDigit(versionString[i])) {
+                sb.append(versionString[i]);
+                foundFirstDigit = true;
+            }
+            if  (versionString[i]=='.' && foundFirstDigit) {
+                sb.append(versionString[i]);
+            }
+            if (Character.isLetter(versionString[i]) && foundFirstDigit) {
                 break;
             }
         }
-        v = v.substring(0, end);
-        return new DeweyDecimal(v);
+        return new DeweyDecimal(sb.toString());
     }
     
     public String getAtLeast() {



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


Mime
View raw message