ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r439014 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition: ConditionBase.java antlib.xml
Date Thu, 31 Aug 2006 19:04:13 GMT
Author: mbenson
Date: Thu Aug 31 12:04:12 2006
New Revision: 439014

URL: http://svn.apache.org/viewvc?rev=439014&view=rev
Log:
Auto-discover built-in conditions added >= 1.7 from the accompanying antlib so we can stop
adding junk setters to ConditionBase.

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

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=439014&r1=439013&r2=439014&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
Aug 31 12:04:12 2006
@@ -19,6 +19,9 @@
 
 import java.util.Enumeration;
 import java.util.Vector;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.DynamicElement;
+import org.apache.tools.ant.ComponentHelper;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.taskdefs.Available;
 import org.apache.tools.ant.taskdefs.Checksum;
@@ -31,7 +34,11 @@
  *
  * @since Ant 1.4
  */
-public abstract class ConditionBase extends ProjectComponent {
+public abstract class ConditionBase extends ProjectComponent
+    implements DynamicElement {
+
+    private static final String CONDITION_ANTLIB
+        = "antlib:org.apache.tools.ant.taskdefs.condition:";
 
     /**
      * name of the component
@@ -44,17 +51,16 @@
     private Vector conditions = new Vector();
 
     /**
-     * simple constructor.
+     * Simple constructor.
      */
     protected ConditionBase() {
         taskName = "component";
     }
 
     /**
-     * constructor that takes the name of the task
-     * in the task name
+     * Constructor that takes the name of the task in the task name.
      * @param taskName
-     * @since Ant1.7
+     * @since Ant 1.7
      */
     protected ConditionBase(String taskName) {
         this.taskName = taskName;
@@ -261,24 +267,6 @@
     }
 
     /**
-     * Add an <typefound> condition.
-     * @param test a TypeFound condition
-     * @since Ant 1.7
-     */
-    public void addTypeFound(TypeFound test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add an <isfailure> condition.
-     *
-     * @param test the condition
-     */
-    public void addIsFailure(IsFailure test) {
-        conditions.addElement(test);
-    }
-
-    /**
      * Add an <isfileselected> condition.
      * @param test the condition
      */
@@ -287,81 +275,30 @@
     }
 
     /**
-     * Add an <isreachable> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addIsReachable(IsReachable test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add an <issigned> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addIsSigned(IsSigned test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add an <parsersupports> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addParserSupports(ParserSupports test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add a <ResourcesMatch> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addResourcesMatch(ResourcesMatch test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add an <xor> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addXor(Xor test) {
-        conditions.addElement(test);
-    }
-
-    /**
-     * Add a  <hasMethod> condition.
-     *
-     * @param test the condition
-     * @since Ant 1.7
-     */
-    public void addHasMethod(HasMethod test) {
-        add(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
+     * @param c a condition
      * @since Ant 1.6
      */
     public void add(Condition c) {
         conditions.addElement(c);
     }
+
+    /**
+     * Create a dynamically discovered condition.  Built-in conditions can
+     * be discovered from the org.apache.tools.ant.taskdefs.condition
+     * antlib.
+     * @param name the condition to create.
+     */
+    public Object createDynamicElement(String name) {
+        Object cond = ComponentHelper.getComponentHelper(getProject())
+            .createComponent(CONDITION_ANTLIB + name);
+        if (!(cond instanceof Condition)) {
+            return null;
+        }
+        log("Dynamically discovered '" + name + "' " + cond,
+            Project.MSG_DEBUG);
+        add((Condition) cond);
+        return cond;
+    }
+
 }

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=439014&r1=439013&r2=439014&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 Aug 31
12:04:12 2006
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
 <antlib>
   <!--
-  /*
- * Copyright  2006 The Apache Software Foundation
+/*
+ * Copyright 2006 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,11 +19,17 @@
  */
 
   -->
-  <!-- ant1.6+ antlib declaration for the conditions
-  use with the declaration xmlns:cond="antlib:org.apache.tools.ant.condition" to
-  trigger ant's autoload of this file into a namespace.
+  <!-- Ant 1.6+ antlib declaration for conditions:
+  Use with the declaration xmlns:cond="antlib:org.apache.tools.ant.condition" to
+  trigger Ant's autoload of this file into namespace 'cond' (or whatever name
+  suits).
 
-  Please keep this list in alphabetical order -it is easier to verify that way
+  Please keep this list in alphabetical order; it is easier to verify that way.
+
+  Additionally, ConditionBase uses this antlib to discover built-in conditions.
+  Prior to Ant 1.7, a new built-in condition required an addXXX method to be
+  added to ConditionBase.  Conditions added in or after version 1.7 need only
+  to be added to this antlib.
   -->
 
   <typedef name="and" classname="org.apache.tools.ant.taskdefs.condition.And"/>
@@ -31,7 +37,7 @@
            classname="org.apache.tools.ant.taskdefs.condition.AntVersion"/>
   <typedef name="contains" classname="org.apache.tools.ant.taskdefs.condition.Contains"/>
   <typedef name="equals" classname="org.apache.tools.ant.taskdefs.condition.Equals"/>
-  <typedef name="filesmatch" classname="org.apache.tools.ant.taskdefs.condition.Filesmatch"/>
+  <typedef name="filesmatch" classname="org.apache.tools.ant.taskdefs.condition.FilesMatch"/>
   <typedef name="http" classname="org.apache.tools.ant.taskdefs.condition.Http"/>
   <typedef name="isfailure" classname="org.apache.tools.ant.taskdefs.condition.IsFailure"/>
   <typedef name="isfalse" classname="org.apache.tools.ant.taskdefs.condition.IsFalse"/>
@@ -50,4 +56,4 @@
   <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"/>
-</antlib>
\ No newline at end of file
+</antlib>



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


Mime
View raw message