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 " ); - } - if( countConditions() < 1 ) + if( m_property == null ) { - throw new TaskException( "You must nest a condition into " ); + throw new TaskException( "No property was specified" ); } - Condition c = (Condition)getConditions().nextElement(); - if( c.eval() ) + + if( m_condition.evaluate( getContext() ) ) { - final String name = property; - final Object value1 = value; - getContext().setProperty( name, value1 ); + getContext().setProperty( m_property, m_value ); } } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java b/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java index 542992dde..e5783ed39 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java @@ -9,7 +9,6 @@ package org.apache.antlib.core; import org.apache.myrmidon.api.AbstractTask; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.Condition; /** * This is a task used to throw a TaskException. @@ -22,7 +21,6 @@ public class Fail extends AbstractTask { private String m_message; - private Condition m_condition; public void setMessage( final String message ) { @@ -36,38 +34,16 @@ public class Fail m_message = message; } - public void setIf( final String ifCondition ) - { - checkNullCondition(); - m_condition = new Condition( true, ifCondition ); - } - - public void setUnless( final String unlessCondition ) - { - checkNullCondition(); - m_condition = new Condition( false, unlessCondition ); - } - public void execute() throws TaskException { - boolean failed = true; - - if( null != m_condition ) + if( null != m_message ) { - failed = m_condition.evaluate( getContext() ); + throw new TaskException( m_message ); } - - if( failed ) + else { - if( null != m_message ) - { - throw new TaskException( m_message ); - } - else - { - throw new TaskException(); - } + throw new TaskException(); } } @@ -80,12 +56,4 @@ public class Fail throw new IllegalStateException( message ); } } - - private void checkNullCondition() - { - if( null != m_condition ) - { - throw new IllegalStateException( "Condition already set!" ); - } - } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java b/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java index 9472a0cf9..f376ff937 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java @@ -14,6 +14,8 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.framework.AbstractContainerTask; import org.apache.myrmidon.framework.Condition; +import org.apache.myrmidon.framework.conditions.IsSetCondition; +import org.apache.myrmidon.framework.conditions.NotCondition; import org.apache.myrmidon.interfaces.executor.ExecutionFrame; import org.apache.myrmidon.interfaces.executor.Executor; @@ -44,7 +46,7 @@ public class IfTask throws TaskException { verifyConditionNull(); - m_condition = new Condition( true, condition ); + m_condition = new IsSetCondition( condition ); } /** @@ -57,7 +59,7 @@ public class IfTask throws TaskException { verifyConditionNull(); - m_condition = new Condition( false, condition ); + m_condition = new NotCondition( new IsSetCondition( condition ) ); } public void add( final Configuration task ) diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/OsCondition.java b/proposal/myrmidon/src/java/org/apache/antlib/core/OsCondition.java similarity index 61% rename from proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/OsCondition.java rename to proposal/myrmidon/src/java/org/apache/antlib/core/OsCondition.java index 8ad02cb77..cf778acb3 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/OsCondition.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/OsCondition.java @@ -5,20 +5,22 @@ * 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; +package org.apache.antlib.core; -import java.util.Locale; import org.apache.aut.nativelib.Os; +import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.Condition; /** * Condition to check the current OS.

