darrell 02/03/29 17:19:18
Modified: proposal/myrmidon ant1compat.xml build.xml
proposal/myrmidon/src/ant1compat/org/apache/tools/ant
Ant1CompatProject.java
proposal/myrmidon/src/java/org/apache/antlib/core
IfTask.java Resources.properties
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder
ant1convert.xsl
proposal/myrmidon/src/test/org/apache/antlib/core/test
IfTestCase.java if.ant
Added: proposal/myrmidon/src/test/org/apache/tools/ant/test
Ant1CompatTestCase.java ant-task-test.xml
basic-test.xml if-unless-test.xml
proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir
build.xml
Log:
* Added nested <condition> element to IfTask, to allow any arbitrary condition
to be used in <if>. Tests updated for new functionality.
* Ant1 conversion stylesheet uses nested <is-set> condition on <if>,
to replicate Ant1 behaviour of 'if=' and 'unless=' on targets.
* ant1compat antlib generated as part of standard build.
* Minor build cleanup: ${custom-tasks-dir} -> ${build.custom-tasks} for
consistency.
* Ant1CompatProject now uses ProjectHelper for property resolution, rather
than
trying to duplicate Ant1 behaviour.
* Added tests for Ant1 Compatibility layer. These have been exclude from
regular
build, as they fail when run under Ant1.4.1, because the JUnit task *always*
places ant.jar *first* in the JUnit classpath. Tests work under Ant1.5alpha,
since it adds ant.jar *last* by default. (Tests also function correctly by
invoking JUnit directly - or with Intellij JUnit integration).
Revision Changes Path
1.5 +3 -5 jakarta-ant/proposal/myrmidon/ant1compat.xml
Index: ant1compat.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/ant1compat.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ant1compat.xml 28 Mar 2002 07:30:41 -0000 1.4
+++ ant1compat.xml 30 Mar 2002 01:19:17 -0000 1.5
@@ -5,11 +5,11 @@
<property name="manifest.dir" value="src/manifest"/>
<property name="java.dir" value="src/java"/>
- <property name="build.dir" value="build/ant1compat"/>
+ <property name="build.dir" value="build"/>
<property name="build.lib" value="${build.dir}/lib"/>
<property name="build.classes" value="${build.dir}/classes"/>
- <property name="custom-tasks-dir" value="build/tasks"/>
+ <property name="build.custom-tasks" value="build/tasks"/>
<path id="project.class.path">
<pathelement location="build/classes"/>
@@ -20,7 +20,7 @@
<taskdef name="antlib-jar"
classname="org.apache.myrmidon.build.AntlibJarTask">
- <classpath location="${custom-tasks-dir}"/>
+ <classpath location="${build.custom-tasks}"/>
</taskdef>
<target name="main" depends="antlib"/>
@@ -83,8 +83,6 @@
<include name="${ant1.package}/**"/>
</fileset>
</antlib-jar>
-
- <copy todir="dist/lib" file="${antlib.file}"/>
</target>
<!-- Runs the supplied build file through the XSL converter -->
1.95 +15 -6 jakarta-ant/proposal/myrmidon/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- build.xml 29 Mar 2002 13:09:41 -0000 1.94
+++ build.xml 30 Mar 2002 01:19:17 -0000 1.95
@@ -188,10 +188,10 @@
<!-- Compiles and installs the custom build tasks -->
<target name="custom-tasks">
- <property name="custom-tasks-dir" value="${build.dir}/tasks"/>
- <property name="custom-package-dir"
value="${custom-tasks-dir}/org/apache/myrmidon/build"/>
- <mkdir dir="${custom-tasks-dir}"/>
- <javac srcdir="src/make" destdir="${custom-tasks-dir}">
+ <property name="build.custom-tasks" value="${build.dir}/tasks"/>
+ <property name="custom-package-dir"
value="${build.custom-tasks}/org/apache/myrmidon/build"/>
+ <mkdir dir="${build.custom-tasks}"/>
+ <javac srcdir="src/make" destdir="${build.custom-tasks}">
<classpath refid="project.class.path"/>
</javac>
@@ -200,13 +200,13 @@
<!-- <copy file="${manifest.dir}/type.j"
todir="${custom-package-dir}"/> -->
<taskdef name="antlib-jar"
classname="org.apache.myrmidon.build.AntlibJarTask">
- <classpath location="${custom-tasks-dir}"/>
+ <classpath location="${build.custom-tasks}"/>
</taskdef>
<taskdef name="antlib-descriptor"
classname="org.apache.myrmidon.build.AntlibDescriptorTask">
<classpath>
- <pathelement location="${custom-tasks-dir}"/>
+ <pathelement location="${build.custom-tasks}"/>
<path refid="project.class.path"/>
</classpath>
</taskdef>
@@ -527,6 +527,9 @@
<ant antfile="antlib.xml">
<property name="antlib.name" value="build"/>
</ant>
+
+ <!-- Create the Ant1 compatibility layer -->
+ <ant antfile="ant1compat.xml"/>
</target>
<!-- Compiles and runs the unit tests -->
@@ -619,6 +622,12 @@
<exclude name="**/BzipTestCase.class"
unless="test.bzip"/>
<exclude name="**/SmbFileSystemTestCase.class"
unless="test.smb"/>
<exclude name="**/FtpFileSystemTestCase.class"
unless="test.ftp"/>
+
+ <!-- Need Ant1.5+ to run Ant1Compat tests, because of
fixes to JUnit -->
+ <exclude name="**/Ant1CompatTestCase.class"
unless="single.test"/>
+
+ <!-- This test fails, as it has no test methods -->
+ <exclude name="**/SimpleConvertersTestCase.class"
unless="single.test"/>
</fileset>
</batchtest>
</junit>
1.9 +5 -28
jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java
Index: Ant1CompatProject.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Ant1CompatProject.java 28 Mar 2002 11:56:44 -0000 1.8
+++ Ant1CompatProject.java 30 Mar 2002 01:19:17 -0000 1.9
@@ -22,10 +22,7 @@
import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException;
-import org.apache.myrmidon.interfaces.property.PropertyResolver;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
-import org.apache.myrmidon.interfaces.type.TypeException;
-import org.apache.myrmidon.interfaces.type.TypeFactory;
import org.apache.myrmidon.interfaces.type.TypeManager;
/**
@@ -36,7 +33,7 @@
* Ant1 original, this class contains the extensions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
- * @version $Revision: 1.8 $ $Date: 2002/03/28 11:56:44 $
+ * @version $Revision: 1.9 $ $Date: 2002/03/30 01:19:17 $
*/
public class Ant1CompatProject extends Project
{
@@ -49,12 +46,10 @@
URL ant1jar =
Ant1CompatProject.class.getProtectionDomain().getCodeSource().getLocation();
String ant1classpath = ant1jar.getFile().toString();
- javaclasspath = System.getProperty( "java.class.path" ) +
- File.pathSeparator +
- ant1classpath;
+ javaclasspath = System.getProperty( "java.class.path" );
+ javaclasspath = javaclasspath + File.pathSeparator + ant1classpath;
}
- private final PropertyResolver m_ant1PropertyResolver;
private final Converter m_converter;
private Set m_userProperties = new HashSet();
@@ -80,17 +75,6 @@
}
m_converter = (Converter)m_context.getService( Converter.class );
-
- TypeManager typeManager = (TypeManager)m_context.getService(
TypeManager.class );
- try
- {
- TypeFactory factory = typeManager.getFactory(
PropertyResolver.ROLE );
- m_ant1PropertyResolver = (PropertyResolver)factory.create(
"classic" );
- }
- catch( TypeException e )
- {
- throw new TaskException( "Failed to create PropertyResolver.", e
);
- }
}
/**
@@ -519,15 +503,8 @@
public String replaceProperties( String value )
throws BuildException
{
- try
- {
- return (String)m_ant1PropertyResolver.resolveProperties( value,
-
m_context );
- }
- catch( TaskException e )
- {
- throw new BuildException( "Error resolving value: '" + value +
"'", e );
- }
+ return ProjectHelper.replaceProperties( this, value,
+ this.getProperties() );
}
/**
1.10 +15 -1
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- IfTask.java 29 Mar 2002 12:57:20 -0000 1.9
+++ IfTask.java 30 Mar 2002 01:19:17 -0000 1.10
@@ -13,6 +13,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.AbstractContainerTask;
+import org.apache.myrmidon.framework.conditions.AndCondition;
import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.framework.conditions.IsTrueCondition;
import org.apache.myrmidon.framework.conditions.NotCondition;
@@ -22,7 +23,7 @@
* then it will execute the inner tasks, else it won't.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.9 $ $Date: 2002/03/29 12:57:20 $
+ * @version $Revision: 1.10 $ $Date: 2002/03/30 01:19:17 $
* @ant.task name="if"
*/
public class IfTask
@@ -58,6 +59,19 @@
{
verifyConditionNull();
m_condition = new NotCondition( new IsTrueCondition( condition ) );
+ }
+
+ /**
+ * Add a nested "condition" element, which provides an AndCondition
+ * container for any type of condition.
+ * @param andCondition The configured Condition
+ * @throws TaskException If a condition has already been set.
+ */
+ public void addCondition( final AndCondition andCondition )
+ throws TaskException
+ {
+ verifyConditionNull();
+ m_condition = andCondition;
}
public void add( final Configuration task )
1.12 +1 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Resources.properties 28 Mar 2002 07:30:41 -0000 1.11
+++ Resources.properties 30 Mar 2002 01:19:17 -0000 1.12
@@ -19,7 +19,7 @@
enum.missing.getNames.error=Enum class "{0}" is missing a public static
method named "getNames" that returns a String array of all enum names.
invalid.enum.error=Invalid value "{0}" for enum, expected one of {1}.
-if.ifelse-duplicate.error=Can only set one of if/else for If task type.
+if.ifelse-duplicate.error=Can only set one condition for If task type.
Conditions may be 'test' or 'not-test' attributes, or nested 'condition'
elements.
if.no-condition.error=No condition was specified for If task.
trycatch.multiple-trys.error=Multiple <try/> elements can not be placed
inside <try-catch/> task.
1.2 +143 -107
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ant1convert.xsl
Index: ant1convert.xsl
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ant1convert.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ant1convert.xsl 18 Mar 2002 02:33:43 -0000 1.1
+++ ant1convert.xsl 30 Mar 2002 01:19:17 -0000 1.2
@@ -1,114 +1,150 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
- <xsl:output method="xml" indent="yes"/>
-
- <xsl:template match="/project">
- <xsl:comment>Converted Project file.</xsl:comment>
- <xsl:copy>
- <xsl:attribute name="version">2.0</xsl:attribute>
- <xsl:apply-templates select="@*[name() != 'version']" mode="copy"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
-
- <!-- For projects with a version attribute, simply copy the entire tree.
-->
- <!-- TODO check for version >= 2.0.0 -->
- <xsl:template match="/[EMAIL PROTECTED]">
- <xsl:comment>Copied Project file.</xsl:comment>
- <xsl:copy>
- <xsl:apply-templates select="@*"/>
- <xsl:apply-templates mode="copy"/>
- </xsl:copy>
- </xsl:template>
-
- <!-- Handle simple target nodes -->
- <xsl:template match="/project/target">
- <xsl:copy>
- <xsl:apply-templates select="@*"/>
- <xsl:apply-templates/>
- </xsl:copy>
- </xsl:template>
-
- <!-- Handle target nodes with 'if' -->
- <xsl:template match="/project/[EMAIL PROTECTED]">
- <xsl:copy>
- <xsl:apply-templates select="@*[name() != 'if']"/>
-
- <!-- Put in the condition -->
- <xsl:element name="if">
- <xsl:attribute name="test"><xsl:value-of
select="@if"/></xsl:attribute>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:copy>
- </xsl:template>
-
- <!-- Handle target nodes with 'unless' -->
- <xsl:template match="/project/[EMAIL PROTECTED]">
- <xsl:copy>
- <xsl:apply-templates select="@*[name() != 'unless']"/>
-
- <!-- Put in the condition -->
- <xsl:element name="if">
- <xsl:attribute name="not-test">
- <xsl:value-of select="@unless"/>
- </xsl:attribute>
- <xsl:apply-templates/>
- </xsl:element>
- </xsl:copy>
- </xsl:template>
-
- <!-- Handle target nodes with 'if' and 'unless' -->
- <xsl:template match="/project/[EMAIL PROTECTED] and @unless]">
- <xsl:copy>
- <xsl:apply-templates select="@*[name()!='if' and name()!='unless']"/>
-
- <!-- Put in the 'if' condition -->
- <xsl:element name="if">
- <xsl:attribute name="test"><xsl:value-of
select="@if"/></xsl:attribute>
- <!-- Put in the 'unless' condition -->
- <xsl:element name="if">
- <xsl:attribute name="not-test"><xsl:value-of
select="@unless"/></xsl:attribute>
- <xsl:apply-templates/>
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:template match="/project">
+ <xsl:comment>Converted Project file.</xsl:comment>
+ <xsl:copy>
+ <xsl:attribute name="version">2.0</xsl:attribute>
+ <xsl:apply-templates select="@*[name() != 'version']"
mode="copy"/>
+ <xsl:apply-templates/>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- For projects with a version attribute, simply copy the entire tree.
-->
+ <!-- TODO check for version >= 2.0.0 -->
+ <xsl:template match="/[EMAIL PROTECTED]">
+ <xsl:comment>Copied Project file.</xsl:comment>
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsl:apply-templates mode="copy"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- Handle simple target nodes -->
+ <xsl:template match="/project/target">
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsl:apply-templates/>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- Handle target nodes with 'if' -->
+ <xsl:template match="/project/[EMAIL PROTECTED]">
+ <xsl:copy>
+ <xsl:apply-templates select="@*[name() != 'if']"/>
+
+ <!-- Put in the if condition -->
+ <xsl:element name="if">
+ <xsl:element name="condition">
+ <xsl:element name="is-set">
+ <xsl:attribute name="property">
+ <xsl:value-of select="@if"/>
+ </xsl:attribute>
+ </xsl:element>
+ </xsl:element>
+
+ <!-- Now add the target content -->
+ <xsl:apply-templates/>
+
+ </xsl:element>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- Handle target nodes with 'unless' -->
+ <xsl:template match="/project/[EMAIL PROTECTED]">
+ <xsl:copy>
+ <xsl:apply-templates select="@*[name() != 'unless']"/>
+
+ <!-- Put in the unless condition -->
+ <xsl:element name="if">
+ <xsl:element name="condition">
+ <xsl:element name="not">
+ <xsl:element name="is-set">
+ <xsl:attribute name="property">
+ <xsl:value-of select="@unless"/>
+ </xsl:attribute>
+ </xsl:element>
+ </xsl:element>
+ </xsl:element>
+
+ <!-- Now add the target content -->
+ <xsl:apply-templates/>
+
+ </xsl:element>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- Handle target nodes with 'if' and 'unless' -->
+ <xsl:template match="/project/[EMAIL PROTECTED] and @unless]">
+ <xsl:copy>
+ <xsl:apply-templates select="@*[name()!='if' and
name()!='unless']"/>
+
+ <!-- Put in the 'if' condition -->
+ <xsl:element name="if">
+ <xsl:element name="condition">
+ <xsl:element name="is-set">
+ <xsl:attribute name="property">
+ <xsl:value-of select="@if"/>
+ </xsl:attribute>
+ </xsl:element>
+ </xsl:element>
+
+ <!-- Put in the 'unless' condition -->
+ <xsl:element name="if">
+ <xsl:element name="condition">
+ <xsl:element name="not">
+ <xsl:element name="is-set">
+ <xsl:attribute name="property">
+ <xsl:value-of select="@unless"/>
+ </xsl:attribute>
+ </xsl:element>
+ </xsl:element>
+ </xsl:element>
+
+ <!-- Now add the target content -->
+ <xsl:apply-templates/>
+
+ </xsl:element>
+ </xsl:element>
+ </xsl:copy>
+ </xsl:template>
+
+
+ <!-- Handle task nodes, prepending "ant1." -->
+ <xsl:template match="*">
+ <xsl:element name="ant1.{name()}">
+ <xsl:apply-templates select="@*"/>
+ <xsl:apply-templates mode="copy"/>
</xsl:element>
- </xsl:element>
- </xsl:copy>
- </xsl:template>
-
-
- <!-- Handle task nodes -->
- <xsl:template match="*">
- <xsl:element name="ant1.{name()}">
- <xsl:apply-templates select="@*"/>
- <xsl:apply-templates mode="copy"/>
- </xsl:element>
- </xsl:template>
-
- <!-- Copy all elements in copy-mode -->
- <xsl:template match="*" mode="copy">
- <xsl:copy>
- <xsl:apply-templates select="@*"/>
- <xsl:apply-templates mode="copy"/>
- </xsl:copy>
- </xsl:template>
-
- <!-- Always copy attributes -->
- <xsl:template match="@*">
- <xsl:copy/>
- </xsl:template>
-
- <xsl:template match="@*" mode="copy">
- <xsl:copy/>
- </xsl:template>
-
- <!-- Always copy comments -->
- <xsl:template match="comment()">
- <xsl:copy/>
- </xsl:template>
-
- <xsl:template match="comment()" mode="copy">
- <xsl:copy/>
- </xsl:template>
+ </xsl:template>
+
+ <!-- Copy all elements in copy-mode -->
+ <xsl:template match="*" mode="copy">
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsl:apply-templates mode="copy"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <!-- Always copy attributes -->
+ <xsl:template match="@*">
+ <xsl:copy/>
+ </xsl:template>
+
+ <xsl:template match="@*" mode="copy">
+ <xsl:copy/>
+ </xsl:template>
+
+ <!-- Always copy comments -->
+ <xsl:template match="comment()">
+ <xsl:copy/>
+ </xsl:template>
+
+ <xsl:template match="comment()" mode="copy">
+ <xsl:copy/>
+ </xsl:template>
</xsl:stylesheet>
1.3 +28 -2
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IfTestCase.java 28 Mar 2002 06:35:21 -0000 1.2
+++ IfTestCase.java 30 Mar 2002 01:19:17 -0000 1.3
@@ -16,7 +16,7 @@
* Test cases for the <if> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
- * @version $Revision: 1.2 $ $Date: 2002/03/28 06:35:21 $
+ * @version $Revision: 1.3 $ $Date: 2002/03/30 01:19:17 $
*/
public class IfTestCase
extends AbstractProjectTest
@@ -42,7 +42,7 @@
executeTarget( projectFile, "true-prop", listener );
// Test when property is set to a value other than 'true' or 'false'
- executeTargetExpectError( projectFile, "set-prop", new String[0] );
+ executeTargetExpectError( projectFile, "set-prop", new String[ 0 ] );
// Test when property is set to 'false'
listener = new LogMessageTracker();
@@ -56,6 +56,24 @@
}
/**
+ * Test nested <condition> elements.
+ */
+ public void testNestedConditions()
+ throws Exception
+ {
+ final File projectFile = getTestResource( "if.ant" );
+
+ // Test when property is set to 'true'
+ LogMessageTracker listener = new LogMessageTracker();
+ listener.addExpectedMessage( "nested-conditions", "prop-true is set"
);
+ listener.addExpectedMessage( "nested-conditions", "prop-false is
set" );
+ listener.addExpectedMessage( "nested-conditions", "prop-true is
true" );
+ listener.addExpectedMessage( "nested-conditions",
+ "prop-true is true and prop-false is
not true" );
+ executeTarget( projectFile, "nested-conditions", listener );
+ }
+
+ /**
* Tests that the <if> task can handle multiple nested tasks.
*/
public void testMultipleTasks() throws Exception
@@ -92,7 +110,15 @@
null,
REZ.getString( "if.ifelse-duplicate.error" )
};
+ // 2 condition attributes.
executeTargetExpectError( projectFile, "too-many-conditions",
messages );
+
+ // attribute condition + nested condition
+ executeTargetExpectError( projectFile,
"attribute-plus-nested-condition",
+ messages );
+
+ // 2 nested conditions
+ executeTargetExpectError( projectFile, "2-nested-conditions",
messages );
}
}
1.2 +74 -0
jakarta-ant/proposal/myrmidon/src/test/org/apache/antlib/core/test/if.ant
Index: if.ant
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/antlib/core/test/if.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- if.ant 17 Mar 2002 08:06:37 -0000 1.1
+++ if.ant 30 Mar 2002 01:19:17 -0000 1.2
@@ -38,6 +38,57 @@
</if>
</target>
+ <target name="nested-conditions">
+ <property name="prop-true" value="true"/>
+ <property name="prop-false" value="false"/>
+
+ <if>
+ <condition>
+ <is-set property="prop-true"/>
+ </condition>
+ <log message="prop-true is set"/>
+ </if>
+
+ <if>
+ <condition>
+ <is-set property="prop-false"/>
+ </condition>
+ <log message="prop-false is set"/>
+ </if>
+
+ <if>
+ <condition>
+ <is-set property="prop-unset"/>
+ </condition>
+ <log message="prop-unset is set (shouldn't be here)"/>
+ </if>
+
+ <if>
+ <condition>
+ <is-true property="prop-true"/>
+ </condition>
+ <log message="prop-true is true"/>
+ </if>
+
+ <if>
+ <condition>
+ <is-true property="prop-false"/>
+ </condition>
+ <log message="prop-false is true (shouldn't be here)"/>
+ </if>
+
+ <!-- Compound condition -->
+ <if>
+ <condition>
+ <is-true property="prop-true"/>
+ <not>
+ <is-true property="prop-false"/>
+ </not>
+ </condition>
+ <log message="prop-true is true and prop-false is not true"/>
+ </if>
+ </target>
+
<target name="multiple-nested-tasks">
<property name="test-prop" value="true"/>
<if test="test-prop">
@@ -57,6 +108,29 @@
<target name="too-many-conditions">
<if test="test-prop" not-test="test-prop">
<log>no go</log>
+ </if>
+ </target>
+
+ <target name="attribute-plus-nested-condition">
+ <property name="test-prop" value="true"/>
+ <if test="test-prop">
+ <condition>
+ <is-set property="test-prop"/>
+ </condition>
+ <log>Double trouble.</log>
+ </if>
+ </target>
+
+ <target name="2-nested-conditions">
+ <property name="test-prop" value="true"/>
+ <if>
+ <condition>
+ <is-set property="test-prop"/>
+ </condition>
+ <condition>
+ <is-true property="test-prop"/>
+ </condition>
+ <log>2 conditions not permitted.</log>
</if>
</target>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/tools/ant/test/Ant1CompatTestCase.java
Index: Ant1CompatTestCase.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.tools.ant.test;
import java.io.File;
import org.apache.myrmidon.AbstractProjectTest;
import org.apache.myrmidon.LogMessageTracker;
/**
* Simple tests for the Ant1 Compatibility layer.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
* @version $Revision: 1.1 $ $Date: 2002/03/30 01:19:17 $
*/
public class Ant1CompatTestCase
extends AbstractProjectTest
{
public Ant1CompatTestCase( final String name )
{
super( name );
}
public void testBasic() throws Exception
{
final File projectFile = getTestResource( "basic-test.xml" );
// <echo> test
LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "echo-test", "Hello, hello, hello" );
executeTarget( projectFile, "echo-test", tracker );
// Property resolution tests
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "property-test", "prop-1 = [value-1]" );
tracker.addExpectedMessage( "property-test", "prop-2 = [value-2]" );
tracker.addExpectedMessage( "property-test", "prop-undefined =
[${prop-undefined}]" );
tracker.addExpectedMessage( "property-test", "Omit, replace$, but
keep ${} and $" );
executeTarget( projectFile, "property-test", tracker );
}
public void testIfUnless() throws Exception
{
final File projectFile = getTestResource( "if-unless-test.xml" );
// if/unless tests.
LogMessageTracker tracker = new LogMessageTracker();
// Should pass if for "set", "true" and "false"
tracker.addExpectedMessage( "if-set-test", "Ran target: if-set-test"
);
tracker.addExpectedMessage( "if-true-test", "Ran target:
if-true-test" );
tracker.addExpectedMessage( "if-false-test", "Ran target:
if-false-test" );
// Should only pass unless, when not defined.
tracker.addExpectedMessage( "unless-unset-test",
"Ran target: unless-unset-test" );
// If combined with unless on a single target.
tracker.addExpectedMessage( "if-with-unless-test-1",
"Ran target: if-with-unless-test-1" );
executeTarget( projectFile, "if-unless-tests", tracker );
}
public void testAntTask() throws Exception
{
final File projectFile = getTestResource( "ant-task-test.xml" );
// TODO - Get the <ant> project listeners working, so we can test log
messages.
LogMessageTracker tracker = new LogMessageTracker();
tracker.addExpectedMessage( "default-target", "In default target." );
tracker.addExpectedMessage( "echo-test", "Hello, hello, hello" );
// executeTarget( projectFile, "ant-samefile-test", tracker );
executeTarget( projectFile, "ant-samefile-test" );
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default
target)" );
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default
target)" );
tracker.addExpectedMessage( "main",
"Executed subdir/build.xml (default
target)" );
tracker.addExpectedMessage( "echo",
"Executed subdir/build.xml (echo target)"
);
// executeTarget( projectFile, "ant-otherfile-test", tracker );
executeTarget( projectFile, "ant-otherfile-test" );
tracker = new LogMessageTracker();
tracker.addExpectedMessage( "property-test",
"test-prop = [test-value]" );
tracker.addExpectedMessage( "property-test",
"test-prop = [set in calling task]" );
tracker.addExpectedMessage( "property-test",
"test-prop = [set in calling target]" );
// executeTarget( projectFile, "ant-setprops-test", tracker );
executeTarget( projectFile, "ant-setprops-test" );
}
}
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/tools/ant/test/ant-task-test.xml
Index: ant-task-test.xml
===================================================================
<project name="ant-task-test"
description="Tests for the <ant> task in the Ant1
Compatibility layer."
default="default-target">
<target name="default-target">
<echo message="In default target."/>
</target>
<target name="echo-test">
<echo message="Hello, hello, hello"/>
</target>
<!-- Test <ant> on this build file. -->
<target name="ant-samefile-test">
<!-- Default target -->
<ant antfile="ant-task-test.xml"/>
<!-- Named target -->
<ant antfile="ant-task-test.xml" target="echo-test"/>
</target>
<!-- Test <ant> on another build file. -->
<target name="ant-otherfile-test">
<!-- Full path to file. -->
<ant antfile="subdir/build.xml"/>
<!-- Dir and file specified -->
<ant dir="subdir" antfile="build.xml"/>
<!-- Dir with default filename -->
<ant dir="subdir"/>
<!-- Call named target -->
<ant antfile="subdir/build.xml" target="echo"/>
</target>
<!-- Test <ant> with property overrides -->
<target name="ant-setprops-test">
<!-- No property overrides -->
<ant antfile="subdir/build.xml" target="property-test"/>
<!-- Override property within task def -->
<ant antfile="subdir/build.xml" target="property-test">
<property name="test-prop" value="set in calling task"/>
</ant>
<!-- Override property in containing project -->
<property name="test-prop" value="set in calling target"/>
<ant antfile="subdir/build.xml" target="property-test"/>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/tools/ant/test/basic-test.xml
Index: basic-test.xml
===================================================================
<project name="ant1compat-test"
description="Basic tests for the Ant1 Compatibility layer."
default="echo-test">
<property name="prop-1" value="value-1"/>
<target name="main" depends="echo-test, property-test"/>
<target name="echo-test">
<echo message="Hello, hello, hello"/>
</target>
<target name="property-test">
<property name="prop-2" value="value-2"/>
<echo message="prop-1 = [${prop-1}]"/>
<echo message="prop-2 = [${prop-2}]"/>
<echo message="prop-undefined = [${prop-undefined}]"/>
<echo message="Omit$, replace$$, but keep ${} and $"/>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/tools/ant/test/if-unless-test.xml
Index: if-unless-test.xml
===================================================================
<project name="if-unless-test"
description="Tests for if/unless functionality of the Ant1
Compatibility layer."
default="if-unless-tests">
<target name="if-unless-tests"
depends="setup-props,
if-set-test, if-unset-test,
if-true-test, if-false-test,
unless-set-test, unless-unset-test,
unless-true-test, unless-false-test,
if-with-unless-test-1, if-with-unless-test-2,
if-with-unless-test-3"/>
<target name="setup-props">
<property name="prop-set" value="set"/>
<property name="prop-true" value="true"/>
<property name="prop-false" value="false"/>
</target>
<target name="if-set-test" if="prop-set">
<echo message="Ran target: if-set-test"/>
</target>
<target name="if-unset-test" if="prop-unset">
<echo message="Ran target: if-unset-test"/>
</target>
<target name="if-true-test" if="prop-true">
<echo message="Ran target: if-true-test"/>
</target>
<target name="if-false-test" if="prop-false">
<echo message="Ran target: if-false-test"/>
</target>
<target name="unless-set-test" unless="prop-set">
<echo message="Ran target: unless-set-test"/>
</target>
<target name="unless-unset-test" unless="prop-unset">
<echo message="Ran target: unless-unset-test"/>
</target>
<target name="unless-true-test" unless="prop-true">
<echo message="Ran target: unless-true-test"/>
</target>
<target name="unless-false-test" unless="prop-false">
<echo message="Ran target: unless-false-test"/>
</target>
<target name="if-with-unless-test-1" if="prop-set" unless="prop-unset">
<echo message="Ran target: if-with-unless-test-1"/>
</target>
<target name="if-with-unless-test-2" if="prop-unset" unless="prop-unset">
<echo message="Ran target: if-with-unless-test-2"/>
</target>
<target name="if-with-unless-test-3" if="prop-set" unless="prop-set">
<echo message="Ran target: if-with-unless-test-3"/>
</target>
</project>
1.1
jakarta-ant/proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir/build.xml
Index: build.xml
===================================================================
<project name="call-target"
description="Simple build for testing ant and antcall tasks."
default="main">
<property name="test-prop" value="test-value"/>
<target name="main">
<echo message="Executed subdir/build.xml (default target)"/>
</target>
<target name="echo">
<echo message="Executed subdir/build.xml (echo target)"/>
</target>
<target name="property-test">
<echo message="test-prop = [${test-prop}]"/>
</target>
</project>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>