adammurdoch 02/03/02 18:19:11
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
UpToDate.java WaitFor.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition
Equals.java Http.java Socket.java
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
DefaultProjectBuilder.java Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace
DefaultWorkspace.java
proposal/myrmidon/src/java/org/apache/myrmidon/framework
Condition.java Pattern.java Resources.properties
proposal/myrmidon/src/java/org/apache/antlib/core Fail.java
IfTask.java
Added:
proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions
AndCondition.java IsSetCondition.java
NotCondition.java OrCondition.java
Resources.properties
proposal/myrmidon/src/java/org/apache/antlib/core
Available.java ConditionTask.java OsCondition.java
Removed: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
Available.java ConditionTask.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition
And.java Condition.java ConditionBase.java
IsSet.java Not.java Or.java OsCondition.java
Log:
Restructured the conditional tasks:
* 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.
Revision Changes Path
1.22 +1 -2
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
Index: UpToDate.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/UpToDate.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- UpToDate.java 6 Feb 2002 13:38:21 -0000 1.21
+++ UpToDate.java 3 Mar 2002 02:19:10 -0000 1.22
@@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.ScannerUtil;
@@ -31,7 +30,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*/
-public class UpToDate extends MatchingTask implements Condition
+public class UpToDate extends MatchingTask
{
private ArrayList sourceFileSets = new ArrayList();
1.7 +15 -14
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java
Index: WaitFor.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/WaitFor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WaitFor.java 6 Feb 2002 13:38:21 -0000 1.6
+++ WaitFor.java 3 Mar 2002 02:19:10 -0000 1.7
@@ -9,8 +9,9 @@
import java.util.Hashtable;
import org.apache.myrmidon.api.TaskException;
-import org.apache.tools.ant.taskdefs.condition.Condition;
-import org.apache.tools.ant.taskdefs.condition.ConditionBase;
+import org.apache.myrmidon.api.AbstractTask;
+import org.apache.myrmidon.framework.conditions.AndCondition;
+import org.apache.myrmidon.framework.Condition;
import org.apache.tools.ant.types.EnumeratedAttribute;
/**
@@ -35,13 +36,23 @@
* @author <a href="mailto:[EMAIL PROTECTED]">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 maxWaitMultiplier = 1l;
private long checkEveryMillis = 500l;
private long checkEveryMultiplier = 1l;
private String timeoutProperty;
+ private AndCondition m_condition = new AndCondition();
+
+ /**
+ * Adds a condition.
+ */
+ public void add( final Condition condition )
+ {
+ m_condition.add( condition );
+ }
/**
* Set the time between each check
@@ -102,16 +113,6 @@
public void execute()
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;
checkEveryMillis *= checkEveryMultiplier;
long start = System.currentTimeMillis();
@@ -119,7 +120,7 @@
while( System.currentTimeMillis() < end )
{
- if( c.eval() )
+ if( m_condition.evaluate( getContext() ) )
{
return;
}
1.4 +12 -3
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java
Index: Equals.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Equals.java 23 Dec 2001 06:34:23 -0000 1.3
+++ Equals.java 3 Mar 2002 02:19:10 -0000 1.4
@@ -5,15 +5,18 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
-package org.apache.tools.ant.taskdefs.condition;
import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.api.TaskContext;
+import org.apache.myrmidon.framework.Condition;
/**
* Simple String comparison condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
+ *
+ * @ant:type type="condition" nam="equals"
*/
public class Equals implements Condition
{
@@ -30,7 +33,13 @@
arg2 = a2;
}
- public boolean eval()
+ /**
+ * Evaluates this condition.
+ *
+ * @param context
+ * The context to evaluate the condition in.
+ */
+ public boolean evaluate( final TaskContext context )
throws TaskException
{
if( arg1 == null || arg2 == null )
1.6 +8 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
Index: Http.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Http.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Http.java 23 Dec 2001 14:22:45 -0000 1.5
+++ Http.java 3 Mar 2002 02:19:10 -0000 1.6
@@ -12,6 +12,8 @@
import java.net.URL;
import java.net.URLConnection;
import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.api.TaskContext;
+import org.apache.myrmidon.framework.Condition;
import org.apache.tools.ant.ProjectComponent;
/**
@@ -19,6 +21,8 @@
* the URL of the request.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Denis Hennessy</a>
+ *
+ * @ant:type type="condition" nam="http"
*/
public class Http
extends ProjectComponent
@@ -31,7 +35,10 @@
spec = url;
}
- public boolean eval()
+ /**
+ * Evaluates this condition.
+ */
+ public boolean evaluate( final TaskContext context )
throws TaskException
{
if( spec == null )
1.6 +9 -1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
Index: Socket.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Socket.java 23 Dec 2001 14:22:45 -0000 1.5
+++ Socket.java 3 Mar 2002 02:19:10 -0000 1.6
@@ -9,6 +9,8 @@
import java.io.IOException;
import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.api.TaskContext;
+import org.apache.myrmidon.framework.Condition;
import org.apache.tools.ant.ProjectComponent;
/**
@@ -16,6 +18,8 @@
* are: server - the name of the server. port - the port number of the
socket.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Denis Hennessy</a>
+ *
+ * @ant:type type="condition" nam="socket"
*/
public class Socket
extends ProjectComponent
@@ -34,7 +38,10 @@
this.server = server;
}
- public boolean eval()
+ /**
+ * Evaluates this condition.
+ */
+ public boolean evaluate( TaskContext context )
throws TaskException
{
if( server == null )
@@ -49,6 +56,7 @@
try
{
java.net.Socket socket = new java.net.Socket( server, port );
+ socket.close();
}
catch( IOException e )
{
1.35 +16 -14
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java
Index: DefaultProjectBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- DefaultProjectBuilder.java 1 Mar 2002 10:33:56 -0000 1.34
+++ DefaultProjectBuilder.java 3 Mar 2002 02:19:10 -0000 1.35
@@ -23,6 +23,9 @@
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.myrmidon.framework.Condition;
+import org.apache.myrmidon.framework.conditions.AndCondition;
+import org.apache.myrmidon.framework.conditions.IsSetCondition;
+import org.apache.myrmidon.framework.conditions.NotCondition;
import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
import org.apache.myrmidon.interfaces.model.Project;
import org.apache.myrmidon.interfaces.model.Target;
@@ -33,7 +36,7 @@
* Default implementation to construct project from a build file.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.34 $ $Date: 2002/03/01 10:33:56 $
+ * @version $Revision: 1.35 $ $Date: 2002/03/03 02:19:10 $
* @ant:type type="project-builder" name="xml"
* @ant:type type="project-builder" name="ant"
*/
@@ -381,7 +384,7 @@
}
final String[] dependencies = buildDependsList( depends, target );
- final Condition condition = buildCondition( ifCondition,
unlessCondition, target );
+ final Condition condition = buildCondition( ifCondition,
unlessCondition );
final Target defaultTarget =
new Target( condition, target.getChildren(), dependencies );
@@ -442,17 +445,13 @@
return dependencies;
}
- private Condition buildCondition( final String ifCondition, final String
unlessCondition, final Configuration target ) throws Exception
+ private Condition buildCondition( final String ifCondition,
+ final String unlessCondition )
+ throws Exception
{
- if( null != ifCondition && null != unlessCondition )
- {
- final String message =
- REZ.getString( "ant.target-bad-logic.error",
target.getLocation() );
- throw new Exception( message );
- }
-
- Condition condition = null;
+ final AndCondition condition = new AndCondition();
+ // Add the 'if' condition
if( null != ifCondition )
{
if( getLogger().isDebugEnabled() )
@@ -460,17 +459,20 @@
final String message = REZ.getString(
"ant.target-if.notice", ifCondition );
getLogger().debug( message );
}
- condition = new Condition( true, ifCondition );
+ condition.add( new IsSetCondition( ifCondition ) );
}
- else if( null != unlessCondition )
+
+ // Add the 'unless' condition
+ if( null != unlessCondition )
{
if( getLogger().isDebugEnabled() )
{
final String message = REZ.getString(
"ant.target-unless.notice", unlessCondition );
getLogger().debug( message );
}
- condition = new Condition( false, unlessCondition );
+ condition.add( new NotCondition( new IsSetCondition(
unlessCondition ) ) );
}
+
return condition;
}
1.5 +0 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Resources.properties 2 Feb 2002 05:58:21 -0000 1.4
+++ Resources.properties 3 Mar 2002 02:19:10 -0000 1.5
@@ -21,7 +21,6 @@
ant.import-malformed.error=Malformed import at {0}. If name or type
attribute is specified, both attributes must be specified.
ant.target-noname.error=Discovered un-named target at {0}.
ant.target-bad-name.error=Target with an invalid name at {0}.
-ant.target-bad-logic.error=Discovered invalid target that has both a if and
unless condition at {0}.
ant.target-bad-dependency.error=Discovered empty dependency in target {0} at
{1}.
ant.malformed.version=Malformed version string "{0}" specified in version
attribute of project.
ant.version-missing.error=Missing version attribute from project.
1.28 +2 -3
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java
Index: DefaultWorkspace.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultWorkspace.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- DefaultWorkspace.java 25 Feb 2002 10:42:43 -0000 1.27
+++ DefaultWorkspace.java 3 Mar 2002 02:19:10 -0000 1.28
@@ -45,7 +45,7 @@
* This is the default implementation of Workspace.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.27 $ $Date: 2002/02/25 10:42:43 $
+ * @version $Revision: 1.28 $ $Date: 2002/03/03 02:19:10 $
*/
public class DefaultWorkspace
extends AbstractLogEnabled
@@ -388,8 +388,7 @@
{
try
{
- final boolean result =
- condition.evaluate( frame.getContext() );
+ final boolean result = condition.evaluate(
frame.getContext() );
if( !result )
{
final String message = REZ.getString(
"skip-target.notice", name );
1.15 +13 -57
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java
Index: Condition.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Condition.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Condition.java 21 Feb 2002 11:06:41 -0000 1.14
+++ Condition.java 3 Mar 2002 02:19:10 -0000 1.15
@@ -13,64 +13,20 @@
/**
* Class representing a condition.
*
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.14 $ $Date: 2002/02/21 11:06:41 $
+ * @version $Revision: 1.15 $ $Date: 2002/03/03 02:19:10 $
+ *
+ * @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;
}
-
-
1.17 +5 -3
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java
Index: Pattern.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Pattern.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Pattern.java 1 Mar 2002 02:13:35 -0000 1.16
+++ Pattern.java 3 Mar 2002 02:19:10 -0000 1.17
@@ -11,12 +11,14 @@
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
+import org.apache.myrmidon.framework.conditions.IsSetCondition;
+import org.apache.myrmidon.framework.conditions.NotCondition;
/**
* Basic data type for holding patterns.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.16 $ $Date: 2002/03/01 02:13:35 $
+ * @version $Revision: 1.17 $ $Date: 2002/03/03 02:19:10 $
* @ant:data-type name="pattern"
*/
public class Pattern
@@ -77,7 +79,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new Condition( true, condition );
+ m_condition = new IsSetCondition( condition );
}
/**
@@ -90,7 +92,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new Condition( false, condition );
+ m_condition = new NotCondition( new IsSetCondition( condition ) );
}
public String evaluateName( final TaskContext context )
1.7 +1 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Resources.properties 14 Feb 2002 10:21:12 -0000 1.6
+++ Resources.properties 3 Mar 2002 02:19:11 -0000 1.7
@@ -13,4 +13,4 @@
type.no-create.error=Unable to create datatype.
type.no-id.error=Id must be specified.
-unknown-family=Don't know how to detect os family "{0}"
\ No newline at end of file
+unknown-family=Don't know how to detect os family "{0}"
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/AndCondition.java
Index: AndCondition.java
===================================================================
/*
* 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:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @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;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java
Index: IsSetCondition.java
===================================================================
/*
* 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 [EMAIL PROTECTED] Condition} that is true when a property is set, but
not set to
* 'false'.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/03 02:19:11 $
*
* @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" ) );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java
Index: NotCondition.java
===================================================================
/*
* 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:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @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 );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/OrCondition.java
Index: OrCondition.java
===================================================================
/*
* 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:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @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);
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties
Index: Resources.properties
===================================================================
isset.no-property.error=No property specified to test.
1.7 +4 -36
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java
Index: Fail.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Fail.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Fail.java 25 Jan 2002 23:18:18 -0000 1.6
+++ Fail.java 3 Mar 2002 02:19:11 -0000 1.7
@@ -9,7 +9,6 @@
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.framework.Condition;
/**
* This is a task used to throw a TaskException.
@@ -22,7 +21,6 @@
extends AbstractTask
{
private String m_message;
- private Condition m_condition;
public void setMessage( final String message )
{
@@ -36,38 +34,16 @@
m_message = message;
}
- public void setIf( final String ifCondition )
- {
- checkNullCondition();
- m_condition = new Condition( true, ifCondition );
- }
-
- public void setUnless( final String unlessCondition )
- {
- checkNullCondition();
- m_condition = new Condition( false, unlessCondition );
- }
-
public void execute()
throws TaskException
{
- boolean failed = true;
-
- if( null != m_condition )
+ if( null != m_message )
{
- failed = m_condition.evaluate( getContext() );
+ throw new TaskException( m_message );
}
-
- if( failed )
+ else
{
- if( null != m_message )
- {
- throw new TaskException( m_message );
- }
- else
- {
- throw new TaskException();
- }
+ throw new TaskException();
}
}
@@ -78,14 +54,6 @@
final String message = "Message can only be set once by " +
"either nested content or the message attribute";
throw new IllegalStateException( message );
- }
- }
-
- private void checkNullCondition()
- {
- if( null != m_condition )
- {
- throw new IllegalStateException( "Condition already set!" );
}
}
}
1.4 +5 -3
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java
Index: IfTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IfTask.java 2 Mar 2002 06:24:09 -0000 1.3
+++ IfTask.java 3 Mar 2002 02:19:11 -0000 1.4
@@ -14,6 +14,8 @@
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.framework.Condition;
+import org.apache.myrmidon.framework.conditions.IsSetCondition;
+import org.apache.myrmidon.framework.conditions.NotCondition;
import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
import org.apache.myrmidon.interfaces.executor.Executor;
@@ -22,7 +24,7 @@
* then it will execute the inner tasks, else it won't.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.3 $ $Date: 2002/03/02 06:24:09 $
+ * @version $Revision: 1.4 $ $Date: 2002/03/03 02:19:11 $
* @ant:task name="if"
*/
public class IfTask
@@ -44,7 +46,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new Condition( true, condition );
+ m_condition = new IsSetCondition( condition );
}
/**
@@ -57,7 +59,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new Condition( false, condition );
+ m_condition = new NotCondition( new IsSetCondition( condition ) );
}
public void add( final Configuration task )
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Available.java
Index: Available.java
===================================================================
/*
* 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:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">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;
}
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/ConditionTask.java
Index: ConditionTask.java
===================================================================
/*
* 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 org.apache.myrmidon.api.TaskException;
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
* <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:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @ant:task name="condition"
*/
public class ConditionTask
extends AbstractTask
{
private AndCondition m_condition = new AndCondition();
private String m_property;
private String m_value = "true";
/**
* Adds a condition.
*/
public void add( final Condition condition )
{
m_condition.add( condition );
}
/**
* The name of the property to set. Required.
*
* @param p The new Property value
*/
public void setProperty( final String p )
{
m_property = p;
}
/**
* The value for the property to set. Defaults to "true".
*
* @param v The new Value value
*/
public void setValue( final String v )
{
m_value = v;
}
/**
* See whether our nested condition holds and set the property.
*/
public void execute()
throws TaskException
{
if( m_property == null )
{
throw new TaskException( "No property was specified" );
}
if( m_condition.evaluate( getContext() ) )
{
getContext().setProperty( m_property, m_value );
}
}
}
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/OsCondition.java
Index: OsCondition.java
===================================================================
/*
* 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 org.apache.aut.nativelib.Os;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.Condition;
/**
* Condition to check the current OS.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @ant:type type="condition" name="os"
*/
public class OsCondition
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 family The OS family type desired.
*/
public void setFamily( final String family )
{
m_family = family;
}
/**
* Sets the desired OS name
*
* @param name The OS name
*/
public void setName( final String name )
{
m_name = name;
}
/**
* Sets the desired OS architecture
*
* @param arch The OS architecture
*/
public void setArch( final String arch )
{
m_arch = arch;
}
/**
* Sets the desired OS version
*
* @param version The OS version
*/
public void setVersion( final String version )
{
m_version = version;
}
/**
* Evaluates this condition.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
return Os.isOs( m_family, m_name, m_arch, m_version );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>