* * @author Stefan Bodewig * @version $Revision$ + * + * @ant:type type="condition" name="os" */ public class OsCondition - extends ConditionBase implements Condition { private String m_family; @@ -29,18 +31,11 @@ public class OsCondition /** * Sets the desired OS family type * - * @param f The OS family type desired
- * Possible values:
- * + * @param family The OS family type desired. */ public void setFamily( final String family ) { - m_family = family.toLowerCase( Locale.US ); + m_family = family; } /** @@ -50,7 +45,7 @@ public class OsCondition */ public void setName( final String name ) { - m_name = name.toLowerCase( Locale.US ); + m_name = name; } /** @@ -60,7 +55,7 @@ public class OsCondition */ public void setArch( final String arch ) { - m_arch = arch.toLowerCase( Locale.US ); + m_arch = arch; } /** @@ -68,17 +63,15 @@ public class OsCondition * * @param version The OS version */ - public void setVersion( String version ) + public void setVersion( final String version ) { - this.m_version = version.toLowerCase( Locale.US ); + m_version = version; } /** - * Determines if the OS on which Ant is executing matches the type of - * that set in setFamily. - * @see Os#setFamily(String) + * Evaluates this condition. */ - public boolean eval() + public boolean evaluate( final TaskContext context ) throws TaskException { return Os.isOs( m_family, m_name, m_arch, m_version ); diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java index 1efbf35ef..d0547554e 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java @@ -23,6 +23,9 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.SAXConfigurationHandler; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.myrmidon.framework.Condition; +import org.apache.myrmidon.framework.conditions.AndCondition; +import org.apache.myrmidon.framework.conditions.IsSetCondition; +import org.apache.myrmidon.framework.conditions.NotCondition; import org.apache.myrmidon.interfaces.builder.ProjectBuilder; import org.apache.myrmidon.interfaces.model.Project; import org.apache.myrmidon.interfaces.model.Target; @@ -381,7 +384,7 @@ public class DefaultProjectBuilder } final String[] dependencies = buildDependsList( depends, target ); - final Condition condition = buildCondition( ifCondition, unlessCondition, target ); + final Condition condition = buildCondition( ifCondition, unlessCondition ); final Target defaultTarget = new Target( condition, target.getChildren(), dependencies ); @@ -442,17 +445,13 @@ public class DefaultProjectBuilder return dependencies; } - private Condition buildCondition( final String ifCondition, final String unlessCondition, final Configuration target ) throws Exception + private Condition buildCondition( final String ifCondition, + final String unlessCondition ) + throws Exception { - if( null != ifCondition && null != unlessCondition ) - { - final String message = - REZ.getString( "ant.target-bad-logic.error", target.getLocation() ); - throw new Exception( message ); - } - - Condition condition = null; + final AndCondition condition = new AndCondition(); + // Add the 'if' condition if( null != ifCondition ) { if( getLogger().isDebugEnabled() ) @@ -460,17 +459,20 @@ public class DefaultProjectBuilder final String message = REZ.getString( "ant.target-if.notice", ifCondition ); getLogger().debug( message ); } - condition = new Condition( true, ifCondition ); + condition.add( new IsSetCondition( ifCondition ) ); } - else if( null != unlessCondition ) + + // Add the 'unless' condition + if( null != unlessCondition ) { if( getLogger().isDebugEnabled() ) { final String message = REZ.getString( "ant.target-unless.notice", unlessCondition ); getLogger().debug( message ); } - condition = new Condition( false, unlessCondition ); + condition.add( new NotCondition( new IsSetCondition( unlessCondition ) ) ); } + return condition; } diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties index 9e980c08e..80cc7f97e 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties @@ -21,7 +21,6 @@ ant.import-no-library.error=Malformed import without a library attribute at {0}. ant.import-malformed.error=Malformed import at {0}. If name or type attribute is specified, both attributes must be specified. ant.target-noname.error=Discovered un-named target at {0}. ant.target-bad-name.error=Target with an invalid name at {0}. -ant.target-bad-logic.error=Discovered invalid target that has both a if and unless condition at {0}. ant.target-bad-dependency.error=Discovered empty dependency in target {0} at {1}. ant.malformed.version=Malformed version string "{0}" specified in version attribute of project. ant.version-missing.error=Missing version attribute from project. diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java index 4cc90e7bf..7b4a0db13 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java @@ -388,8 +388,7 @@ public class DefaultWorkspace { try { - final boolean result = - condition.evaluate( frame.getContext() ); + final boolean result = condition.evaluate( frame.getContext() ); if( !result ) { final String message = REZ.getString( "skip-target.notice", name ); diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java index 6a60580bb..84a1ed809 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java @@ -13,64 +13,20 @@ import org.apache.myrmidon.api.TaskException; /** * Class representing a condition. * + * @author Stefan Bodewig * @author Peter Donald * @version $Revision$ $Date$ + * + * @ant:role shorthand="condition" */ -public class Condition +public interface Condition { - private String m_condition; - private boolean m_isIfCondition; - - public Condition( final boolean isIfCondition, final String condition ) - { - m_isIfCondition = isIfCondition; - m_condition = condition; - } - - public String getCondition() - { - return m_condition; - } - - public boolean isIfCondition() - { - return m_isIfCondition; - } - - public boolean evaluate( final TaskContext context ) - throws TaskException - { - boolean result = false; - - final Object resolved = context.resolveValue( getCondition() ); - if( null != resolved ) - { - final Object object = context.getProperty( resolved.toString() ); - if( object != null && !object.toString().equals( "false" ) ) - { - result = true; - } - } - - if( !m_isIfCondition ) - { - result = !result; - } - - return result; - } - - public String toString() - { - if( isIfCondition() ) - { - return "if='" + getCondition() + "'"; - } - else - { - return "unless='" + getCondition() + "'"; - } - } + /** + * Evaluates this condition. + * + * @param context + * The context to evaluate the condition in. + */ + boolean evaluate( final TaskContext context ) + throws TaskException; } - - diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java index 622504e28..1002f7a29 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java @@ -11,6 +11,8 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.conditions.IsSetCondition; +import org.apache.myrmidon.framework.conditions.NotCondition; /** * Basic data type for holding patterns. @@ -77,7 +79,7 @@ public class Pattern throws TaskException { verifyConditionNull(); - m_condition = new Condition( true, condition ); + m_condition = new IsSetCondition( condition ); } /** @@ -90,7 +92,7 @@ public class Pattern throws TaskException { verifyConditionNull(); - m_condition = new Condition( false, condition ); + m_condition = new NotCondition( new IsSetCondition( condition ) ); } public String evaluateName( final TaskContext context ) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties index b8b48a121..cfee49e92 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties @@ -13,4 +13,4 @@ pattern.ifelse-duplicate.error=Can only set one of if/else for pattern data type type.no-create.error=Unable to create datatype. type.no-id.error=Id must be specified. -unknown-family=Don't know how to detect os family "{0}" \ No newline at end of file +unknown-family=Don't know how to detect os family "{0}" diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/AndCondition.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/AndCondition.java new file mode 100644 index 000000000..e0dc84cba --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/AndCondition.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; + +/** + * <and> condition container.

+ * + * 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 ) - * - * look for: - * full-pathname specified == path in list - * full-pathname specified == parent dir of path in list - * simple name specified == path in list - * simple name specified == path in list + name - * simple name specified == parent dir + name - * simple name specified == parent of parent dir + name - * - */ - File path = new File( paths[ i ] ); - - // ** full-pathname specified == path in list - // ** simple name specified == path in list - if( path.exists() && m_file.equals( paths[ i ] ) ) - { - if( m_type == null ) - { - getLogger().debug( "Found: " + path ); - return true; - } - else if( m_type.isDir() - && path.isDirectory() ) - { - getLogger().debug( "Found directory: " + path ); - return true; - } - else if( m_type.isFile() - && path.isFile() ) - { - getLogger().debug( "Found file: " + path ); - return true; - } - // not the requested type - return false; - } - - File parent = path.getParentFile(); - // ** full-pathname specified == parent dir of path in list - if( parent != null && parent.exists() - && m_file.equals( parent.getAbsolutePath() ) ) - { - if( m_type == null ) - { - getLogger().debug( "Found: " + parent ); - return true; - } - else if( m_type.isDir() ) - { - getLogger().debug( "Found directory: " + parent ); - return true; - } - // not the requested type - return false; - } - - // ** simple name specified == path in list + name - if( path.exists() && path.isDirectory() ) - { - if( checkFile( new File( path, m_file ), - m_file + " in " + path ) ) - { - return true; - } - } - - // ** simple name specified == parent dir + name - if( parent != null && parent.exists() ) - { - if( checkFile( new File( parent, m_file ), - m_file + " in " + parent ) ) - { - return true; - } - } - - // ** simple name specified == parent of parent dir + name - if( parent != null ) - { - File grandParent = parent.getParentFile(); - if( grandParent != null && grandParent.exists() ) - { - if( checkFile( new File( grandParent, m_file ), - m_file + " in " + grandParent ) ) - { - return true; - } - } - } - } - } - return false; - } - - private boolean checkFile( File f, String text ) - { - if( m_type != null ) - { - if( m_type.isDir() ) - { - if( f.isDirectory() ) - { - getLogger().debug( "Found directory: " + text ); - } - return f.isDirectory(); - } - else if( m_type.isFile() ) - { - if( f.isFile() ) - { - getLogger().debug( "Found file: " + text ); - } - return f.isFile(); - } - } - if( f.exists() ) - { - getLogger().debug( "Found: " + text ); - } - return f.exists(); - } - - 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/UpToDate.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java index 54fd094d8..26d3decc2 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java @@ -11,7 +11,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Iterator; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.condition.Condition; import org.apache.tools.ant.types.DirectoryScanner; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.ScannerUtil; @@ -31,7 +30,7 @@ import org.apache.tools.ant.util.mappers.MergingMapper; * @author Stefan Bodewig */ -public class UpToDate extends MatchingTask implements Condition +public class UpToDate extends MatchingTask { private ArrayList sourceFileSets = new ArrayList(); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java index 5ee5e37a4..72d4e0900 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java @@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs; import java.util.Hashtable; 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; import org.apache.tools.ant.types.EnumeratedAttribute; /** @@ -35,13 +36,23 @@ import org.apache.tools.ant.types.EnumeratedAttribute; * @author Magesh Umasankar */ -public class WaitFor extends ConditionBase +public class WaitFor + extends AbstractTask { private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time private long maxWaitMultiplier = 1l; private long checkEveryMillis = 500l; private long checkEveryMultiplier = 1l; private String timeoutProperty; + private AndCondition m_condition = new AndCondition(); + + /** + * Adds a condition. + */ + public void add( final Condition condition ) + { + m_condition.add( condition ); + } /** * Set the time between each check @@ -102,16 +113,6 @@ public class WaitFor extends ConditionBase public void execute() throws TaskException { - if( countConditions() > 1 ) - { - throw new TaskException( "You must not nest more than one condition into " ); - } - if( countConditions() < 1 ) - { - throw new TaskException( "You must nest a condition into " ); - } - Condition c = (Condition)getConditions().nextElement(); - maxWaitMillis *= maxWaitMultiplier; checkEveryMillis *= checkEveryMultiplier; long start = System.currentTimeMillis(); @@ -119,7 +120,7 @@ public class WaitFor extends ConditionBase while( System.currentTimeMillis() < end ) { - if( c.eval() ) + if( m_condition.evaluate( getContext() ) ) { return; } diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/And.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/And.java deleted file mode 100644 index f2c68971d..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/And.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 java.util.Enumeration; -import org.apache.myrmidon.api.TaskException; - -/** - * <and> condition container.

