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-ffa450edef68master
@@ -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 --> | |||
@@ -188,10 +188,10 @@ Legal: | |||
<!-- 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 @@ Legal: | |||
<!-- <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 @@ Legal: | |||
<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 @@ Legal: | |||
<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> | |||
@@ -22,10 +22,7 @@ import org.apache.aut.converter.Converter; | |||
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; | |||
/** | |||
@@ -49,12 +46,10 @@ public class Ant1CompatProject extends Project | |||
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 @@ public class Ant1CompatProject extends Project | |||
} | |||
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 ) | |||
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() ); | |||
} | |||
/** | |||
@@ -13,6 +13,7 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
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; | |||
@@ -60,6 +61,19 @@ public class IfTask | |||
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 ) | |||
{ | |||
m_tasks.add( task ); | |||
@@ -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. | |||
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,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="/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: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> | |||
@@ -42,7 +42,7 @@ public class IfTestCase | |||
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(); | |||
@@ -55,6 +55,24 @@ public class IfTestCase | |||
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. | |||
*/ | |||
@@ -92,7 +110,15 @@ public class IfTestCase | |||
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 ); | |||
} | |||
} |
@@ -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"> | |||
@@ -60,4 +111,27 @@ | |||
</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> | |||
</project> |
@@ -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" ); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
<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> |
@@ -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> |
@@ -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> |
@@ -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> |