ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r409337 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition: AntVersion.java ConditionBase.java antlib.xml
Date Thu, 25 May 2006 09:06:22 GMT
Author: kevj
Date: Thu May 25 02:06:22 2006
New Revision: 409337

URL: http://svn.apache.org/viewvc?rev=409337&view=rev
Log:
add an antversion condition as requested in #32804

Added:
    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/ConditionBase.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml

Added: 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=409337&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/AntVersion.java Thu May
25 02:06:22 2006
@@ -0,0 +1,67 @@
+package org.apache.tools.ant.taskdefs.condition;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+public class AntVersion implements Condition {
+    
+    private String atLeast = null;
+    private String exactly = null;
+    
+    public boolean eval() throws BuildException {
+        validate();
+        String actual = getVersion();
+        if (null != atLeast) {
+            
+            if (Float.valueOf(actual).compareTo(Float.valueOf(atLeast)) >= 0) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        if (null != exactly) {
+            if (Float.valueOf(actual).compareTo(Float.valueOf(exactly)) == 0) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        //default
+        return false;
+    }
+    
+    private void validate() throws BuildException {
+        if (atLeast != null && exactly != null) {
+            throw new BuildException("Only one of atleast or exactly may be set.");
+        }
+        if (null == atLeast && null == exactly) {
+            throw new BuildException("One of atleast or exactly must be set.");
+        }
+    }
+    
+    private String getVersion() {
+        Project p = new Project();
+        p.init();
+        String versionString = p.getProperty("ant.version");
+        String version = versionString.substring(versionString.indexOf("Ant version")+12,

+                versionString.indexOf("compiled on")-1);
+        version = version.replaceAll("alpha","");
+        return version;
+    }
+    
+    public String getAtLeast() {
+        return atLeast;
+    }
+    
+    public void setAtLeast(String atLeast) {
+        this.atLeast = atLeast;
+    }
+    
+    public String getExactly() {
+        return exactly;
+    }
+    
+    public void setExactly(String exactly) {
+        this.exactly = exactly;
+    }   
+}
\ No newline at end of file

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java?rev=409337&r1=409336&r2=409337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java Thu
May 25 02:06:22 2006
@@ -32,25 +32,25 @@
  * @since Ant 1.4
  */
 public abstract class ConditionBase extends ProjectComponent {
-
-
+    
+    
     /**
      * name of the component
      */
     private String taskName="condition";
-
+    
     /**
      *
      */
     private Vector conditions = new Vector();
-
+    
     /**
      * simple constructor.
      */
     protected ConditionBase() {
         taskName = "component";
     }
-
+    
     /**
      * constructor that takes the name of the task
      * in the task name
@@ -60,7 +60,7 @@
     protected ConditionBase(String taskName) {
         this.taskName = taskName;
     }
-
+    
     /**
      * Count the conditions.
      *
@@ -70,7 +70,7 @@
     protected int countConditions() {
         return conditions.size();
     }
-
+    
     /**
      * Iterate through all conditions.
      *
@@ -80,7 +80,7 @@
     protected final Enumeration getConditions() {
         return conditions.elements();
     }
-
+    
     /**
      * Sets the name to use in logging messages.
      *
@@ -91,7 +91,7 @@
     public void setTaskName(String name) {
         this.taskName = name;
     }
-
+    
     /**
      * Returns the name to use in logging messages.
      *
@@ -101,7 +101,7 @@
     public String getTaskName() {
         return taskName;
     }
-
+    
     /**
      * Add an <available> condition.
      * @param a an available condition
@@ -110,7 +110,7 @@
     public void addAvailable(Available a) {
         conditions.addElement(a);
     }
-
+    
     /**
      * Add an <checksum> condition.
      *
@@ -120,7 +120,7 @@
     public void addChecksum(Checksum c) {
         conditions.addElement(c);
     }
-
+    
     /**
      * Add an <uptodate> condition.
      *
@@ -130,7 +130,7 @@
     public void addUptodate(UpToDate u) {
         conditions.addElement(u);
     }
-
+    
     /**
      * Add an <not> condition "container".
      *
@@ -140,7 +140,7 @@
     public void addNot(Not n) {
         conditions.addElement(n);
     }
-
+    
     /**
      * Add an <and> condition "container".
      *
@@ -150,7 +150,7 @@
     public void addAnd(And a) {
         conditions.addElement(a);
     }
-
+    
     /**
      * Add an <or> condition "container".
      *
@@ -160,7 +160,7 @@
     public void addOr(Or o) {
         conditions.addElement(o);
     }
-
+    
     /**
      * Add an <equals> condition.
      *
@@ -170,7 +170,7 @@
     public void addEquals(Equals e) {
         conditions.addElement(e);
     }
-
+    
     /**
      * Add an <os> condition.
      *
@@ -180,7 +180,7 @@
     public void addOs(Os o) {
         conditions.addElement(o);
     }
-
+    
     /**
      * Add an <isset> condition.
      *
@@ -190,7 +190,7 @@
     public void addIsSet(IsSet i) {
         conditions.addElement(i);
     }
-
+    
     /**
      * Add an <http> condition.
      *
@@ -200,7 +200,7 @@
     public void addHttp(Http h) {
         conditions.addElement(h);
     }
-
+    
     /**
      * Add a <socket> condition.
      *
@@ -210,7 +210,7 @@
     public void addSocket(Socket s) {
         conditions.addElement(s);
     }
-
+    
     /**
      * Add a <filesmatch> condition.
      *
@@ -220,7 +220,7 @@
     public void addFilesMatch(FilesMatch test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add a <contains> condition.
      *
@@ -230,7 +230,7 @@
     public void addContains(Contains test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add a <istrue> condition.
      *
@@ -240,7 +240,7 @@
     public void addIsTrue(IsTrue test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add a <isfalse> condition.
      *
@@ -250,7 +250,7 @@
     public void addIsFalse(IsFalse test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <isreference> condition.
      *
@@ -260,7 +260,7 @@
     public void addIsReference(IsReference i) {
         conditions.addElement(i);
     }
-
+    
     /**
      * Add an <typefound> condition.
      * @param test a TypeFound condition
@@ -269,7 +269,7 @@
     public void addTypeFound(TypeFound test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <isfailure> condition.
      *
@@ -278,7 +278,7 @@
     public void addIsFailure(IsFailure test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <isfileselected> condition.
      * @param test the condition
@@ -286,7 +286,7 @@
     public void addIsFileSelected(IsFileSelected test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <isreachable> condition.
      *
@@ -296,7 +296,7 @@
     public void addIsReachable(IsReachable test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <issigned> condition.
      *
@@ -306,7 +306,7 @@
     public void addIsSigned(IsSigned test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add an <parsersupports> condition.
      *
@@ -316,7 +316,7 @@
     public void addParserSupports(ParserSupports test) {
         conditions.addElement(test);
     }
-
+    
     /**
      * Add a <ResourcesMatch> condition.
      *
@@ -326,8 +326,8 @@
     public void addResourcesMatch(ResourcesMatch test) {
         conditions.addElement(test);
     }
-
-
+    
+    
     /**
      * Add an <xor> condition.
      *
@@ -337,6 +337,17 @@
     public void addXor(Xor test) {
         conditions.addElement(test);
     }
+    
+    /**
+     * Add an <antversion> condition.
+     *
+     * @param test the condition
+     * @since Ant 1.7
+     */
+    public void addAntVersion(AntVersion test) {
+        conditions.addElement(test);
+    }
+    
     /**
      * Add an arbitrary condition
      * @param c a  condition

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml?rev=409337&r1=409336&r2=409337&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml Thu May 25
02:06:22 2006
@@ -47,4 +47,5 @@
   <typedef name="socket" classname="org.apache.tools.ant.taskdefs.condition.Socket"/>
   <typedef name="typefound" classname="org.apache.tools.ant.taskdefs.condition.TypeFound"/>
   <typedef name="xor" classname="org.apache.tools.ant.taskdefs.condition.Xor"/>
+  <typedef name="antversion" classname="org.apache.tools.ant.taskdefs.condition.AntVersion"/>
 </antlib>



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


Mime
View raw message