- * - * 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 " ); - } - if( countConditions() < 1 ) - { - throw new TaskException( "You must nest a condition into " ); - } - return !( (Condition)getConditions().nextElement() ).eval(); - } - -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Or.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Or.java deleted file mode 100644 index 6431172d6..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Or.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 java.util.Enumeration; -import org.apache.myrmidon.api.TaskException; - -/** - * <or> condition container.

- * - * 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
- * Possible values:
- *
  • dos
  • - *
  • mac
  • - *
  • netware
  • - *
  • os/2
  • - *
  • unix
  • - *
  • windows
- */ - public void setFamily( final String family ) - { - m_family = family.toLowerCase( Locale.US ); - } - - /** - * Sets the desired OS name - * - * @param name The OS name - */ - public void setName( final String name ) - { - m_name = name.toLowerCase( Locale.US ); - } - - /** - * Sets the desired OS architecture - * - * @param arch The OS architecture - */ - public void setArch( final String arch ) - { - m_arch = arch.toLowerCase( Locale.US ); - } - - /** - * Sets the desired OS version - * - * @param version The OS version - */ - public void setVersion( String version ) - { - this.m_version = version.toLowerCase( Locale.US ); - } - - /** - * Determines if the OS on which Ant is executing matches the type of - * that set in setFamily. - * @see Os#setFamily(String) - */ - public boolean eval() - throws TaskException - { - return Os.isOs( m_family, m_name, m_arch, m_version ); - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java index b66cd8254..4834acb67 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java +++ b/proposal/myrmidon/src/main/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 ) { diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Available.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Available.java deleted file mode 100644 index e537e3732..000000000 --- a/proposal/myrmidon/src/todo/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 ) - * - * look for: - * full-pathname specified == path in list - * full-pathname specified == parent dir of path in list - * simple name specified == path in list - * simple name specified == path in list + name - * simple name specified == parent dir + name - * simple name specified == parent of parent dir + name - * - */ - File path = new File( paths[ i ] ); - - // ** full-pathname specified == path in list - // ** simple name specified == path in list - if( path.exists() && m_file.equals( paths[ i ] ) ) - { - if( m_type == null ) - { - getLogger().debug( "Found: " + path ); - return true; - } - else if( m_type.isDir() - && path.isDirectory() ) - { - getLogger().debug( "Found directory: " + path ); - return true; - } - else if( m_type.isFile() - && path.isFile() ) - { - getLogger().debug( "Found file: " + path ); - return true; - } - // not the requested type - return false; - } - - File parent = path.getParentFile(); - // ** full-pathname specified == parent dir of path in list - if( parent != null && parent.exists() - && m_file.equals( parent.getAbsolutePath() ) ) - { - if( m_type == null ) - { - getLogger().debug( "Found: " + parent ); - return true; - } - else if( m_type.isDir() ) - { - getLogger().debug( "Found directory: " + parent ); - return true; - } - // not the requested type - return false; - } - - // ** simple name specified == path in list + name - if( path.exists() && path.isDirectory() ) - { - if( checkFile( new File( path, m_file ), - m_file + " in " + path ) ) - { - return true; - } - } - - // ** simple name specified == parent dir + name - if( parent != null && parent.exists() ) - { - if( checkFile( new File( parent, m_file ), - m_file + " in " + parent ) ) - { - return true; - } - } - - // ** simple name specified == parent of parent dir + name - if( parent != null ) - { - File grandParent = parent.getParentFile(); - if( grandParent != null && grandParent.exists() ) - { - if( checkFile( new File( grandParent, m_file ), - m_file + " in " + grandParent ) ) - { - return true; - } - } - } - } - } - return false; - } - - private boolean checkFile( File f, String text ) - { - if( m_type != null ) - { - if( m_type.isDir() ) - { - if( f.isDirectory() ) - { - getLogger().debug( "Found directory: " + text ); - } - return f.isDirectory(); - } - else if( m_type.isFile() ) - { - if( f.isFile() ) - { - getLogger().debug( "Found file: " + text ); - } - return f.isFile(); - } - } - if( f.exists() ) - { - getLogger().debug( "Found: " + text ); - } - return f.exists(); - } - - 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/todo/org/apache/tools/ant/taskdefs/ConditionTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ConditionTask.java deleted file mode 100644 index de252f57a..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ConditionTask.java +++ /dev/null @@ -1,79 +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 org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.condition.Condition; -import org.apache.tools.ant.taskdefs.condition.ConditionBase; - -/** - * <condition> task as a generalization of <available> and - * <uptodate>

