diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Available.java b/proposal/myrmidon/src/java/org/apache/antlib/core/Available.java
new file mode 100644
index 000000000..417b1d1e5
--- /dev/null
+++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Available.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software License
+ * version 1.1, a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ */
+package org.apache.antlib.core;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import org.apache.myrmidon.api.TaskContext;
+import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.framework.Condition;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.PathUtil;
+
+/**
+ * A condition that evaluates to true if the requested class or resource
+ * is available at runtime.
+ *
+ * @author Stefano Mazzocchi
+ * stefano@apache.org
+ * @author Magesh Umasankar
+ *
+ * @ant:type type="condition" name="available"
+ */
+public class Available
+ implements Condition
+{
+ private String m_classname;
+ private Path m_classpath;
+ private ClassLoader m_classLoader;
+ private String m_resource;
+
+ /**
+ * Sets the name of the class to search for.
+ */
+ public void setClassname( final String classname )
+ {
+ if( !"".equals( classname ) )
+ {
+ m_classname = classname;
+ }
+ }
+
+ /**
+ * Adds a classpath element.
+ */
+ public void addClasspath( final Path classpath )
+ throws TaskException
+ {
+ if( m_classpath == null )
+ {
+ m_classpath = classpath;
+ }
+ else
+ {
+ m_classpath.addPath( classpath );
+ }
+ }
+
+ /**
+ * Sets the name of the resource to look for.
+ */
+ public void setResource( final String resource )
+ {
+ m_resource = resource;
+ }
+
+ /**
+ * Evaluates the condition.
+ */
+ public boolean evaluate( final TaskContext context )
+ throws TaskException
+ {
+ if( m_classname == null && m_resource == null )
+ {
+ throw new TaskException( "At least one of (classname|file|resource) is required" );
+ }
+
+ if( m_classpath != null )
+ {
+ final URL[] urls = PathUtil.toURLs( m_classpath );
+ m_classLoader = new URLClassLoader( urls );
+ }
+
+ if( ( m_classname != null ) && !checkClass( m_classname ) )
+ {
+ return false;
+ }
+
+ if( ( m_resource != null ) && !checkResource( m_resource ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean checkClass( String classname )
+ {
+ try
+ {
+ final ClassLoader classLoader = getClassLoader();
+ classLoader.loadClass( classname );
+ return true;
+ }
+ catch( ClassNotFoundException e )
+ {
+ return false;
+ }
+ catch( NoClassDefFoundError e )
+ {
+ return false;
+ }
+ }
+
+ private boolean checkResource( String resource )
+ {
+ final ClassLoader classLoader = getClassLoader();
+ return ( null != classLoader.getResourceAsStream( resource ) );
+ }
+
+ private ClassLoader getClassLoader()
+ {
+ if( null == m_classLoader )
+ {
+ return ClassLoader.getSystemClassLoader();
+ }
+ else
+ {
+ return m_classLoader;
+ }
+ }
+}
diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java b/proposal/myrmidon/src/java/org/apache/antlib/core/ConditionTask.java
similarity index 53%
rename from proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
rename to proposal/myrmidon/src/java/org/apache/antlib/core/ConditionTask.java
index de252f57a..526b92461 100644
--- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
+++ b/proposal/myrmidon/src/java/org/apache/antlib/core/ConditionTask.java
@@ -5,11 +5,12 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
-package org.apache.tools.ant.taskdefs;
+package org.apache.antlib.core;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.taskdefs.condition.Condition;
-import org.apache.tools.ant.taskdefs.condition.ConditionBase;
+import org.apache.myrmidon.api.AbstractTask;
+import org.apache.myrmidon.framework.conditions.AndCondition;
+import org.apache.myrmidon.framework.Condition;
/**
* <condition> task as a generalization of <available> and
@@ -22,58 +23,58 @@ import org.apache.tools.ant.taskdefs.condition.ConditionBase;
*
* @author Stefan Bodewig
* @version $Revision$
+ *
+ * @ant:task name="condition"
*/
-public class ConditionTask extends ConditionBase
+public class ConditionTask
+ extends AbstractTask
{
- private String value = "true";
+ private AndCondition m_condition = new AndCondition();
+ private String m_property;
+ private String m_value = "true";
- private String property;
+ /**
+ * Adds a condition.
+ */
+ public void add( final Condition condition )
+ {
+ m_condition.add( condition );
+ }
/**
* The name of the property to set. Required.
*
* @param p The new Property value
- * @since 1.1
*/
- public void setProperty( String p )
+ public void setProperty( final String p )
{
- property = p;
+ m_property = p;
}
/**
* The value for the property to set. Defaults to "true".
*
* @param v The new Value value
- * @since 1.1
*/
- public void setValue( String v )
+ public void setValue( final String v )
{
- value = v;
+ m_value = v;
}
/**
* See whether our nested condition holds and set the property.
- *
- * @exception TaskException Description of Exception
- * @since 1.1
*/
public void execute()
throws TaskException
{
- if( countConditions() > 1 )
- {
- throw new TaskException( "You must not nest more than one condition into
+ * + * Iterates over all conditions and returns false as soon as one evaluates to + * false. An empty and condition returns true.
+ * + * @author Stefan Bodewig + * @version $Revision$ + * + * @ant:type type="condition" name="and" + */ +public class AndCondition + implements Condition +{ + final ArrayList m_conditions = new ArrayList(); + + /** + * Adds a condition. + */ + public void add( final Condition condition ) + { + m_conditions.add( condition ); + } + + /** + * Evaluates the condition. + * + */ + public boolean evaluate( final TaskContext context ) + throws TaskException + { + final int count = m_conditions.size(); + for( int i = 0; i < count; i++ ) + { + final Condition condition = (Condition)m_conditions.get( i ); + if( !condition.evaluate( context ) ) + { + return false; + } + } + return true; + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java new file mode 100644 index 000000000..ecfe1fe54 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.framework.conditions; + +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.Condition; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; + +/** + * A {@link Condition} that is true when a property is set, but not set to + * 'false'. + * + * @author Stefan Bodewig + * @author Peter Donald + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:type type="condition" name="is-set" + */ +public class IsSetCondition + implements Condition +{ + private final static Resources REZ + = ResourceManager.getPackageResources( IsSetCondition.class ); + + private String m_property; + + public IsSetCondition( final String propName ) + { + m_property = propName; + } + + public IsSetCondition() + { + } + + /** + * Set the property name to test. + */ + public void setProperty( final String propName ) + { + m_property = propName; + } + + /** + * Evaluates the condition. + */ + public boolean evaluate( final TaskContext context ) + throws TaskException + { + if( m_property == null ) + { + final String message = REZ.getString( "isset.no-property.error" ); + throw new TaskException( message ); + } + + // Resolve the condition + final Object object = context.getProperty( m_property ); + return ( object != null && !object.toString().equals( "false" ) ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java new file mode 100644 index 000000000..6d7572d82 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.framework.conditions; + +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; + +/** + * <not> condition. Evaluates to true if the single condition nested into + * it is false and vice versa. + * + * @author Stefan Bodewig + * @version $Revision$ + * + * @ant:type type="condition" name="not" + */ +public class NotCondition + implements Condition +{ + private Condition m_condition; + + public NotCondition() + { + } + + public NotCondition( final Condition condition ) + { + m_condition = condition; + } + + /** + * Sets the nested condition. + */ + public void set( final Condition condition ) + { + m_condition = condition; + } + + /** + * Evaluates the condition. + */ + public boolean evaluate( final TaskContext context ) + throws TaskException + { + if( m_condition == null ) + { + throw new TaskException( "no condition set" ); + } + + return ! m_condition.evaluate( context ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/OrCondition.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/OrCondition.java new file mode 100644 index 000000000..bf7ea3829 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/OrCondition.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.myrmidon.framework.conditions; + +import java.util.Enumeration; +import java.util.ArrayList; +import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; + +/** + * <or> condition container.+ * + * Iterates over all conditions and returns true as soon as one evaluates to + * true. An empty container evaluates to true
+ * + * @author Stefan Bodewig + * @version $Revision$ + * + * @ant:type type="condition" name="or" + */ +public class OrCondition + implements Condition +{ + final ArrayList m_conditions = new ArrayList(); + + /** + * Adds a condition. + */ + public void add( final Condition condition ) + { + m_conditions.add( condition ); + } + + /** + * Evaluates the condition. + * + */ + public boolean evaluate( final TaskContext context ) + throws TaskException + { + final int count = m_conditions.size(); + for( int i = 0; i < count; i++ ) + { + final Condition condition = (Condition)m_conditions.get( i ); + if( condition.evaluate( context ) ) + { + return true; + } + } + return (count == 0); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties new file mode 100644 index 000000000..10b859f0f --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties @@ -0,0 +1 @@ +isset.no-property.error=No property specified to test. diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Available.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Available.java deleted file mode 100644 index e537e3732..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Available.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs; - -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.condition.Condition; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PathUtil; - -/** - * Will set the given property if the requested resource is available at - * runtime. - * - * @author Stefano Mazzocchi - * stefano@apache.org - * @author Magesh Umasankar - */ -public class Available - extends AbstractTask - implements Condition -{ - private String m_value = "true"; - private String m_classname; - private Path m_classpath; - private String m_file; - private Path m_filepath; - private ClassLoader m_classLoader; - - private String m_property; - private String m_resource; - private FileDir m_type; - - public void setClassname( String classname ) - { - if( !"".equals( classname ) ) - { - m_classname = classname; - } - } - - /** - * Adds a classpath element. - */ - public void addClasspath( Path classpath ) - throws TaskException - { - if( m_classpath == null ) - { - m_classpath = classpath; - } - else - { - m_classpath.addPath( classpath ); - } - } - - public void setFile( String file ) - { - m_file = file; - } - - public void setProperty( String property ) - { - m_property = property; - } - - public void setResource( String resource ) - { - m_resource = resource; - } - - public void setType( FileDir type ) - { - m_type = type; - } - - public void setValue( String value ) - { - m_value = value; - } - - /** - * Adds a file search path element. - */ - public void addFilepath( Path path ) - throws TaskException - { - if( m_filepath == null ) - { - m_filepath = path; - } - else - { - m_filepath.addPath( path ); - } - } - - public boolean eval() - throws TaskException - { - if( m_classname == null && m_file == null && m_resource == null ) - { - throw new TaskException( "At least one of (classname|file|resource) is required" ); - } - - if( m_type != null ) - { - if( m_file == null ) - { - throw new TaskException( "The type attribute is only valid when specifying the file attribute." ); - } - } - - if( m_classpath != null ) - { - final URL[] urls = PathUtil.toURLs( m_classpath ); - m_classLoader = new URLClassLoader( urls ); - } - - if( ( m_classname != null ) && !checkClass( m_classname ) ) - { - getLogger().debug( "Unable to load class " + m_classname + " to set property " + m_property ); - return false; - } - - if( ( m_file != null ) && !checkFile() ) - { - if( m_type != null ) - { - getLogger().debug( "Unable to find " + m_type + " " + m_file + " to set property " + m_property ); - } - else - { - getLogger().debug( "Unable to find " + m_file + " to set property " + m_property ); - } - return false; - } - - if( ( m_resource != null ) && !checkResource( m_resource ) ) - { - getLogger().debug( "Unable to load resource " + m_resource + " to set property " + m_property ); - return false; - } - - return true; - } - - public void execute() - throws TaskException - { - if( m_property == null ) - { - throw new TaskException( "property attribute is required" ); - } - - if( eval() ) - { - final String name = m_property; - final Object value = m_value; - getContext().setProperty( name, value ); - } - } - - private boolean checkClass( String classname ) - { - try - { - final ClassLoader classLoader = getClassLoader(); - classLoader.loadClass( classname ); - return true; - } - catch( ClassNotFoundException e ) - { - return false; - } - catch( NoClassDefFoundError e ) - { - return false; - } - } - - private boolean checkFile() - throws TaskException - { - if( m_filepath == null ) - { - return checkFile( getContext().resolveFile( m_file ), m_file ); - } - else - { - String[] paths = m_filepath.list(); - for( int i = 0; i < paths.length; ++i ) - { - getLogger().debug( "Searching " + paths[ i ] ); - /* - * filepath can be a list of directory and/or - * file names (gen'd via- * - * Iterates over all conditions and returns false as soon as one evaluates to - * false.
- * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class And - extends ConditionBase - implements Condition -{ - public boolean eval() - throws TaskException - { - final Enumeration enum = getConditions(); - while( enum.hasMoreElements() ) - { - final Condition condition = (Condition)enum.nextElement(); - if( !condition.eval() ) - { - return false; - } - } - return true; - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Condition.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Condition.java deleted file mode 100644 index 4fcc52a4f..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Condition.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; - -/** - * Interface for conditions to use inside the <condition> task. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public interface Condition -{ - /** - * Is this condition true? - * - * @return Description of the Returned Value - * @exception TaskException Description of Exception - */ - boolean eval() - throws TaskException; -} - diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java deleted file mode 100644 index 0736da584..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.NoSuchElementException; -import org.apache.tools.ant.ProjectComponent; -import org.apache.tools.ant.taskdefs.Available; -import org.apache.antlib.build.Checksum; -import org.apache.tools.ant.taskdefs.UpToDate; - -/** - * Baseclass for the <condition> task as well as several conditions - - * ensures that the types of conditions inside the task and the "container" - * conditions are in sync. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public abstract class ConditionBase - extends ProjectComponent -{ - private ArrayList m_conditions = new ArrayList(); - - /** - * Add an <and> condition "container". - * - * @param a The feature to be added to the And attribute - * @since 1.1 - */ - public void addAnd( And a ) - { - m_conditions.add( a ); - } - - /** - * Add an <available> condition. - * - * @param a The feature to be added to the Available attribute - * @since 1.1 - */ - public void addAvailable( Available a ) - { - m_conditions.add( a ); - } - - /** - * Add an <checksum> condition. - * - * @param c The feature to be added to the Checksum attribute - * @since 1.4 - */ - public void addChecksum( Checksum c ) - { - m_conditions.add( c ); - } - - /** - * Add an <equals> condition. - * - * @param e The feature to be added to the Equals attribute - * @since 1.1 - */ - public void addEquals( Equals e ) - { - m_conditions.add( e ); - } - - /** - * Add an <http> condition. - * - * @param h The feature to be added to the Http attribute - * @since 1.7 - */ - public void addHttp( Http h ) - { - m_conditions.add( h ); - } - - /** - * Add an <isset> condition. - * - * @param i The feature to be added to the IsSet attribute - * @since 1.1 - */ - public void addIsSet( IsSet i ) - { - m_conditions.add( i ); - } - - /** - * Add an <not> condition "container". - * - * @param n The feature to be added to the Not attribute - * @since 1.1 - */ - public void addNot( Not n ) - { - m_conditions.add( n ); - } - - /** - * Add an <or> condition "container". - * - * @param o The feature to be added to the Or attribute - * @since 1.1 - */ - public void addOr( Or o ) - { - m_conditions.add( o ); - } - - /** - * Add an <os> condition. - * - * @param o The feature to be added to the Os attribute - * @since 1.1 - */ - public void addOs( final OsCondition o ) - { - m_conditions.add( o ); - } - - /** - * Add a <socket> condition. - * - * @param s The feature to be added to the Socket attribute - * @since 1.7 - */ - public void addSocket( Socket s ) - { - m_conditions.add( s ); - } - - /** - * Add an <uptodate> condition. - * - * @param u The feature to be added to the Uptodate attribute - * @since 1.1 - */ - public void addUptodate( UpToDate u ) - { - m_conditions.add( u ); - } - - /** - * Iterate through all conditions. - * - * @return The Conditions value - * @since 1.1 - */ - protected final Enumeration getConditions() - { - return new ConditionEnumeration(); - } - - /** - * Count the conditions. - * - * @return Description of the Returned Value - * @since 1.1 - */ - protected int countConditions() - { - return m_conditions.size(); - } - - /** - * Inner class that configures those conditions with a project instance that - * need it. - * - * @author RT - * @since 1.1 - */ - private class ConditionEnumeration implements Enumeration - { - private int currentElement = 0; - - public boolean hasMoreElements() - { - return countConditions() > currentElement; - } - - public Object nextElement() - throws NoSuchElementException - { - Object o = null; - try - { - o = m_conditions.get( currentElement++ ); - } - catch( ArrayIndexOutOfBoundsException e ) - { - throw new NoSuchElementException(); - } - return o; - } - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java index 31f9d7806..57fcb7d2e 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java @@ -5,15 +5,18 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs.condition; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; /** * Simple String comparison condition. * * @author Stefan Bodewig * @version $Revision$ + * + * @ant:type type="condition" nam="equals" */ public class Equals implements Condition { @@ -30,7 +33,13 @@ public class Equals implements Condition arg2 = a2; } - public boolean eval() + /** + * Evaluates this condition. + * + * @param context + * The context to evaluate the condition in. + */ + public boolean evaluate( final TaskContext context ) throws TaskException { if( arg1 == null || arg2 == null ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java index 25ed4d0ef..ee35980f9 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java @@ -12,6 +12,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; import org.apache.tools.ant.ProjectComponent; /** @@ -19,6 +21,8 @@ import org.apache.tools.ant.ProjectComponent; * the URL of the request. * * @author Denis Hennessy + * + * @ant:type type="condition" nam="http" */ public class Http extends ProjectComponent @@ -31,7 +35,10 @@ public class Http spec = url; } - public boolean eval() + /** + * Evaluates this condition. + */ + public boolean evaluate( final TaskContext context ) throws TaskException { if( spec == null ) diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/IsSet.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/IsSet.java deleted file mode 100644 index 29791532c..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/IsSet.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.tools.ant.ProjectComponent; - -/** - * Condition that tests whether a given property has been set. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class IsSet extends ProjectComponent implements Condition -{ - private String property; - - public void setProperty( String p ) - { - property = p; - } - - public boolean eval() - throws TaskException - { - if( property == null ) - { - throw new TaskException( "No property specified for isset condition" ); - } - - return getContext().getProperty( property ) != null; - } - -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Not.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Not.java deleted file mode 100644 index 6e7cbe052..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Not.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; - -/** - * <not> condition. Evaluates to true if the single condition nested into - * it is false and vice versa. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class Not extends ConditionBase implements Condition -{ - - public boolean eval() - throws TaskException - { - if( countConditions() > 1 ) - { - throw new TaskException( "You must not nest more than one condition into- * - * Iterates over all conditions and returns true as soon as one evaluates to - * true.
- * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class Or extends ConditionBase implements Condition -{ - - public boolean eval() - throws TaskException - { - Enumeration enum = getConditions(); - while( enum.hasMoreElements() ) - { - Condition c = (Condition)enum.nextElement(); - if( c.eval() ) - { - return true; - } - } - return false; - } - -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/OsCondition.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/OsCondition.java deleted file mode 100644 index 8ad02cb77..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/OsCondition.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import java.util.Locale; -import org.apache.aut.nativelib.Os; -import org.apache.myrmidon.api.TaskException; - -/** - * Condition to check the current OS. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class OsCondition - extends ConditionBase - implements Condition -{ - private String m_family; - private String m_name; - private String m_version; - private String m_arch; - - /** - * Sets the desired OS family type - * - * @param f The OS family type desired- * - * This task supports boolean logic as well as pluggable conditions to decide, - * whether a property should be set.
- * - * This task does not extend Task to take advantage of ConditionBase.
- * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class ConditionTask extends ConditionBase -{ - private String value = "true"; - - private String property; - - /** - * The name of the property to set. Required. - * - * @param p The new Property value - * @since 1.1 - */ - public void setProperty( String p ) - { - property = p; - } - - /** - * The value for the property to set. Defaults to "true". - * - * @param v The new Value value - * @since 1.1 - */ - public void setValue( String v ) - { - value = v; - } - - /** - * See whether our nested condition holds and set the property. - * - * @exception TaskException Description of Exception - * @since 1.1 - */ - public void execute() - throws TaskException - { - if( countConditions() > 1 ) - { - throw new TaskException( "You must not nest more than one condition into- * - * Iterates over all conditions and returns false as soon as one evaluates to - * false.
- * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class And - extends ConditionBase - implements Condition -{ - public boolean eval() - throws TaskException - { - final Enumeration enum = getConditions(); - while( enum.hasMoreElements() ) - { - final Condition condition = (Condition)enum.nextElement(); - if( !condition.eval() ) - { - return false; - } - } - return true; - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Condition.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Condition.java deleted file mode 100644 index 4fcc52a4f..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Condition.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; - -/** - * Interface for conditions to use inside the <condition> task. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public interface Condition -{ - /** - * Is this condition true? - * - * @return Description of the Returned Value - * @exception TaskException Description of Exception - */ - boolean eval() - throws TaskException; -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/ConditionBase.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/ConditionBase.java deleted file mode 100644 index 0736da584..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/ConditionBase.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.NoSuchElementException; -import org.apache.tools.ant.ProjectComponent; -import org.apache.tools.ant.taskdefs.Available; -import org.apache.antlib.build.Checksum; -import org.apache.tools.ant.taskdefs.UpToDate; - -/** - * Baseclass for the <condition> task as well as several conditions - - * ensures that the types of conditions inside the task and the "container" - * conditions are in sync. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public abstract class ConditionBase - extends ProjectComponent -{ - private ArrayList m_conditions = new ArrayList(); - - /** - * Add an <and> condition "container". - * - * @param a The feature to be added to the And attribute - * @since 1.1 - */ - public void addAnd( And a ) - { - m_conditions.add( a ); - } - - /** - * Add an <available> condition. - * - * @param a The feature to be added to the Available attribute - * @since 1.1 - */ - public void addAvailable( Available a ) - { - m_conditions.add( a ); - } - - /** - * Add an <checksum> condition. - * - * @param c The feature to be added to the Checksum attribute - * @since 1.4 - */ - public void addChecksum( Checksum c ) - { - m_conditions.add( c ); - } - - /** - * Add an <equals> condition. - * - * @param e The feature to be added to the Equals attribute - * @since 1.1 - */ - public void addEquals( Equals e ) - { - m_conditions.add( e ); - } - - /** - * Add an <http> condition. - * - * @param h The feature to be added to the Http attribute - * @since 1.7 - */ - public void addHttp( Http h ) - { - m_conditions.add( h ); - } - - /** - * Add an <isset> condition. - * - * @param i The feature to be added to the IsSet attribute - * @since 1.1 - */ - public void addIsSet( IsSet i ) - { - m_conditions.add( i ); - } - - /** - * Add an <not> condition "container". - * - * @param n The feature to be added to the Not attribute - * @since 1.1 - */ - public void addNot( Not n ) - { - m_conditions.add( n ); - } - - /** - * Add an <or> condition "container". - * - * @param o The feature to be added to the Or attribute - * @since 1.1 - */ - public void addOr( Or o ) - { - m_conditions.add( o ); - } - - /** - * Add an <os> condition. - * - * @param o The feature to be added to the Os attribute - * @since 1.1 - */ - public void addOs( final OsCondition o ) - { - m_conditions.add( o ); - } - - /** - * Add a <socket> condition. - * - * @param s The feature to be added to the Socket attribute - * @since 1.7 - */ - public void addSocket( Socket s ) - { - m_conditions.add( s ); - } - - /** - * Add an <uptodate> condition. - * - * @param u The feature to be added to the Uptodate attribute - * @since 1.1 - */ - public void addUptodate( UpToDate u ) - { - m_conditions.add( u ); - } - - /** - * Iterate through all conditions. - * - * @return The Conditions value - * @since 1.1 - */ - protected final Enumeration getConditions() - { - return new ConditionEnumeration(); - } - - /** - * Count the conditions. - * - * @return Description of the Returned Value - * @since 1.1 - */ - protected int countConditions() - { - return m_conditions.size(); - } - - /** - * Inner class that configures those conditions with a project instance that - * need it. - * - * @author RT - * @since 1.1 - */ - private class ConditionEnumeration implements Enumeration - { - private int currentElement = 0; - - public boolean hasMoreElements() - { - return countConditions() > currentElement; - } - - public Object nextElement() - throws NoSuchElementException - { - Object o = null; - try - { - o = m_conditions.get( currentElement++ ); - } - catch( ArrayIndexOutOfBoundsException e ) - { - throw new NoSuchElementException(); - } - return o; - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Equals.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Equals.java index 31f9d7806..57fcb7d2e 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Equals.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Equals.java @@ -5,15 +5,18 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ -package org.apache.tools.ant.taskdefs.condition; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; /** * Simple String comparison condition. * * @author Stefan Bodewig * @version $Revision$ + * + * @ant:type type="condition" nam="equals" */ public class Equals implements Condition { @@ -30,7 +33,13 @@ public class Equals implements Condition arg2 = a2; } - public boolean eval() + /** + * Evaluates this condition. + * + * @param context + * The context to evaluate the condition in. + */ + public boolean evaluate( final TaskContext context ) throws TaskException { if( arg1 == null || arg2 == null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Http.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Http.java index 25ed4d0ef..ee35980f9 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Http.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Http.java @@ -12,6 +12,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; import org.apache.tools.ant.ProjectComponent; /** @@ -19,6 +21,8 @@ import org.apache.tools.ant.ProjectComponent; * the URL of the request. * * @author Denis Hennessy + * + * @ant:type type="condition" nam="http" */ public class Http extends ProjectComponent @@ -31,7 +35,10 @@ public class Http spec = url; } - public boolean eval() + /** + * Evaluates this condition. + */ + public boolean evaluate( final TaskContext context ) throws TaskException { if( spec == null ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/IsSet.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/IsSet.java deleted file mode 100644 index 29791532c..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/IsSet.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.api.AbstractTask; -import org.apache.tools.ant.ProjectComponent; - -/** - * Condition that tests whether a given property has been set. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class IsSet extends ProjectComponent implements Condition -{ - private String property; - - public void setProperty( String p ) - { - property = p; - } - - public boolean eval() - throws TaskException - { - if( property == null ) - { - throw new TaskException( "No property specified for isset condition" ); - } - - return getContext().getProperty( property ) != null; - } - -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Not.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Not.java deleted file mode 100644 index 6e7cbe052..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Not.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE.txt file. - */ -package org.apache.tools.ant.taskdefs.condition; - -import org.apache.myrmidon.api.TaskException; - -/** - * <not> condition. Evaluates to true if the single condition nested into - * it is false and vice versa. - * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class Not extends ConditionBase implements Condition -{ - - public boolean eval() - throws TaskException - { - if( countConditions() > 1 ) - { - throw new TaskException( "You must not nest more than one condition into- * - * Iterates over all conditions and returns true as soon as one evaluates to - * true.
- * - * @author Stefan Bodewig - * @version $Revision$ - */ -public class Or extends ConditionBase implements Condition -{ - - public boolean eval() - throws TaskException - { - Enumeration enum = getConditions(); - while( enum.hasMoreElements() ) - { - Condition c = (Condition)enum.nextElement(); - if( c.eval() ) - { - return true; - } - } - return false; - } - -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Socket.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Socket.java index b66cd8254..4834acb67 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Socket.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Socket.java @@ -9,6 +9,8 @@ package org.apache.tools.ant.taskdefs.condition; import java.io.IOException; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.framework.Condition; import org.apache.tools.ant.ProjectComponent; /** @@ -16,6 +18,8 @@ import org.apache.tools.ant.ProjectComponent; * are: server - the name of the server. port - the port number of the socket. * * @author Denis Hennessy + * + * @ant:type type="condition" nam="socket" */ public class Socket extends ProjectComponent @@ -34,7 +38,10 @@ public class Socket this.server = server; } - public boolean eval() + /** + * Evaluates this condition. + */ + public boolean evaluate( TaskContext context ) throws TaskException { if( server == null ) @@ -49,6 +56,7 @@ public class Socket try { java.net.Socket socket = new java.net.Socket( server, port ); + socket.close(); } catch( IOException e ) {