Browse Source

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


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272101 13f79535-47bb-0310-9956-ffa450edef68
master
Darrell DeBoer 23 years ago
parent
commit
ab2c4e4c2e
13 changed files with 539 additions and 147 deletions
  1. +3
    -5
      proposal/myrmidon/ant1compat.xml
  2. +15
    -6
      proposal/myrmidon/build.xml
  3. +4
    -27
      proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java
  4. +14
    -0
      proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java
  5. +1
    -1
      proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties
  6. +143
    -107
      proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ant1convert.xsl
  7. +27
    -1
      proposal/myrmidon/src/test/org/apache/antlib/core/test/IfTestCase.java
  8. +74
    -0
      proposal/myrmidon/src/test/org/apache/antlib/core/test/if.ant
  9. +103
    -0
      proposal/myrmidon/src/test/org/apache/tools/ant/test/Ant1CompatTestCase.java
  10. +52
    -0
      proposal/myrmidon/src/test/org/apache/tools/ant/test/ant-task-test.xml
  11. +22
    -0
      proposal/myrmidon/src/test/org/apache/tools/ant/test/basic-test.xml
  12. +63
    -0
      proposal/myrmidon/src/test/org/apache/tools/ant/test/if-unless-test.xml
  13. +18
    -0
      proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir/build.xml

+ 3
- 5
proposal/myrmidon/ant1compat.xml View File

@@ -5,11 +5,11 @@
<property name="manifest.dir" value="src/manifest"/> <property name="manifest.dir" value="src/manifest"/>
<property name="java.dir" value="src/java"/> <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.lib" value="${build.dir}/lib"/>
<property name="build.classes" value="${build.dir}/classes"/> <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"> <path id="project.class.path">
<pathelement location="build/classes"/> <pathelement location="build/classes"/>
@@ -20,7 +20,7 @@


<taskdef name="antlib-jar" <taskdef name="antlib-jar"
classname="org.apache.myrmidon.build.AntlibJarTask"> classname="org.apache.myrmidon.build.AntlibJarTask">
<classpath location="${custom-tasks-dir}"/>
<classpath location="${build.custom-tasks}"/>
</taskdef> </taskdef>


<target name="main" depends="antlib"/> <target name="main" depends="antlib"/>
@@ -83,8 +83,6 @@
<include name="${ant1.package}/**"/> <include name="${ant1.package}/**"/>
</fileset> </fileset>
</antlib-jar> </antlib-jar>

<copy todir="dist/lib" file="${antlib.file}"/>
</target> </target>


<!-- Runs the supplied build file through the XSL converter --> <!-- Runs the supplied build file through the XSL converter -->


+ 15
- 6
proposal/myrmidon/build.xml View File

@@ -188,10 +188,10 @@ Legal:


<!-- Compiles and installs the custom build tasks --> <!-- Compiles and installs the custom build tasks -->
<target name="custom-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"/> <classpath refid="project.class.path"/>
</javac> </javac>


@@ -200,13 +200,13 @@ Legal:
<!-- <copy file="${manifest.dir}/type.j" todir="${custom-package-dir}"/> --> <!-- <copy file="${manifest.dir}/type.j" todir="${custom-package-dir}"/> -->


<taskdef name="antlib-jar" classname="org.apache.myrmidon.build.AntlibJarTask"> <taskdef name="antlib-jar" classname="org.apache.myrmidon.build.AntlibJarTask">
<classpath location="${custom-tasks-dir}"/>
<classpath location="${build.custom-tasks}"/>
</taskdef> </taskdef>


<taskdef name="antlib-descriptor" <taskdef name="antlib-descriptor"
classname="org.apache.myrmidon.build.AntlibDescriptorTask"> classname="org.apache.myrmidon.build.AntlibDescriptorTask">
<classpath> <classpath>
<pathelement location="${custom-tasks-dir}"/>
<pathelement location="${build.custom-tasks}"/>
<path refid="project.class.path"/> <path refid="project.class.path"/>
</classpath> </classpath>
</taskdef> </taskdef>
@@ -527,6 +527,9 @@ Legal:
<ant antfile="antlib.xml"> <ant antfile="antlib.xml">
<property name="antlib.name" value="build"/> <property name="antlib.name" value="build"/>
</ant> </ant>

<!-- Create the Ant1 compatibility layer -->
<ant antfile="ant1compat.xml"/>
</target> </target>


<!-- Compiles and runs the unit tests --> <!-- Compiles and runs the unit tests -->
@@ -619,6 +622,12 @@ Legal:
<exclude name="**/BzipTestCase.class" unless="test.bzip"/> <exclude name="**/BzipTestCase.class" unless="test.bzip"/>
<exclude name="**/SmbFileSystemTestCase.class" unless="test.smb"/> <exclude name="**/SmbFileSystemTestCase.class" unless="test.smb"/>
<exclude name="**/FtpFileSystemTestCase.class" unless="test.ftp"/> <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> </fileset>
</batchtest> </batchtest>
</junit> </junit>


+ 4
- 27
proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatProject.java View File

@@ -22,10 +22,7 @@ import org.apache.aut.converter.Converter;
import org.apache.aut.converter.ConverterException; import org.apache.aut.converter.ConverterException;
import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.interfaces.property.PropertyResolver;
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; 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; import org.apache.myrmidon.interfaces.type.TypeManager;


