* Made framework.Condition an interface. * Converted old framework.Condition into <is-set> condition. * Ported all Ant 1 conditions to the new Condition interface, and removed the old Condition and ConditionBase classes. * Moved <and>, <or>, <not> conditions to framework.conditions. * Moved <condition> task and <os> condition to antlib. * Moved <available> to antlib. This is no longer a task, just a condition. Removed all file checking, which will be done by other condition implementations. * Removed conditions from <fail>, as it can be wrapped in an <if> instead. * A target can now take both an "if" and an "unless" condition. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271683 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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 <a href="mailto:stefano@apache.org"> | |||||
| * stefano@apache.org</a> | |||||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | |||||
| * | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -5,11 +5,12 @@ | |||||
| * version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
| * the LICENSE.txt file. | * the LICENSE.txt file. | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs; | |||||
| package org.apache.antlib.core; | |||||
| import org.apache.myrmidon.api.TaskException; | 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 | * <condition> task as a generalization of <available> and | ||||
| @@ -22,58 +23,58 @@ import org.apache.tools.ant.taskdefs.condition.ConditionBase; | |||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @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. | * The name of the property to set. Required. | ||||
| * | * | ||||
| * @param p The new Property value | * @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". | * The value for the property to set. Defaults to "true". | ||||
| * | * | ||||
| * @param v The new Value value | * @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. | * See whether our nested condition holds and set the property. | ||||
| * | |||||
| * @exception TaskException Description of Exception | |||||
| * @since 1.1 | |||||
| */ | */ | ||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( countConditions() > 1 ) | |||||
| { | |||||
| throw new TaskException( "You must not nest more than one condition into <condition>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| if( m_property == null ) | |||||
| { | { | ||||
| throw new TaskException( "You must nest a condition into <condition>" ); | |||||
| 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 ); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -9,7 +9,6 @@ package org.apache.antlib.core; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * This is a task used to throw a TaskException. | * This is a task used to throw a TaskException. | ||||
| @@ -22,7 +21,6 @@ public class Fail | |||||
| extends AbstractTask | extends AbstractTask | ||||
| { | { | ||||
| private String m_message; | private String m_message; | ||||
| private Condition m_condition; | |||||
| public void setMessage( final String message ) | public void setMessage( final String message ) | ||||
| { | { | ||||
| @@ -36,38 +34,16 @@ public class Fail | |||||
| m_message = message; | 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() | public void execute() | ||||
| throws TaskException | 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 ); | throw new IllegalStateException( message ); | ||||
| } | } | ||||
| } | } | ||||
| private void checkNullCondition() | |||||
| { | |||||
| if( null != m_condition ) | |||||
| { | |||||
| throw new IllegalStateException( "Condition already set!" ); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -14,6 +14,8 @@ import org.apache.avalon.framework.configuration.Configuration; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.AbstractContainerTask; | import org.apache.myrmidon.framework.AbstractContainerTask; | ||||
| import org.apache.myrmidon.framework.Condition; | 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.ExecutionFrame; | ||||
| import org.apache.myrmidon.interfaces.executor.Executor; | import org.apache.myrmidon.interfaces.executor.Executor; | ||||
| @@ -44,7 +46,7 @@ public class IfTask | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| verifyConditionNull(); | verifyConditionNull(); | ||||
| m_condition = new Condition( true, condition ); | |||||
| m_condition = new IsSetCondition( condition ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -57,7 +59,7 @@ public class IfTask | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| verifyConditionNull(); | verifyConditionNull(); | ||||
| m_condition = new Condition( false, condition ); | |||||
| m_condition = new NotCondition( new IsSetCondition( condition ) ); | |||||
| } | } | ||||
| public void add( final Configuration task ) | public void add( final Configuration task ) | ||||
| @@ -5,20 +5,22 @@ | |||||
| * version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
| * the LICENSE.txt file. | * 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.aut.nativelib.Os; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * Condition to check the current OS.</p> | * Condition to check the current OS.</p> | ||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @version $Revision$ | ||||
| * | |||||
| * @ant:type type="condition" name="os" | |||||
| */ | */ | ||||
| public class OsCondition | public class OsCondition | ||||
| extends ConditionBase | |||||
| implements Condition | implements Condition | ||||
| { | { | ||||
| private String m_family; | private String m_family; | ||||
| @@ -29,18 +31,11 @@ public class OsCondition | |||||
| /** | /** | ||||
| * Sets the desired OS family type | * Sets the desired OS family type | ||||
| * | * | ||||
| * @param f The OS family type desired<br /> | |||||
| * Possible values:<br /> | |||||
| * <ul><li>dos</li> | |||||
| * <li>mac</li> | |||||
| * <li>netware</li> | |||||
| * <li>os/2</li> | |||||
| * <li>unix</li> | |||||
| * <li>windows</li></ul> | |||||
| * @param family The OS family type desired. | |||||
| */ | */ | ||||
| public void setFamily( final String family ) | 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 ) | 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 ) | 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 | * @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 | throws TaskException | ||||
| { | { | ||||
| return Os.isOs( m_family, m_name, m_arch, m_version ); | return Os.isOs( m_family, m_name, m_arch, m_version ); | ||||
| @@ -23,6 +23,9 @@ import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
| import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | import org.apache.avalon.framework.configuration.SAXConfigurationHandler; | ||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
| import org.apache.myrmidon.framework.Condition; | 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.builder.ProjectBuilder; | ||||
| import org.apache.myrmidon.interfaces.model.Project; | import org.apache.myrmidon.interfaces.model.Project; | ||||
| import org.apache.myrmidon.interfaces.model.Target; | import org.apache.myrmidon.interfaces.model.Target; | ||||
| @@ -381,7 +384,7 @@ public class DefaultProjectBuilder | |||||
| } | } | ||||
| final String[] dependencies = buildDependsList( depends, target ); | final String[] dependencies = buildDependsList( depends, target ); | ||||
| final Condition condition = buildCondition( ifCondition, unlessCondition, target ); | |||||
| final Condition condition = buildCondition( ifCondition, unlessCondition ); | |||||
| final Target defaultTarget = | final Target defaultTarget = | ||||
| new Target( condition, target.getChildren(), dependencies ); | new Target( condition, target.getChildren(), dependencies ); | ||||
| @@ -442,17 +445,13 @@ public class DefaultProjectBuilder | |||||
| return dependencies; | 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( null != ifCondition ) | ||||
| { | { | ||||
| if( getLogger().isDebugEnabled() ) | if( getLogger().isDebugEnabled() ) | ||||
| @@ -460,17 +459,20 @@ public class DefaultProjectBuilder | |||||
| final String message = REZ.getString( "ant.target-if.notice", ifCondition ); | final String message = REZ.getString( "ant.target-if.notice", ifCondition ); | ||||
| getLogger().debug( message ); | 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() ) | if( getLogger().isDebugEnabled() ) | ||||
| { | { | ||||
| final String message = REZ.getString( "ant.target-unless.notice", unlessCondition ); | final String message = REZ.getString( "ant.target-unless.notice", unlessCondition ); | ||||
| getLogger().debug( message ); | getLogger().debug( message ); | ||||
| } | } | ||||
| condition = new Condition( false, unlessCondition ); | |||||
| condition.add( new NotCondition( new IsSetCondition( unlessCondition ) ) ); | |||||
| } | } | ||||
| return condition; | return condition; | ||||
| } | } | ||||
| @@ -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.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-noname.error=Discovered un-named target at {0}. | ||||
| ant.target-bad-name.error=Target with an invalid name 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.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.malformed.version=Malformed version string "{0}" specified in version attribute of project. | ||||
| ant.version-missing.error=Missing version attribute from project. | ant.version-missing.error=Missing version attribute from project. | ||||
| @@ -388,8 +388,7 @@ public class DefaultWorkspace | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| final boolean result = | |||||
| condition.evaluate( frame.getContext() ); | |||||
| final boolean result = condition.evaluate( frame.getContext() ); | |||||
| if( !result ) | if( !result ) | ||||
| { | { | ||||
| final String message = REZ.getString( "skip-target.notice", name ); | final String message = REZ.getString( "skip-target.notice", name ); | ||||
| @@ -13,64 +13,20 @@ import org.apache.myrmidon.api.TaskException; | |||||
| /** | /** | ||||
| * Class representing a condition. | * Class representing a condition. | ||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @version $Revision$ $Date$ | * @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; | |||||
| } | } | ||||
| @@ -11,6 +11,8 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
| import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | 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. | * Basic data type for holding patterns. | ||||
| @@ -77,7 +79,7 @@ public class Pattern | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| verifyConditionNull(); | verifyConditionNull(); | ||||
| m_condition = new Condition( true, condition ); | |||||
| m_condition = new IsSetCondition( condition ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -90,7 +92,7 @@ public class Pattern | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| verifyConditionNull(); | verifyConditionNull(); | ||||
| m_condition = new Condition( false, condition ); | |||||
| m_condition = new NotCondition( new IsSetCondition( condition ) ); | |||||
| } | } | ||||
| public String evaluateName( final TaskContext context ) | public String evaluateName( final TaskContext context ) | ||||
| @@ -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-create.error=Unable to create datatype. | ||||
| type.no-id.error=Id must be specified. | type.no-id.error=Id must be specified. | ||||
| unknown-family=Don't know how to detect os family "{0}" | |||||
| unknown-family=Don't know how to detect os family "{0}" | |||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns false as soon as one evaluates to | |||||
| * false. An empty and condition returns true.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
| * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||||
| * @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" ) ); | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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 ); | |||||
| } | |||||
| } | |||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns true as soon as one evaluates to | |||||
| * true. An empty container evaluates to true</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1 @@ | |||||
| isset.no-property.error=No property specified to test. | |||||
| @@ -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 <a href="mailto:stefano@apache.org"> | |||||
| * stefano@apache.org</a> | |||||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | |||||
| */ | |||||
| 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 <fileset>) | |||||
| * | |||||
| * 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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -11,7 +11,6 @@ import java.io.File; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.myrmidon.api.TaskException; | 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.DirectoryScanner; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.types.ScannerUtil; | import org.apache.tools.ant.types.ScannerUtil; | ||||
| @@ -31,7 +30,7 @@ import org.apache.tools.ant.util.mappers.MergingMapper; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class UpToDate extends MatchingTask implements Condition | |||||
| public class UpToDate extends MatchingTask | |||||
| { | { | ||||
| private ArrayList sourceFileSets = new ArrayList(); | private ArrayList sourceFileSets = new ArrayList(); | ||||
| @@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs; | |||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import org.apache.myrmidon.api.TaskException; | 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; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| /** | /** | ||||
| @@ -35,13 +36,23 @@ import org.apache.tools.ant.types.EnumeratedAttribute; | |||||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | ||||
| */ | */ | ||||
| public class WaitFor extends ConditionBase | |||||
| public class WaitFor | |||||
| extends AbstractTask | |||||
| { | { | ||||
| private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time | private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time | ||||
| private long maxWaitMultiplier = 1l; | private long maxWaitMultiplier = 1l; | ||||
| private long checkEveryMillis = 500l; | private long checkEveryMillis = 500l; | ||||
| private long checkEveryMultiplier = 1l; | private long checkEveryMultiplier = 1l; | ||||
| private String timeoutProperty; | 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 | * Set the time between each check | ||||
| @@ -102,16 +113,6 @@ public class WaitFor extends ConditionBase | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( countConditions() > 1 ) | |||||
| { | |||||
| throw new TaskException( "You must not nest more than one condition into <waitfor>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| { | |||||
| throw new TaskException( "You must nest a condition into <waitfor>" ); | |||||
| } | |||||
| Condition c = (Condition)getConditions().nextElement(); | |||||
| maxWaitMillis *= maxWaitMultiplier; | maxWaitMillis *= maxWaitMultiplier; | ||||
| checkEveryMillis *= checkEveryMultiplier; | checkEveryMillis *= checkEveryMultiplier; | ||||
| long start = System.currentTimeMillis(); | long start = System.currentTimeMillis(); | ||||
| @@ -119,7 +120,7 @@ public class WaitFor extends ConditionBase | |||||
| while( System.currentTimeMillis() < end ) | while( System.currentTimeMillis() < end ) | ||||
| { | { | ||||
| if( c.eval() ) | |||||
| if( m_condition.evaluate( getContext() ) ) | |||||
| { | { | ||||
| return; | return; | ||||
| } | } | ||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns false as soon as one evaluates to | |||||
| * false.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @version $Revision$ | |||||
| */ | |||||
| public interface Condition | |||||
| { | |||||
| /** | |||||
| * Is this condition true? | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| boolean eval() | |||||
| throws TaskException; | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -5,15 +5,18 @@ | |||||
| * version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
| * the LICENSE.txt file. | * the LICENSE.txt file. | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.condition; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * Simple String comparison condition. | * Simple String comparison condition. | ||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @version $Revision$ | ||||
| * | |||||
| * @ant:type type="condition" nam="equals" | |||||
| */ | */ | ||||
| public class Equals implements Condition | public class Equals implements Condition | ||||
| { | { | ||||
| @@ -30,7 +33,13 @@ public class Equals implements Condition | |||||
| arg2 = a2; | 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 | throws TaskException | ||||
| { | { | ||||
| if( arg1 == null || arg2 == null ) | if( arg1 == null || arg2 == null ) | ||||
| @@ -12,6 +12,8 @@ import java.net.MalformedURLException; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.net.URLConnection; | import java.net.URLConnection; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| /** | /** | ||||
| @@ -19,6 +21,8 @@ import org.apache.tools.ant.ProjectComponent; | |||||
| * the URL of the request. | * the URL of the request. | ||||
| * | * | ||||
| * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | ||||
| * | |||||
| * @ant:type type="condition" nam="http" | |||||
| */ | */ | ||||
| public class Http | public class Http | ||||
| extends ProjectComponent | extends ProjectComponent | ||||
| @@ -31,7 +35,10 @@ public class Http | |||||
| spec = url; | spec = url; | ||||
| } | } | ||||
| public boolean eval() | |||||
| /** | |||||
| * Evaluates this condition. | |||||
| */ | |||||
| public boolean evaluate( final TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( spec == null ) | if( spec == 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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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 <not>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| { | |||||
| throw new TaskException( "You must nest a condition into <not>" ); | |||||
| } | |||||
| return !( (Condition)getConditions().nextElement() ).eval(); | |||||
| } | |||||
| } | |||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns true as soon as one evaluates to | |||||
| * true.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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<br /> | |||||
| * Possible values:<br /> | |||||
| * <ul><li>dos</li> | |||||
| * <li>mac</li> | |||||
| * <li>netware</li> | |||||
| * <li>os/2</li> | |||||
| * <li>unix</li> | |||||
| * <li>windows</li></ul> | |||||
| */ | |||||
| 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 ); | |||||
| } | |||||
| } | |||||
| @@ -9,6 +9,8 @@ package org.apache.tools.ant.taskdefs.condition; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| import org.apache.tools.ant.ProjectComponent; | 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. | * are: server - the name of the server. port - the port number of the socket. | ||||
| * | * | ||||
| * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | ||||
| * | |||||
| * @ant:type type="condition" nam="socket" | |||||
| */ | */ | ||||
| public class Socket | public class Socket | ||||
| extends ProjectComponent | extends ProjectComponent | ||||
| @@ -34,7 +38,10 @@ public class Socket | |||||
| this.server = server; | this.server = server; | ||||
| } | } | ||||
| public boolean eval() | |||||
| /** | |||||
| * Evaluates this condition. | |||||
| */ | |||||
| public boolean evaluate( TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( server == null ) | if( server == null ) | ||||
| @@ -49,6 +56,7 @@ public class Socket | |||||
| try | try | ||||
| { | { | ||||
| java.net.Socket socket = new java.net.Socket( server, port ); | java.net.Socket socket = new java.net.Socket( server, port ); | ||||
| socket.close(); | |||||
| } | } | ||||
| catch( IOException e ) | catch( IOException e ) | ||||
| { | { | ||||
| @@ -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 <a href="mailto:stefano@apache.org"> | |||||
| * stefano@apache.org</a> | |||||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | |||||
| */ | |||||
| 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 <fileset>) | |||||
| * | |||||
| * 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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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> <p> | |||||
| * | |||||
| * This task supports boolean logic as well as pluggable conditions to decide, | |||||
| * whether a property should be set.</p> <p> | |||||
| * | |||||
| * This task does not extend Task to take advantage of ConditionBase.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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 <condition>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| { | |||||
| throw new TaskException( "You must nest a condition into <condition>" ); | |||||
| } | |||||
| Condition c = (Condition)getConditions().nextElement(); | |||||
| if( c.eval() ) | |||||
| { | |||||
| final String name = property; | |||||
| final Object value1 = value; | |||||
| getContext().setProperty( name, value1 ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -11,7 +11,6 @@ import java.io.File; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.myrmidon.api.TaskException; | 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.DirectoryScanner; | ||||
| import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
| import org.apache.tools.ant.types.ScannerUtil; | import org.apache.tools.ant.types.ScannerUtil; | ||||
| @@ -31,7 +30,7 @@ import org.apache.tools.ant.util.mappers.MergingMapper; | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| */ | */ | ||||
| public class UpToDate extends MatchingTask implements Condition | |||||
| public class UpToDate extends MatchingTask | |||||
| { | { | ||||
| private ArrayList sourceFileSets = new ArrayList(); | private ArrayList sourceFileSets = new ArrayList(); | ||||
| @@ -9,8 +9,9 @@ package org.apache.tools.ant.taskdefs; | |||||
| import java.util.Hashtable; | import java.util.Hashtable; | ||||
| import org.apache.myrmidon.api.TaskException; | 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; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| /** | /** | ||||
| @@ -35,13 +36,23 @@ import org.apache.tools.ant.types.EnumeratedAttribute; | |||||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | ||||
| */ | */ | ||||
| public class WaitFor extends ConditionBase | |||||
| public class WaitFor | |||||
| extends AbstractTask | |||||
| { | { | ||||
| private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time | private long maxWaitMillis = 1000l * 60l * 3l;// default max wait time | ||||
| private long maxWaitMultiplier = 1l; | private long maxWaitMultiplier = 1l; | ||||
| private long checkEveryMillis = 500l; | private long checkEveryMillis = 500l; | ||||
| private long checkEveryMultiplier = 1l; | private long checkEveryMultiplier = 1l; | ||||
| private String timeoutProperty; | 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 | * Set the time between each check | ||||
| @@ -102,16 +113,6 @@ public class WaitFor extends ConditionBase | |||||
| public void execute() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( countConditions() > 1 ) | |||||
| { | |||||
| throw new TaskException( "You must not nest more than one condition into <waitfor>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| { | |||||
| throw new TaskException( "You must nest a condition into <waitfor>" ); | |||||
| } | |||||
| Condition c = (Condition)getConditions().nextElement(); | |||||
| maxWaitMillis *= maxWaitMultiplier; | maxWaitMillis *= maxWaitMultiplier; | ||||
| checkEveryMillis *= checkEveryMultiplier; | checkEveryMillis *= checkEveryMultiplier; | ||||
| long start = System.currentTimeMillis(); | long start = System.currentTimeMillis(); | ||||
| @@ -119,7 +120,7 @@ public class WaitFor extends ConditionBase | |||||
| while( System.currentTimeMillis() < end ) | while( System.currentTimeMillis() < end ) | ||||
| { | { | ||||
| if( c.eval() ) | |||||
| if( m_condition.evaluate( getContext() ) ) | |||||
| { | { | ||||
| return; | return; | ||||
| } | } | ||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns false as soon as one evaluates to | |||||
| * false.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @version $Revision$ | |||||
| */ | |||||
| public interface Condition | |||||
| { | |||||
| /** | |||||
| * Is this condition true? | |||||
| * | |||||
| * @return Description of the Returned Value | |||||
| * @exception TaskException Description of Exception | |||||
| */ | |||||
| boolean eval() | |||||
| throws TaskException; | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -5,15 +5,18 @@ | |||||
| * version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
| * the LICENSE.txt file. | * the LICENSE.txt file. | ||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.condition; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| /** | /** | ||||
| * Simple String comparison condition. | * Simple String comparison condition. | ||||
| * | * | ||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | ||||
| * @version $Revision$ | * @version $Revision$ | ||||
| * | |||||
| * @ant:type type="condition" nam="equals" | |||||
| */ | */ | ||||
| public class Equals implements Condition | public class Equals implements Condition | ||||
| { | { | ||||
| @@ -30,7 +33,13 @@ public class Equals implements Condition | |||||
| arg2 = a2; | 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 | throws TaskException | ||||
| { | { | ||||
| if( arg1 == null || arg2 == null ) | if( arg1 == null || arg2 == null ) | ||||
| @@ -12,6 +12,8 @@ import java.net.MalformedURLException; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.net.URLConnection; | import java.net.URLConnection; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| /** | /** | ||||
| @@ -19,6 +21,8 @@ import org.apache.tools.ant.ProjectComponent; | |||||
| * the URL of the request. | * the URL of the request. | ||||
| * | * | ||||
| * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | ||||
| * | |||||
| * @ant:type type="condition" nam="http" | |||||
| */ | */ | ||||
| public class Http | public class Http | ||||
| extends ProjectComponent | extends ProjectComponent | ||||
| @@ -31,7 +35,10 @@ public class Http | |||||
| spec = url; | spec = url; | ||||
| } | } | ||||
| public boolean eval() | |||||
| /** | |||||
| * Evaluates this condition. | |||||
| */ | |||||
| public boolean evaluate( final TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( spec == null ) | if( spec == 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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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 <not>" ); | |||||
| } | |||||
| if( countConditions() < 1 ) | |||||
| { | |||||
| throw new TaskException( "You must nest a condition into <not>" ); | |||||
| } | |||||
| return !( (Condition)getConditions().nextElement() ).eval(); | |||||
| } | |||||
| } | |||||
| @@ -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. <p> | |||||
| * | |||||
| * Iterates over all conditions and returns true as soon as one evaluates to | |||||
| * true.</p> | |||||
| * | |||||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||||
| * @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; | |||||
| } | |||||
| } | |||||
| @@ -9,6 +9,8 @@ package org.apache.tools.ant.taskdefs.condition; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.framework.Condition; | |||||
| import org.apache.tools.ant.ProjectComponent; | 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. | * are: server - the name of the server. port - the port number of the socket. | ||||
| * | * | ||||
| * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | * @author <a href="mailto:denis@network365.com">Denis Hennessy</a> | ||||
| * | |||||
| * @ant:type type="condition" nam="socket" | |||||
| */ | */ | ||||
| public class Socket | public class Socket | ||||
| extends ProjectComponent | extends ProjectComponent | ||||
| @@ -34,7 +38,10 @@ public class Socket | |||||
| this.server = server; | this.server = server; | ||||
| } | } | ||||
| public boolean eval() | |||||
| /** | |||||
| * Evaluates this condition. | |||||
| */ | |||||
| public boolean evaluate( TaskContext context ) | |||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| if( server == null ) | if( server == null ) | ||||
| @@ -49,6 +56,7 @@ public class Socket | |||||
| try | try | ||||
| { | { | ||||
| java.net.Socket socket = new java.net.Socket( server, port ); | java.net.Socket socket = new java.net.Socket( server, port ); | ||||
| socket.close(); | |||||
| } | } | ||||
| catch( IOException e ) | catch( IOException e ) | ||||
| { | { | ||||