adammurdoch 02/03/27 22:35:22
Modified: proposal/myrmidon/src/test/org/apache/antlib/core/test
IfTestCase.java
proposal/myrmidon/src/test/org/apache/myrmidon
AbstractMyrmidonTest.java AbstractProjectTest.java
proposal/myrmidon/src/java/org/apache/antlib/core
IfTask.java
proposal/myrmidon/src/java/org/apache/antlib/runtime
Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/framework
Pattern.java
proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions
IsSetCondition.java NotCondition.java
Resources.properties
Added:
proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test
AndConditionTestCase.java ConditionTestTask.java
IsSetConditionTestCase.java
IsTrueConditionTestCase.java
NotConditionTestCase.java OrConditionTestCase.java
TestCondition.java and.ant isset.ant istrue.ant
not.ant or.ant
proposal/myrmidon/src/java/org/apache/antlib/build
UpToDateCondition.java
proposal/myrmidon/src/java/org/apache/antlib/core
Equals.java
proposal/myrmidon/src/java/org/apache/antlib/runtime
TypeAvailableCondition.java
proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions
IsTrueCondition.java
Log:
Condition changes:
* Split <is-set> into <is-set> and <is-true> conditions. <is-true> uses the
converter to determine whether something is 'true', so is a little fussy.
* Moved <uptodate> and <equals> into antlib, and made <uptodate> a condition.
* Added <type-available> condition, which checks whether a particular
type is defined.
* Fixed <not> to actually work.
* Added test cases for some of the conditions.
Revision Changes Path
1.2 +2 -4
jakarta-ant/proposal/myrmidon/src/test/org/apache/antlib/core/test/IfTestCase.java
Index: IfTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/antlib/core/test/IfTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- IfTestCase.java 17 Mar 2002 08:06:37 -0000 1.1
+++ IfTestCase.java 28 Mar 2002 06:35:21 -0000 1.2
@@ -16,7 +16,7 @@
* Test cases for the <if> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.1 $ $Date: 2002/03/17 08:06:37 $
+ * @version $Revision: 1.2 $ $Date: 2002/03/28 06:35:21 $
*/
public class IfTestCase
extends AbstractProjectTest
@@ -42,9 +42,7 @@
executeTarget( projectFile, "true-prop", listener );
// Test when property is set to a value other than 'true' or 'false'
- listener = new LogMessageTracker();
- listener.addExpectedMessage( "set-prop", "test-prop is set" );
- executeTarget( projectFile, "set-prop", listener );
+ executeTargetExpectError( projectFile, "set-prop", new String[0] );
// Test when property is set to 'false'
listener = new LogMessageTracker();
1.11 +1 -1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/AbstractMyrmidonTest.java
Index: AbstractMyrmidonTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/AbstractMyrmidonTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractMyrmidonTest.java 17 Mar 2002 08:07:07 -0000 1.10
+++ AbstractMyrmidonTest.java 28 Mar 2002 06:35:21 -0000 1.11
@@ -127,7 +127,7 @@
/**
* Returns the directory containing a Myrmidon install.
*/
- protected File getHomeDirectory()
+ protected File getInstallDirectory()
{
final File file = new File( m_baseDir, "dist" );
return getCanonicalFile( file );
1.6 +2 -2
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java
Index: AbstractProjectTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/AbstractProjectTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractProjectTest.java 13 Mar 2002 07:35:19 -0000 1.5
+++ AbstractProjectTest.java 28 Mar 2002 06:35:21 -0000 1.6
@@ -20,7 +20,7 @@
* A base class for test cases which need to execute projects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.5 $ $Date: 2002/03/13 07:35:19 $
+ * @version $Revision: 1.6 $ $Date: 2002/03/28 06:35:21 $
*/
public class AbstractProjectTest
extends AbstractMyrmidonTest
@@ -59,7 +59,7 @@
m_embeddor.enableLogging( logger );
final Parameters params = new Parameters();
- final File instDir = getHomeDirectory();
+ final File instDir = getInstallDirectory();
params.setParameter( "myrmidon.home", instDir.getAbsolutePath()
);
m_embeddor.parameterize( params );
m_embeddor.initialize();
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/AndConditionTestCase.java
Index: AndConditionTestCase.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.test;
import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
/**
* Test cases for the <and> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*/
public class AndConditionTestCase
extends AbstractProjectTest
{
public AndConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of the <and> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "and.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/ConditionTestTask.java
Index: ConditionTestTask.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.test;
import org.apache.myrmidon.api.AbstractTask;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.conditions.Condition;
/**
* A simple assert task, used for testing conditions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*
* @ant.task name="assert"
*/
public class ConditionTestTask
extends AbstractTask
{
private boolean m_expected = true;
private Condition m_condition;
public void setExpected( final boolean expected )
{
m_expected = expected;
}
public void add( final Condition condition )
{
m_condition = condition;
}
/**
* Execute task.
*/
public void execute()
throws TaskException
{
final boolean result = m_condition.evaluate( getContext() );
if( result != m_expected )
{
throw new TaskException( "Expected " + m_expected + ", got " +
result );
}
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsSetConditionTestCase.java
Index: IsSetConditionTestCase.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.test;
import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsSetCondition;
/**
* Test cases for the <is-set> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*/
public class IsSetConditionTestCase
extends AbstractProjectTest
{
public IsSetConditionTestCase( final String name )
{
super( name );
}
/**
* Test cases for <is-set> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "isset.ant" );
executeTarget( projectFile, "set" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );
Resources res = getResourcesForTested( IsSetCondition.class );
final String[] messages = {
null,
res.getString( "isset.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/IsTrueConditionTestCase.java
Index: IsTrueConditionTestCase.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.test;
import java.io.File;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.framework.conditions.IsTrueCondition;
/**
* Test cases for the <is-true> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*/
public class IsTrueConditionTestCase
extends AbstractProjectTest
{
public IsTrueConditionTestCase( final String name )
{
super( name );
}
/**
* Test cases for <is-true> evaluation.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "istrue.ant" );
executeTarget( projectFile, "set2true" );
executeTarget( projectFile, "set2false" );
executeTarget( projectFile, "not-set" );
// TODO - check error message
String[] messages = {};
executeTargetExpectError( projectFile, "set", messages );
final Resources res = getResourcesForTested( IsTrueCondition.class );
messages = new String[] {
null,
res.getString( "istrue.no-property.error" )
};
executeTargetExpectError( projectFile, "no-prop-name", messages );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/NotConditionTestCase.java
Index: NotConditionTestCase.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.test;
import org.apache.myrmidon.AbstractProjectTest;
import java.io.File;
/**
* Test cases for the <not> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*/
public class NotConditionTestCase
extends AbstractProjectTest
{
public NotConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of <not>.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "not.ant" );
executeTarget( projectFile, "truth-table" );
// TODO - check error messages
executeTargetExpectError( projectFile, "empty", new String[0] );
executeTargetExpectError( projectFile, "too-many-nested", new
String[0] );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/OrConditionTestCase.java
Index: OrConditionTestCase.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.test;
import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
/**
* Test cases for the <or> condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*/
public class OrConditionTestCase
extends AbstractProjectTest
{
public OrConditionTestCase( final String name )
{
super( name );
}
/**
* Tests evaluation of the <or> condition.
*/
public void testEvaluation() throws Exception
{
final File projectFile = getTestResource( "or.ant" );
executeTarget( projectFile, "empty" );
executeTarget( projectFile, "truth-table" );
executeTarget( projectFile, "lazy" );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/TestCondition.java
Index: TestCondition.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.test;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* A condition used for testing.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:21 $
*
* @ant.type type="condition" name="true"
* @ant.type type="condition" name="false"
* @ant.type type="condition" name="fail"
*/
public class TestCondition
implements Condition, Configurable
{
private String m_action;
public void configure( final Configuration configuration )
throws ConfigurationException
{
m_action = configuration.getName();
}
/**
* Evaluates this condition.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
if( m_action.equalsIgnoreCase( "true" ) )
{
return true;
}
else if( m_action.equalsIgnoreCase( "false" ) )
{
return false;
}
else
{
throw new TaskException( "Fail." );
}
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/and.ant
Index: and.ant
===================================================================
<!-- Tests for the <and> condition. -->
<project version="2.0">
<!-- An empty <and> condition -->
<target name="empty">
<assert>
<and/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<and><false/></and>
</assert>
<assert>
<and><true/></and>
</assert>
<assert expected="false">
<and><false/><false/></and>
</assert>
<assert expected="false">
<and><true/><false/></and>
</assert>
<assert expected="false">
<and><false/><true/></and>
</assert>
<assert>
<and><true/><true/></and>
</assert>
</target>
<!-- Check lazy evaluation -->
<target name="lazy">
<assert expected="false">
<and><false/><fail/></and>
</assert>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/isset.ant
Index: isset.ant
===================================================================
<!-- Tests for the <is-set> condition. -->
<project version="2.0">
<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert>
<is-set property="test-prop"/>
</assert>
</target>
<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-set property="test-prop"/>
</assert>
</target>
<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-set/>
</assert>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/istrue.ant
Index: istrue.ant
===================================================================
<!-- Tests for the <is-true> condition. -->
<project version="2.0">
<!-- Set to some arbirary value -->
<target name="set">
<property name="test-prop">
<path location="some-location"/>
</property>
<assert>
<is-true property="test-prop"/>
</assert>
</target>
<!-- Set to true -->
<target name="set2true">
<property name="test-prop" value="true"/>
<assert>
<is-true property="test-prop"/>
</assert>
</target>
<!-- Set to false -->
<target name="set2false">
<property name="test-prop" value="false"/>
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>
<!-- Not set -->
<target name="not-set">
<assert expected="false">
<is-true property="test-prop"/>
</assert>
</target>
<!-- No property name -->
<target name="no-prop-name">
<assert>
<is-true/>
</assert>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/not.ant
Index: not.ant
===================================================================
<!-- Tests for the <not> condition. -->
<project version="2.0">
<!-- An empty <or> condition -->
<target name="empty">
<assert>
<not/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<not><true/></not>
</assert>
<assert>
<not><false/></not>
</assert>
</target>
<!-- Too many nested conditions -->
<target name="too-many-nested">
<assert>
<not><true/><false/></not>
</assert>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/framework/conditions/test/or.ant
Index: or.ant
===================================================================
<!-- Tests for the <or> condition. -->
<project version="2.0">
<!-- An empty <or> condition -->
<target name="empty">
<assert>
<or/>
</assert>
</target>
<!-- The truth-table -->
<target name="truth-table">
<assert expected="false">
<or><false/></or>
</assert>
<assert>
<or><true/></or>
</assert>
<assert expected="false">
<or><false/><false/></or>
</assert>
<assert>
<or><true/><false/></or>
</assert>
<assert>
<or><false/><true/></or>
</assert>
<assert>
<or><true/><true/></or>
</assert>
</target>
<!-- Check lazy evaluation -->
<target name="lazy">
<assert>
<or><true/><fail/></or>
</assert>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/build/UpToDateCondition.java
Index: UpToDateCondition.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.build;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.FileNameMapper;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.tools.todo.types.DirectoryScanner;
import org.apache.tools.todo.types.FileSet;
import org.apache.tools.todo.types.ScannerUtil;
import org.apache.tools.todo.types.SourceFileScanner;
import org.apache.tools.todo.util.mappers.MergingMapper;
/**
* A condition which evaluates to true when the specified target has a
* timestamp greater than all of the source files.
*
* @author William Ferguson <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @author Hiroaki Nakamura <a href="mailto:[EMAIL PROTECTED]">
* [EMAIL PROTECTED]</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*
* @ant.type type="condition" name="uptodate"
*/
public class UpToDateCondition
implements Condition
{
private final ArrayList m_fileSets = new ArrayList();
private FileNameMapper m_mapper;
private File m_targetFile;
/**
* The file which must be more up to date than each of the source files if
* the property is to be set.
*
* @param file the file which we are checking against.
*/
public void setTargetFile( final File file )
{
m_targetFile = file;
}
/**
* Nested <srcfiles> element.
*
* @param fs The feature to be added to the Srcfiles attribute
*/
public void addSrcfiles( final FileSet fs )
{
m_fileSets.add( fs );
}
/**
* Defines the FileNameMapper to use (nested mapper element).
*/
public void add( final FileNameMapper mapper )
throws TaskException
{
if( m_mapper != null )
{
throw new TaskException( "Cannot define more than one mapper" );
}
m_mapper = mapper;
}
/**
* Evaluates this condition.
*
* @param context
* The context to evaluate the condition in.
*/
public boolean evaluate( TaskContext context )
throws TaskException
{
if( m_targetFile == null && m_mapper == null )
{
throw new TaskException( "The targetfile attribute or a nested
mapper element must be set" );
}
// if not there then it can't be up to date
if( m_targetFile != null && !m_targetFile.exists() )
{
return false;
}
final Iterator enum = m_fileSets.iterator();
while( enum.hasNext() )
{
final FileSet fs = (FileSet)enum.next();
final DirectoryScanner ds = ScannerUtil.getDirectoryScanner( fs );
if ( !scanDir( fs.getDir(), ds.getIncludedFiles(), context ) )
{
return false;
}
}
return true;
}
private boolean scanDir( final File srcDir,
final String files[],
final TaskContext context )
throws TaskException
{
final SourceFileScanner scanner = new SourceFileScanner();
FileNameMapper mapper = null;
File dir = srcDir;
if( m_mapper == null )
{
final MergingMapper mm = new MergingMapper();
mm.setTo( m_targetFile.getAbsolutePath() );
mapper = mm;
dir = null;
}
else
{
mapper = m_mapper;
}
return scanner.restrict( files, srcDir, dir, mapper, context ).length
== 0;
}
}
1.8 +4 -4
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- IfTask.java 23 Mar 2002 03:46:31 -0000 1.7
+++ IfTask.java 28 Mar 2002 06:35:22 -0000 1.8
@@ -14,7 +14,7 @@
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.framework.conditions.Condition;
-import org.apache.myrmidon.framework.conditions.IsSetCondition;
+import org.apache.myrmidon.framework.conditions.IsTrueCondition;
import org.apache.myrmidon.framework.conditions.NotCondition;
/**
@@ -22,7 +22,7 @@
* then it will execute the inner tasks, else it won't.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.7 $ $Date: 2002/03/23 03:46:31 $
+ * @version $Revision: 1.8 $ $Date: 2002/03/28 06:35:22 $
* @ant.task name="if"
*/
public class IfTask
@@ -44,7 +44,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new IsSetCondition( condition );
+ m_condition = new IsTrueCondition( condition );
}
/**
@@ -57,7 +57,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new NotCondition( new IsSetCondition( condition ) );
+ m_condition = new NotCondition( new IsTrueCondition( condition ) );
}
public void add( final Configuration task )
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Equals.java
Index: Equals.java
===================================================================
package org.apache.antlib.core;
/*
* 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.
*/
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.framework.conditions.Condition;
/**
* Simple String comparison condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*
* @ant.type type="condition" name="equals"
*/
public class Equals implements Condition
{
private String arg1, arg2;
public void setArg1( String a1 )
{
arg1 = a1;
}
public void setArg2( String a2 )
{
arg2 = a2;
}
/**
* 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 )
{
throw new TaskException( "both arg1 and arg2 are required in
equals" );
}
return arg1.equals( arg2 );
}
}
1.4 +4 -0
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 2 Feb 2002 12:51:58 -0000 1.3
+++ Resources.properties 28 Mar 2002 06:35:22 -0000 1.4
@@ -4,3 +4,7 @@
import.no-lib.error=Must specify lib parameter.
import.no-deploy.error=Error importing tasklib.
+
+typeavailable.no-type-name.error=No type name was specified.
+typeavailable.unknown-role.error=Unknown role "{0}".
+typeavailable.evaluate.error=Could not determine if type "{0}" is available.
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/TypeAvailableCondition.java
Index: TypeAvailableCondition.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.runtime;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.framework.DataType;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.role.RoleManager;
import org.apache.myrmidon.interfaces.role.RoleInfo;
import org.apache.myrmidon.interfaces.type.TypeManager;
import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
/**
* A condition that evaluates to true if a particular type is available.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/03/28 06:35:22 $
*
* @ant.type type="condition" name="type-available"
*/
public class TypeAvailableCondition
implements Condition
{
private final static Resources REZ =
ResourceManager.getPackageResources( TypeAvailableCondition.class );
private String m_roleShorthand;
private String m_name;
/**
* Sets the role to search for.
*/
public void setType( final String type )
{
m_roleShorthand = type;
}
/**
* Sets the type to search for.
*/
public void setName( final String name )
{
m_name = name;
}
/**
* Evaluates this condition.
*
* @param context
* The context to evaluate the condition in.
*/
public boolean evaluate( final TaskContext context )
throws TaskException
{
if( m_name == null )
{
final String message = REZ.getString(
"typeavailable.no-type-name.error" );
throw new TaskException( message );
}
try
{
// Map the shorthand name to a role
final String roleName;
if( m_roleShorthand != null )
{
final RoleManager roleManager =
(RoleManager)context.getService( RoleManager.class );
final RoleInfo roleInfo = roleManager.getRoleByShorthandName(
m_roleShorthand );
if( roleInfo == null )
{
final String message = REZ.getString(
"typeavailable.unknown-role.error", m_roleShorthand );
throw new TaskException( message );
}
roleName = roleInfo.getName();
}
else
{
roleName = DataType.ROLE;
}
// Lookup the type
final TypeManager typeManager = (TypeManager)context.getService(
TypeManager.class );
final TypeFactory typeFactory = typeManager.getFactory( roleName
);
// Check if the type is available
return typeFactory.canCreate( m_name );
}
catch( final Exception e )
{
final String message = REZ.getString(
"typeavailable.evaluate.error", m_name );
throw new TaskException( message, e );
}
}
}
1.22 +4 -4
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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Pattern.java 23 Mar 2002 04:01:24 -0000 1.21
+++ Pattern.java 28 Mar 2002 06:35:22 -0000 1.22
@@ -12,14 +12,14 @@
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.conditions.Condition;
-import org.apache.myrmidon.framework.conditions.IsSetCondition;
+import org.apache.myrmidon.framework.conditions.IsTrueCondition;
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.21 $ $Date: 2002/03/23 04:01:24 $
+ * @version $Revision: 1.22 $ $Date: 2002/03/28 06:35:22 $
* @ant.data-type name="pattern"
*/
public class Pattern
@@ -80,7 +80,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new IsSetCondition( condition );
+ m_condition = new IsTrueCondition( condition );
}
/**
@@ -93,7 +93,7 @@
throws TaskException
{
verifyConditionNull();
- m_condition = new NotCondition( new IsSetCondition( condition ) );
+ m_condition = new NotCondition( new IsTrueCondition( condition ) );
}
public String evaluateName( final TaskContext context )
1.6 +3 -4
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java
Index: IsSetCondition.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsSetCondition.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IsSetCondition.java 23 Mar 2002 04:01:24 -0000 1.5
+++ IsSetCondition.java 28 Mar 2002 06:35:22 -0000 1.6
@@ -13,13 +13,12 @@
import org.apache.myrmidon.api.TaskException;
/**
- * A [EMAIL PROTECTED] Condition} that is true when a property is set, but
not set to
- * 'false'.
+ * A [EMAIL PROTECTED] Condition} that is true when a property is set.
*
* @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.5 $ $Date: 2002/03/23 04:01:24 $
+ * @version $Revision: 1.6 $ $Date: 2002/03/28 06:35:22 $
*
* @ant.type type="condition" name="is-set"
*/
@@ -62,6 +61,6 @@
// Resolve the condition
final Object object = context.getProperty( m_property );
- return ( object != null && !object.toString().equals( "false" ) );
+ return ( object != null );
}
}
1.5 +16 -4
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java
Index: NotCondition.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/NotCondition.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NotCondition.java 23 Mar 2002 04:01:24 -0000 1.4
+++ NotCondition.java 28 Mar 2002 06:35:22 -0000 1.5
@@ -9,19 +9,24 @@
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
+import org.apache.avalon.excalibur.i18n.ResourceManager;
+import org.apache.avalon.excalibur.i18n.Resources;
/**
* <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.4 $
+ * @version $Revision: 1.5 $
*
* @ant.type type="condition" name="not"
*/
public class NotCondition
implements Condition
{
+ private final static Resources REZ =
+ ResourceManager.getPackageResources( NotCondition.class );
+
private Condition m_condition;
public NotCondition()
@@ -34,10 +39,16 @@
}
/**
- * Sets the nested condition.
+ * Adds a nested condition.
*/
- public void set( final Condition condition )
+ public void add( final Condition condition )
+ throws TaskException
{
+ if( m_condition != null )
+ {
+ final String message = REZ.getString(
"not.too-many-conditions.error" );
+ throw new TaskException( message );
+ }
m_condition = condition;
}
@@ -49,7 +60,8 @@
{
if( m_condition == null )
{
- throw new TaskException( "no condition set" );
+ final String message = REZ.getString( "not.no-condition.error" );
+ throw new TaskException( message );
}
return ! m_condition.evaluate( context );
1.2 +3 -0
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/Resources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resources.properties 3 Mar 2002 02:19:11 -0000 1.1
+++ Resources.properties 28 Mar 2002 06:35:22 -0000 1.2
@@ -1 +1,4 @@
isset.no-property.error=No property specified to test.
+istrue.no-property.error=No property specified to test.
+not.no-condition.error=No condition specified.
+not.too-many-conditions.error=Too many conditions specified.
\ No newline at end of file
1.1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/conditions/IsTrueCondition.java
Index: IsTrueCondition.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.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException;
/**
* 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/28 06:35:22 $
*
* @ant.type type="condition" name="is-true"
*/
public class IsTrueCondition
implements Condition
{
private final static Resources REZ =
ResourceManager.getPackageResources( IsTrueCondition.class );
private String m_property;
public IsTrueCondition( final String propName )
{
m_property = propName;
}
public IsTrueCondition()
{
}
/**
* 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 property name
final Object object = context.getProperty( m_property );
if( object == null )
{
return false;
}
// Convert value to boolean
try
{
final Converter converter = (Converter)context.getService(
Converter.class );
final Boolean value = (Boolean)converter.convert( Boolean.class,
object, context );
return value.booleanValue();
}
catch( final ConverterException e )
{
throw new TaskException( e.getMessage(), e );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>