- * - * 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 " ); - } - if( countConditions() < 1 ) - { - throw new TaskException( "You must nest a condition into " ); - } - Condition c = (Condition)getConditions().nextElement(); - if( c.eval() ) - { - final String name = property; - final Object value1 = value; - getContext().setProperty( name, value1 ); - } - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/UpToDate.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/UpToDate.java index 54fd094d8..26d3decc2 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/UpToDate.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/UpToDate.java @@ -11,7 +11,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Iterator; import org.apache.myrmidon.api.TaskException; -import org.apache.tools.ant.taskdefs.condition.Condition; import org.apache.tools.ant.types.DirectoryScanner; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.ScannerUtil; @@ -31,7 +30,7 @@ import org.apache.tools.ant.util.mappers.MergingMapper; * @author Stefan Bodewig */ -public class UpToDate extends MatchingTask implements Condition +public class UpToDate extends MatchingTask { private ArrayList sourceFileSets = new ArrayList(); diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/WaitFor.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/WaitFor.java index 5ee5e37a4..72d4e0900 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/WaitFor.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/WaitFor.java @@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs; import java.util.Hashtable; 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; import org.apache.tools.ant.types.EnumeratedAttribute; /** @@ -35,13 +36,23 @@ import org.apache.tools.ant.types.EnumeratedAttribute; * @author Magesh Umasankar */ -public class WaitFor extends ConditionBase +public class WaitFor + extends AbstractTask { private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time private long maxWaitMultiplier = 1l; private long checkEveryMillis = 500l; private long checkEveryMultiplier = 1l; private String timeoutProperty; + private AndCondition m_condition = new AndCondition(); + + /** + * Adds a condition. + */ + public void add( final Condition condition ) + { + m_condition.add( condition ); + } /** * Set the time between each check @@ -102,16 +113,6 @@ public class WaitFor extends ConditionBase public void execute() throws TaskException { - if( countConditions() > 1 ) - { - throw new TaskException( "You must not nest more than one condition into " ); - } - if( countConditions() < 1 ) - { - throw new TaskException( "You must nest a condition into " ); - } - Condition c = (Condition)getConditions().nextElement(); - maxWaitMillis *= maxWaitMultiplier; checkEveryMillis *= checkEveryMultiplier; long start = System.currentTimeMillis(); @@ -119,7 +120,7 @@ public class WaitFor extends ConditionBase while( System.currentTimeMillis() < end ) { - if( c.eval() ) + if( m_condition.evaluate( getContext() ) ) { return; } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/And.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/And.java deleted file mode 100644 index f2c68971d..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/And.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 java.util.Enumeration; -import org.apache.myrmidon.api.TaskException; - -/** - * <and> condition container.

- * - * 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 " ); - } - if( countConditions() < 1 ) - { - throw new TaskException( "You must nest a condition into " ); - } - return !( (Condition)getConditions().nextElement() ).eval(); - } - -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Or.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Or.java deleted file mode 100644 index 6431172d6..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/condition/Or.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 java.util.Enumeration; -import org.apache.myrmidon.api.TaskException; - -/** - * <or> condition container.

- * - * 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 ) {