/** /**
@@ -49,12 +46,10 @@ public class Ant1CompatProject extends Project
URL ant1jar = URL ant1jar =
Ant1CompatProject.class.getProtectionDomain().getCodeSource().getLocation(); Ant1CompatProject.class.getProtectionDomain().getCodeSource().getLocation();
String ant1classpath = ant1jar.getFile().toString(); 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 final Converter m_converter;


private Set m_userProperties = new HashSet(); private Set m_userProperties = new HashSet();
@@ -80,17 +75,6 @@ public class Ant1CompatProject extends Project
} }


m_converter = (Converter)m_context.getService( Converter.class ); 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 class Ant1CompatProject extends Project
public String replaceProperties( String value ) public String replaceProperties( String value )
throws BuildException 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() );
} }


/** /**


+ 14
- 0
proposal/myrmidon/src/java/org/apache/antlib/core/IfTask.java View File

@@ -13,6 +13,7 @@ import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.framework.AbstractContainerTask; import org.apache.myrmidon.framework.AbstractContainerTask;
import org.apache.myrmidon.framework.conditions.AndCondition;
import org.apache.myrmidon.framework.conditions.Condition; import org.apache.myrmidon.framework.conditions.Condition;
import org.apache.myrmidon.framework.conditions.IsTrueCondition; import org.apache.myrmidon.framework.conditions.IsTrueCondition;
import org.apache.myrmidon.framework.conditions.NotCondition; import org.apache.myrmidon.framework.conditions.NotCondition;
@@ -60,6 +61,19 @@ public class IfTask
m_condition = new NotCondition( new IsTrueCondition( condition ) ); 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 ) public void add( final Configuration task )
{ {
m_tasks.add( task ); m_tasks.add( task );


+ 1
- 1
proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties View File

@@ -19,7 +19,7 @@ enum.missing.getByName.error=Enum class "{0}" is missing a public static method
enum.missing.getNames.error=Enum class "{0}" is missing a public static method named "getNames" that returns a String array of all enum names. 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}. 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. 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. trycatch.multiple-trys.error=Multiple <try/> elements can not be placed inside <try-catch/> task.


+ 143
- 107
proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ant1convert.xsl View File

@@ -1,114 +1,150 @@
<?xml version="1.0"?> <?xml version="1.0"?>


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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="/project[@version]">
<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/target[@if]">
<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/target[@unless]">
<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/target[@if 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="/project[@version]">
<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/target[@if]">
<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/target[@unless]">
<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/target[@if 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: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> </xsl:stylesheet>






+ 27
- 1
proposal/myrmidon/src/test/org/apache/antlib/core/test/IfTestCase.java View File

@@ -42,7 +42,7 @@ public class IfTestCase
executeTarget( projectFile, "true-prop", listener ); executeTarget( projectFile, "true-prop", listener );


// Test when property is set to a value other than 'true' or 'false' // 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' // Test when property is set to 'false'
listener = new LogMessageTracker(); listener = new LogMessageTracker();
@@ -55,6 +55,24 @@ public class IfTestCase
executeTarget( projectFile, "not-set-prop", listener ); executeTarget( projectFile, "not-set-prop", listener );
} }


/**
* 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. * Tests that the <if> task can handle multiple nested tasks.
*/ */
@@ -92,7 +110,15 @@ public class IfTestCase
null, null,
REZ.getString( "if.ifelse-duplicate.error" ) REZ.getString( "if.ifelse-duplicate.error" )
}; };
// 2 condition attributes.
executeTargetExpectError( projectFile, "too-many-conditions", messages ); 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 );
} }


} }

+ 74
- 0
proposal/myrmidon/src/test/org/apache/antlib/core/test/if.ant View File

@@ -38,6 +38,57 @@
</if> </if>
</target> </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"> <target name="multiple-nested-tasks">
<property name="test-prop" value="true"/> <property name="test-prop" value="true"/>
<if test="test-prop"> <if test="test-prop">
@@ -60,4 +111,27 @@
</if> </if>
</target> </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>

</project> </project>

+ 103
- 0
proposal/myrmidon/src/test/org/apache/tools/ant/test/Ant1CompatTestCase.java View File

@@ -0,0 +1,103 @@
/*
* 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:darrell@apache.org">Darrell DeBoer</a>
* @version $Revision$ $Date$
*/
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" );
}

}

+ 52
- 0
proposal/myrmidon/src/test/org/apache/tools/ant/test/ant-task-test.xml View File

@@ -0,0 +1,52 @@
<project name="ant-task-test"
description="Tests for the &lt;ant&gt; 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>

+ 22
- 0
proposal/myrmidon/src/test/org/apache/tools/ant/test/basic-test.xml View File

@@ -0,0 +1,22 @@
<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>

+ 63
- 0
proposal/myrmidon/src/test/org/apache/tools/ant/test/if-unless-test.xml View File

@@ -0,0 +1,63 @@
<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>

+ 18
- 0
proposal/myrmidon/src/test/org/apache/tools/ant/test/subdir/build.xml View File

@@ -0,0 +1,18 @@
<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>

Loading…
Cancel
Save