Submitted by: Larry Shatzer git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277037 13f79535-47bb-0310-9956-ffa450edef68master
@@ -213,9 +213,9 @@ how to generate a HTML report from the XML report.</p> | |||||
<revision>1.3</revision> | <revision>1.3</revision> | ||||
<prevrevision>1.2</prevrevision> | <prevrevision>1.2</prevrevision> | ||||
</file> | </file> | ||||
<msg><![CDATA[Use URLs directly rather than go via a FIle. | |||||
<msg><![CDATA[Use URLs directly rather than go via a File. | |||||
This allows temp[lates to be stored inside jar]]></msg> | |||||
This allows templates to be stored inside jar]]></msg> | |||||
</entry> | </entry> | ||||
</changelog> | </changelog> | ||||
</pre> | </pre> | ||||
@@ -147,8 +147,8 @@ permissions.</p> | |||||
</blockquote> | </blockquote> | ||||
<p>keeps non-owners from touching cgi scripts, files with a <code>.old</code> | <p>keeps non-owners from touching cgi scripts, files with a <code>.old</code> | ||||
extension or directories begining with <code>private_</code>. A directory | |||||
ending in <code>.old</code> or a file begining with private_ would remain | |||||
extension or directories beginning with <code>private_</code>. A directory | |||||
ending in <code>.old</code> or a file beginning with private_ would remain | |||||
unaffected.</p> | unaffected.</p> | ||||
<hr> | <hr> | ||||
@@ -648,34 +648,34 @@ This graphic shows the dependencies: | |||||
<TABLE> | <TABLE> | ||||
<TR> | <TR> | ||||
<TD bgcolor="#C0C0C0"> </TD> | <TD bgcolor="#C0C0C0"> </TD> | ||||
<TD><PRE><filterchain> | |||||
<TD><PRE><filterchain> | |||||
<headfilter lines="2"/> | <headfilter lines="2"/> | ||||
</filterchain></PRE></TD> | |||||
</filterchain></PRE></TD> | |||||
</TR> | </TR> | ||||
<TR> | <TR> | ||||
<TD bgcolor="#FF00FF"> </TD> | <TD bgcolor="#FF00FF"> </TD> | ||||
<TD><PRE><filterchain> | |||||
<TD><PRE><filterchain> | |||||
<tailfilter lines="-1" skip="2"/> | <tailfilter lines="-1" skip="2"/> | ||||
</filterchain></PRE></TD> | |||||
</filterchain></PRE></TD> | |||||
</TR> | </TR> | ||||
<TR> | <TR> | ||||
<TD bgcolor="#008000"> </TD> | <TD bgcolor="#008000"> </TD> | ||||
<TD><PRE><filterchain> | |||||
<TD><PRE><filterchain> | |||||
<headfilter lines="-1" skip="2"/> | <headfilter lines="-1" skip="2"/> | ||||
</filterchain></PRE></TD> | |||||
</filterchain></PRE></TD> | |||||
</TR> | </TR> | ||||
<TR> | <TR> | ||||
<TD bgcolor="#0000FF"> </TD> | <TD bgcolor="#0000FF"> </TD> | ||||
<TD><PRE><filterchain> | |||||
<headfilter lines="-1" skip="2"/> | |||||
<tailfilter lines="-1" skip="2"/> | |||||
</filterchain></PRE></TD> | |||||
<TD><PRE><filterchain> | |||||
<headfilter lines="-1" skip="2"/> | |||||
<tailfilter lines="-1" skip="2"/> | |||||
</filterchain></PRE></TD> | |||||
</TR> | </TR> | ||||
<TR> | <TR> | ||||
<TD bgcolor="#00FF00"> </TD> | <TD bgcolor="#00FF00"> </TD> | ||||
<TD><PRE><filterchain> | |||||
<TD><PRE><filterchain> | |||||
<tailfilter lines="2"/> | <tailfilter lines="2"/> | ||||
</filterchain></PRE></TD> | |||||
</filterchain></PRE></TD> | |||||
</TR> | </TR> | ||||
</TABLE> | </TABLE> | ||||
</TD> | </TD> | ||||
@@ -201,9 +201,9 @@ public class MySelectorTest extends BaseSelectorTest { | |||||
As an example of an error JUnit could log<pre> | As an example of an error JUnit could log<pre> | ||||
[junit] FAILED | [junit] FAILED | ||||
[junit] Error for files: <font color=blue>.;copy.filterset.filtered;tar/gz/asf-logo.gif.tar.gz</font> | [junit] Error for files: <font color=blue>.;copy.filterset.filtered;tar/gz/asf-logo.gif.tar.gz</font> | ||||
[junit] expected:<<font color=blue>FTTTFTTTF...</font>> but was:<TTTTTTTTT...> | |||||
[junit] expected:<<font color=blue>FTTTFTTTF...</font>> but was:<TTTTTTTTT...> | |||||
[junit] junit.framework.ComparisonFailure: Error for files: .;copy.filterset.filtered;tar/gz/asf-logo.gif.tar.gz | [junit] junit.framework.ComparisonFailure: Error for files: .;copy.filterset.filtered;tar/gz/asf-logo.gif.tar.gz | ||||
[junit] expected:<FTTTFTTTF...> but was:<TTTTTTTTT...> | |||||
[junit] expected:<FTTTFTTTF...> but was:<TTTTTTTTT...> | |||||
[junit] at junit.framework.Assert.assertEquals(Assert.java:81) | [junit] at junit.framework.Assert.assertEquals(Assert.java:81) | ||||
[junit] at org.apache.tools.ant.types.selectors.BaseSelectorTest.performTest(BaseSelectorTest.java:194) | [junit] at org.apache.tools.ant.types.selectors.BaseSelectorTest.performTest(BaseSelectorTest.java:194) | ||||
</pre></p> | </pre></p> | ||||
@@ -613,7 +613,7 @@ | |||||
<blockquote><pre> | <blockquote><pre> | ||||
<fileset dir="${src}"> | <fileset dir="${src}"> | ||||
<type type="dir"/> | |||||
<type type="dir"/> | |||||
</fileset> | </fileset> | ||||
</pre></blockquote> | </pre></blockquote> | ||||
@@ -622,12 +622,12 @@ | |||||
directory, but avoid selecting empty directories, use: | directory, but avoid selecting empty directories, use: | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<fileset dir="${src}"> | |||||
<and> | |||||
<present targetdir="template"/> | |||||
<type type="file"/> | |||||
</and> | |||||
</fileset> | |||||
<fileset dir="${src}"> | |||||
<and> | |||||
<present targetdir="template"/> | |||||
<type type="file"/> | |||||
</and> | |||||
</fileset> | |||||
</pre></blockquote> | </pre></blockquote> | ||||
@@ -816,62 +816,62 @@ | |||||
<p>Here are some examples of how to use the Modified Selector:</p> | <p>Here are some examples of how to use the Modified Selector:</p> | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<modified/> | |||||
</fileset> | |||||
</copy | |||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<modified/> | |||||
</fileset> | |||||
</copy> | |||||
</pre></blockquote> | </pre></blockquote> | ||||
<p>This will copy all files from <i>src</i> to <i>dest</i> which content has changed. | <p>This will copy all files from <i>src</i> to <i>dest</i> which content has changed. | ||||
Using an updating PropertyfileCache with cache.properties and | Using an updating PropertyfileCache with cache.properties and | ||||
MD5-DigestAlgorithm.</p> | MD5-DigestAlgorithm.</p> | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<modified update="true" | <modified update="true" | ||||
seldirs="true" | seldirs="true" | ||||
cache="propertyfile" | cache="propertyfile" | ||||
algorithm="digest" | algorithm="digest" | ||||
comparator="equal"> | |||||
<param name="cache.cachefile" value="cache.properties"/> | |||||
<param name="algorithm.algorithm" value="MD5"/> | |||||
</modified> | |||||
</fileset> | |||||
</copy> | |||||
comparator="equal"> | |||||
<param name="cache.cachefile" value="cache.properties"/> | |||||
<param name="algorithm.algorithm" value="MD5"/> | |||||
</modified> | |||||
</fileset> | |||||
</copy> | |||||
</pre></blockquote> | </pre></blockquote> | ||||
<p>This is the same example rewritten as CoreSelector with setting the all the values | <p>This is the same example rewritten as CoreSelector with setting the all the values | ||||
(same as defaults are).</p> | (same as defaults are).</p> | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<custom class="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"> | |||||
<param name="update" value="true"/> | |||||
<param name="seldirs" value="true"/> | |||||
<param name="cache" value="propertyfile"/> | |||||
<param name="algorithm" value="digest"/> | |||||
<param name="comparator" value="equal"/> | |||||
<param name="cache.cachefile" value="cache.properties"/> | |||||
<param name="algorithm.algorithm" value="MD5"/> | |||||
</custom> | |||||
</fileset> | |||||
</copy> | |||||
<copy todir="dest"> | |||||
<fileset dir="src"> | |||||
<custom class="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"> | |||||
<param name="update" value="true"/> | |||||
<param name="seldirs" value="true"/> | |||||
<param name="cache" value="propertyfile"/> | |||||
<param name="algorithm" value="digest"/> | |||||
<param name="comparator" value="equal"/> | |||||
<param name="cache.cachefile" value="cache.properties"/> | |||||
<param name="algorithm.algorithm" value="MD5"/> | |||||
</custom> | |||||
</fileset> | |||||
</copy> | |||||
</pre></blockquote> | </pre></blockquote> | ||||
<p>And this is the same rewritten as CustomSelector.</p> | <p>And this is the same rewritten as CustomSelector.</p> | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<target name="generate-and-upload-site"> | |||||
<echo> generate the site using forrest </echo> | |||||
<antcall target="site"/> | |||||
<echo> upload the changed file </echo> | |||||
<ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.pwd}"> | |||||
<fileset dir="htdocs/manual"> | |||||
<modified/> | |||||
</fileset> | |||||
</ftp> | |||||
</target> | |||||
<target name="generate-and-upload-site"> | |||||
<echo> generate the site using forrest </echo> | |||||
<antcall target="site"/> | |||||
<echo> upload the changed file </echo> | |||||
<ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.pwd}"> | |||||
<fileset dir="htdocs/manual"> | |||||
<modified/> | |||||
</fileset> | |||||
</ftp> | |||||
</target> | |||||
</pre></blockquote> | </pre></blockquote> | ||||
<p>A useful scenario for this selector inside a build environment | <p>A useful scenario for this selector inside a build environment | ||||
for homepage generation (e.g. with <a href="http://xml.apache.org/forrest/"> | for homepage generation (e.g. with <a href="http://xml.apache.org/forrest/"> | ||||
@@ -123,7 +123,7 @@ line separator. So with input | |||||
<blockquote> | <blockquote> | ||||
<pre> | <pre> | ||||
<html> <body> | |||||
<html> <body> | |||||
<<TAB>><h1> T E S T </h1> <<TAB>> | <<TAB>><h1> T E S T </h1> <<TAB>> | ||||
<<TAB>> </body></html> | <<TAB>> </body></html> | ||||
</pre></blockquote> | </pre></blockquote> | ||||
@@ -217,7 +217,7 @@ set):</p> | |||||
<p>So here the result of a search through the codebase. Because system properties are | <p>So here the result of a search through the codebase. Because system properties are | ||||
available via Project instance, I searched for them with a | available via Project instance, I searched for them with a | ||||
<pre> | <pre> | ||||
grep -r -n "getPropert" * > ..\grep.txt | |||||
grep -r -n "getPropert" * > ..\grep.txt | |||||
</pre> | </pre> | ||||
command. After that I filtered out the often-used but not-so-important values (most of them | command. After that I filtered out the often-used but not-so-important values (most of them | ||||
read-only values): <i>path.separator, ant.home, basedir, user.dir, os.name, ant.file, | read-only values): <i>path.separator, ant.home, basedir, user.dir, os.name, ant.file, | ||||
@@ -41,16 +41,16 @@ location of that file in a property.</p> | |||||
<p>We can use the buildfile from the other tutorial and modify it a little bit. | <p>We can use the buildfile from the other tutorial and modify it a little bit. | ||||
That´s the advantage of using properties - we can reuse nearly the whole script. :-)</p> | That´s the advantage of using properties - we can reuse nearly the whole script. :-)</p> | ||||
<pre class="code"> | <pre class="code"> | ||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="<b>FindTask</b>" basedir="." default="test"> | |||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="<b>FindTask</b>" basedir="." default="test"> | |||||
... | ... | ||||
<target name="use.init" description="Taskdef´ the <b>Find</b>-Task" depends="jar"> | |||||
<taskdef name="<b>find</b>" classname="<b>Find</b>" classpath="${ant.project.name}.jar"/> | |||||
</target> | |||||
<target name="use.init" description="Taskdef´ the <b>Find</b>-Task" depends="jar"> | |||||
<taskdef name="<b>find</b>" classname="<b>Find</b>" classpath="${ant.project.name}.jar"/> | |||||
</target> | |||||
<b><!-- the other use.* targets are deleted --></b> | <b><!-- the other use.* targets are deleted --></b> | ||||
... | ... | ||||
</project> | |||||
</project> | |||||
</pre> | </pre> | ||||
<p>The buildfile is in the archive <a href="tutorial-tasks-filesets-properties.zip"> | <p>The buildfile is in the archive <a href="tutorial-tasks-filesets-properties.zip"> | ||||
@@ -63,13 +63,13 @@ tutorial-tasks-filesets-properties.zip [2]</a> in <tt>/build.xml.01-propertyacce | |||||
<p>Our first step is to set a property to a value and print the value of that property. | <p>Our first step is to set a property to a value and print the value of that property. | ||||
So our scenario would be | So our scenario would be | ||||
<pre class="code"> | <pre class="code"> | ||||
<find property="test" value="test-value"/> | |||||
<find print="test"/> | |||||
<find property="test" value="test-value"/> | |||||
<find print="test"/> | |||||
</pre> | </pre> | ||||
ok, can be rewritten with the core tasks | ok, can be rewritten with the core tasks | ||||
<pre class="code"> | <pre class="code"> | ||||
<property name="test" value="test-value"/> | |||||
<echo message="${test}"/> | |||||
<property name="test" value="test-value"/> | |||||
<echo message="${test}"/> | |||||
</pre> | </pre> | ||||
but I have to start on known ground :-)</p> | but I have to start on known ground :-)</p> | ||||
<p>So what to do? Handling three attributes (property, value, print) and an execute method. | <p>So what to do? Handling three attributes (property, value, print) and an execute method. | ||||
@@ -117,7 +117,7 @@ name. Otherwise a message is logged.</p> | |||||
<p><i>(by the way: a short word to ants "namespaces" (don´t | <p><i>(by the way: a short word to ants "namespaces" (don´t | ||||
be confused with xml namespaces which will be also introduces in the future (1.6 or 1.7): | be confused with xml namespaces which will be also introduces in the future (1.6 or 1.7): | ||||
an <antcall> creates a new space for property names. All properties from the caller | |||||
an <antcall> creates a new space for property names. All properties from the caller | |||||
are passed to the callee, but the callee can set its own properties without notice by the | are passed to the callee, but the callee can set its own properties without notice by the | ||||
caller.)</i></p> | caller.)</i></p> | ||||
@@ -158,9 +158,9 @@ their usage in buildfiles. Our goal is to search a file in path. And on this ste | |||||
path is simply a fileset (or more precise: a collection of filesets). So our usage | path is simply a fileset (or more precise: a collection of filesets). So our usage | ||||
would be | would be | ||||
<pre class="code"> | <pre class="code"> | ||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</find> | |||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</find> | |||||
</pre> | </pre> | ||||
</p> | </p> | ||||
@@ -315,30 +315,30 @@ whithout being complex :-)</p> | |||||
environment we have to set that value for our own. And we use the <junit> task in fork-mode. | environment we have to set that value for our own. And we use the <junit> task in fork-mode. | ||||
Therefore we have do modify our buildfile: | Therefore we have do modify our buildfile: | ||||
<pre class="code"> | <pre class="code"> | ||||
<target name="junit" description="Runs the unit tests" depends="jar"> | |||||
<delete dir="${junit.out.dir.xml}" /> | |||||
<mkdir dir="${junit.out.dir.xml}" /> | |||||
<junit printsummary="yes" haltonfailure="no"> | |||||
<classpath refid="classpath.test"/> | |||||
<b><sysproperty key="ant.home" value="${ant.home}"/></b> | |||||
<formatter type="xml"/> | |||||
<batchtest fork="yes" todir="${junit.out.dir.xml}"> | |||||
<fileset dir="${src.dir}" includes="**/*Test.java"/> | |||||
</batchtest> | |||||
</junit> | |||||
</target> | |||||
<target name="junit" description="Runs the unit tests" depends="jar"> | |||||
<delete dir="${junit.out.dir.xml}"/> | |||||
<mkdir dir="${junit.out.dir.xml}"/> | |||||
<junit printsummary="yes" haltonfailure="no"> | |||||
<classpath refid="classpath.test"/> | |||||
<b><sysproperty key="ant.home" value="${ant.home}"/></b> | |||||
<formatter type="xml"/> | |||||
<batchtest fork="yes" todir="${junit.out.dir.xml}"> | |||||
<fileset dir="${src.dir}" includes="**/*Test.java"/> | |||||
</batchtest> | |||||
</junit> | |||||
</target> | |||||
</pre> | </pre> | ||||
<a name="path"/> | <a name="path"/> | ||||
<h2>Using nested paths</h2> | <h2>Using nested paths</h2> | ||||
<p>A task providing support for filesets is a very comfortable one. But there is another | <p>A task providing support for filesets is a very comfortable one. But there is another | ||||
possibility of bundling files: the <path>. Fileset are easy if the files are all under | |||||
possibility of bundling files: the <path>. Fileset are easy if the files are all under | |||||
a common base directory. But if this is not the case you have a problem. Another disadvantage | a common base directory. But if this is not the case you have a problem. Another disadvantage | ||||
is its speed: if you have only a few files in a huge directory structure, why not use a | is its speed: if you have only a few files in a huge directory structure, why not use a | ||||
<filelist> instead? <path>s combines these datatypes in that way that a path contains | |||||
<filelist> instead? <path>s combines these datatypes in that way that a path contains | |||||
other paths, filesets, dirsets and filelists. This is why <a href="http://ant-contrib.sourceforge.net/"> | other paths, filesets, dirsets and filelists. This is why <a href="http://ant-contrib.sourceforge.net/"> | ||||
Ant-Contribs [4]</a> <foreach> task is modified to support paths instead of filesets. So we want that, | |||||
Ant-Contribs [4]</a> <foreach> task is modified to support paths instead of filesets. So we want that, | |||||
too.</p> | too.</p> | ||||
<p>Changing from fileset to path support is very easy:</p> | <p>Changing from fileset to path support is very easy:</p> | ||||
@@ -354,15 +354,15 @@ too.</p> | |||||
paths.add(path); | paths.add(path); | ||||
} | } | ||||
<i><b>and build file from:</b></i> | <i><b>and build file from:</b></i> | ||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</find> | |||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</find> | |||||
<i><b>to:</b></i> | <i><b>to:</b></i> | ||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<b><path></b> *3 | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</path> | |||||
</find> | |||||
<find file="ant.jar" location="location.ant-jar"> | |||||
<b><path></b> *3 | |||||
<fileset dir="${ant.home}" includes="**/*.jar"/> | |||||
</path> | |||||
</find> | |||||
</pre> | </pre> | ||||
<p>On <b>*1</b> we rename only the vector. It´s just for better reading the source. On <b>*2</b> | <p>On <b>*1</b> we rename only the vector. It´s just for better reading the source. On <b>*2</b> | ||||
we have to provide the right method: an add<i>Name</i>(<i>Type</i> t). Therefore replace the | we have to provide the right method: an add<i>Name</i>(<i>Type</i> t). Therefore replace the | ||||
@@ -414,13 +414,13 @@ And would it be good to get all of them? - It depends on ...<p> | |||||
<p>In this section we will extend that task to support returning a list of all files. | <p>In this section we will extend that task to support returning a list of all files. | ||||
Lists as property values are not supported by Ant natively. So we have to see how other | Lists as property values are not supported by Ant natively. So we have to see how other | ||||
tasks use lists. The most famous task using lists is Ant-Contribs <foreach>. All list | |||||
tasks use lists. The most famous task using lists is Ant-Contribs <foreach>. All list | |||||
elements are concatenated and separated with a customizable separator (default ',').</p> | elements are concatenated and separated with a customizable separator (default ',').</p> | ||||
<p>So we do the following:</p> | <p>So we do the following:</p> | ||||
<pre class="code"> | <pre class="code"> | ||||
<find ... <b>delimiter=""</b>/> ... </find> | |||||
<find ... <b>delimiter=""</b>/> ... </find> | |||||
</pre> | </pre> | ||||
<p>If the delimiter is set we will return all found files as list with that delimiter.</p> | <p>If the delimiter is set we will return all found files as list with that delimiter.</p> | ||||
@@ -436,35 +436,35 @@ elements are concatenated and separated with a customizable separator (default ' | |||||
<p>So we add as testcase:</p> | <p>So we add as testcase:</p> | ||||
<pre class="code"> | <pre class="code"> | ||||
<b><i>in the buildfile:</i></b> | <b><i>in the buildfile:</i></b> | ||||
<target name="test.init"> | |||||
<mkdir dir="test1/dir11/dir111"/> *1 | |||||
<mkdir dir="test1/dir11/dir112"/> | |||||
<target name="test.init"> | |||||
<mkdir dir="test1/dir11/dir111"/> *1 | |||||
<mkdir dir="test1/dir11/dir112"/> | |||||
... | ... | ||||
<touch file="test1/dir11/dir111/test"/> | |||||
<touch file="test1/dir11/dir111/not"/> | |||||
<touch file="test1/dir11/dir111/test"/> | |||||
<touch file="test1/dir11/dir111/not"/> | |||||
... | ... | ||||
<touch file="test1/dir13/dir131/not2"/> | |||||
<touch file="test1/dir13/dir132/test"/> | |||||
<touch file="test1/dir13/dir132/not"/> | |||||
<touch file="test1/dir13/dir132/not2"/> | |||||
<mkdir dir="test2"/> | |||||
<copy todir="test2"> *2 | |||||
<fileset dir="test1"/> | |||||
</copy> | |||||
</target> | |||||
<target name="testMultipleFiles" depends="use.init,<b>test.init</b>"> *3 | |||||
<find file="test" location="location.test" <b>delimiter=";"</b>> | |||||
<path> | |||||
<fileset dir="test1"/> | |||||
<fileset dir="test2"/> | |||||
</path> | |||||
</find> | |||||
<delete> *4 | |||||
<fileset dir="test1"/> | |||||
<fileset dir="test2"/> | |||||
</delete> | |||||
</target> | |||||
<touch file="test1/dir13/dir131/not2"/> | |||||
<touch file="test1/dir13/dir132/test"/> | |||||
<touch file="test1/dir13/dir132/not"/> | |||||
<touch file="test1/dir13/dir132/not2"/> | |||||
<mkdir dir="test2"/> | |||||
<copy todir="test2"> *2 | |||||
<fileset dir="test1"/> | |||||
</copy> | |||||
</target> | |||||
<target name="testMultipleFiles" depends="use.init,<b>test.init</b>"> *3 | |||||
<find file="test" location="location.test" <b>delimiter=";"</b>> | |||||
<path> | |||||
<fileset dir="test1"/> | |||||
<fileset dir="test2"/> | |||||
</path> | |||||
</find> | |||||
<delete> *4 | |||||
<fileset dir="test1"/> | |||||
<fileset dir="test2"/> | |||||
</delete> | |||||
</target> | |||||
<b><i>in the test class:</i></b> | <b><i>in the test class:</i></b> | ||||
public void testMultipleFiles() { | public void testMultipleFiles() { | ||||
@@ -563,123 +563,123 @@ important :-) examples</li> | |||||
As a template we have: | As a template we have: | ||||
<pre class="code"> | <pre class="code"> | ||||
<html> | |||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title> <b>Taskname</b> Task</title> | |||||
</head> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title> <b>Taskname</b> Task</title> | |||||
</head> | |||||
<body> | |||||
<body> | |||||
<h2><a name="<i>taskname</i>"><b>Taskname</b></a></h2> | |||||
<h3>Description</h3> | |||||
<p> <b>Describe the task.</b></p> | |||||
<h2><a name="<i>taskname</i>"><b>Taskname</b></a></h2> | |||||
<h3>Description</h3> | |||||
<p> <b>Describe the task.</b></p> | |||||
<h3>Parameters</h3> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<h3>Parameters</h3> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<b>do this html row for each attribute (including inherited attributes)</b> | <b>do this html row for each attribute (including inherited attributes)</b> | ||||
<tr> | |||||
<td valign="top">classname</td> | |||||
<td valign="top">the Java class to execute.</td> | |||||
<td align="center" valign="top">Either jar or classname</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">classname</td> | |||||
<td valign="top">the Java class to execute.</td> | |||||
<td align="center" valign="top">Either jar or classname</td> | |||||
</tr> | |||||
</table> | |||||
</table> | |||||
<h3>Parameters specified as nested elements</h3> | |||||
<h3>Parameters specified as nested elements</h3> | |||||
<b>Describe each nested element (including inherited)</b> | <b>Describe each nested element (including inherited)</b> | ||||
<h4><b>your nested element</b></h4> | |||||
<p> <b>description</b> </p> | |||||
<p><em>since Ant 1.6</em>.</p> | |||||
<h4>your nested element</b></h4> | |||||
<p> <b>description</b> </p> | |||||
<p><em>since Ant 1.6</em>.</p> | |||||
<h3>Examples</h3> | |||||
<pre> | |||||
<h3>Examples</h3> | |||||
<pre> | |||||
<b>A code sample; don´t forget to escape the < of the tags with &lt;</b> | <b>A code sample; don´t forget to escape the < of the tags with &lt;</b> | ||||
</pre> | |||||
</pre> | |||||
<b>what should that example do?</b> | <b>what should that example do?</b> | ||||
</body> | |||||
</html> | |||||
</body> | |||||
</html> | |||||
</pre> | </pre> | ||||
<p>For our task we have <a href="CoreTasks/find.html">that [6]</a>:</p> | <p>For our task we have <a href="CoreTasks/find.html">that [6]</a>:</p> | ||||
<pre class="code"> | <pre class="code"> | ||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title> Find Task</title> | |||||
</head> | |||||
<body> | |||||
<h2><a name="find">Find</a></h2> | |||||
<h3>Description</h3> | |||||
<p>Searchs in a given path for a file and returns the absolute to it as property. | |||||
If delimiter is set this task returns all found locations.</p> | |||||
<h3>Parameters</h3> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">file</td> | |||||
<td valign="top">The name of the file to search.</td> | |||||
<td align="center" valign="top">yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">location</td> | |||||
<td valign="top">The name of the property where to store the location</td> | |||||
<td align="center" valign="top">yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">delimiter</td> | |||||
<td valign="top">A delimiter to use when returning the list</td> | |||||
<td align="center" valign="top">only if the list is required</td> | |||||
</tr> | |||||
</table> | |||||
<h3>Parameters specified as nested elements</h3> | |||||
<h4>path</h4> | |||||
<p>The path where to search the file.</p> | |||||
<h3>Examples</h3> | |||||
<pre> | |||||
<find file="ant.jar" location="loc"> | |||||
<path> | |||||
<fileset dir="${ant.home}"/> | |||||
<path> | |||||
</find> | |||||
</pre> | |||||
Searches in Ants home directory for a file <i>ant.jar</i> and stores its location in | |||||
property <i>loc</i> (should be ANT_HOME/bin/ant.jar). | |||||
<pre> | |||||
<find file="ant.jar" location="loc" delimiter=";"> | |||||
<path> | |||||
<fileset dir="C:/"/> | |||||
<path> | |||||
</find> | |||||
<echo>ant.jar found in: ${loc}</echo> | |||||
</pre> | |||||
Searches in Windows C: drive for all <i>ant.jar</i> and stores their locations in | |||||
property <i>loc</i> delimited with <i>';'</i>. (should need a long time :-) | |||||
<html> | |||||
<head> | |||||
<meta http-equiv="Content-Language" content="en-us"> | |||||
<title> Find Task</title> | |||||
</head> | |||||
<body> | |||||
<h2><a name="find">Find</a></h2> | |||||
<h3>Description</h3> | |||||
<p>Searchs in a given path for a file and returns the absolute to it as property. | |||||
If delimiter is set this task returns all found locations.</p> | |||||
<h3>Parameters</h3> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">file</td> | |||||
<td valign="top">The name of the file to search.</td> | |||||
<td align="center" valign="top">yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">location</td> | |||||
<td valign="top">The name of the property where to store the location</td> | |||||
<td align="center" valign="top">yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">delimiter</td> | |||||
<td valign="top">A delimiter to use when returning the list</td> | |||||
<td align="center" valign="top">only if the list is required</td> | |||||
</tr> | |||||
</table> | |||||
<h3>Parameters specified as nested elements</h3> | |||||
<h4>path</h4> | |||||
<p>The path where to search the file.</p> | |||||
<h3>Examples</h3> | |||||
<pre> | |||||
<find file="ant.jar" location="loc"> | |||||
<path> | |||||
<fileset dir="${ant.home}"/> | |||||
<path> | |||||
</find> | |||||
</pre> | |||||
Searches in Ants home directory for a file <i>ant.jar</i> and stores its location in | |||||
property <i>loc</i> (should be ANT_HOME/bin/ant.jar). | |||||
<pre> | |||||
<find file="ant.jar" location="loc" delimiter=";"> | |||||
<path> | |||||
<fileset dir="C:/"/> | |||||
<path> | |||||
</find> | |||||
<echo>ant.jar found in: ${loc}</echo> | |||||
</pre> | |||||
Searches in Windows C: drive for all <i>ant.jar</i> and stores their locations in | |||||
property <i>loc</i> delimited with <i>';'</i>. (should need a long time :-) | |||||
After that it prints out the result (e.g. C:/ant-1.5.4/bin/ant.jar;C:/ant-1.6/bin/ant.jar). | After that it prints out the result (e.g. C:/ant-1.5.4/bin/ant.jar;C:/ant-1.6/bin/ant.jar). | ||||
</body> | |||||
</html> | |||||
</body> | |||||
</html> | |||||
</pre> | </pre> | ||||
@@ -755,9 +755,9 @@ on <b>//4</b>.</p> | |||||
are any tests failing on our machine. (We can ignore these failing tests on later | are any tests failing on our machine. (We can ignore these failing tests on later | ||||
steps; windows syntax used here- translate to xNIX if needed): | steps; windows syntax used here- translate to xNIX if needed): | ||||
<pre class="output"> | <pre class="output"> | ||||
ANTHOME> build // 1 | |||||
ANTHOME> set ANT_HOME=%CD%\dist // 2 | |||||
ANTHOME> ant test -Dtest.haltonfailure=false // 3 | |||||
ANTHOME> build // 1 | |||||
ANTHOME> set ANT_HOME=%CD%\dist // 2 | |||||
ANTHOME> ant test -Dtest.haltonfailure=false // 3 | |||||
</pre> | </pre> | ||||
First we have to build our Ant distribution (<b>//1</b>). On <b>//2</b> we set the ANT_HOME | First we have to build our Ant distribution (<b>//1</b>). On <b>//2</b> we set the ANT_HOME | ||||
@@ -782,14 +782,14 @@ necessary and saves a lot of work if you modify existing source :-)</i>. | |||||
<li>in FindTest.java change the line <tt>configureProject("build.xml");</tt> to | <li>in FindTest.java change the line <tt>configureProject("build.xml");</tt> to | ||||
<tt>configureProject("src/etc/testcases/taskdefs/find.xml");</tt> </li> | <tt>configureProject("src/etc/testcases/taskdefs/find.xml");</tt> </li> | ||||
<li>move the find.html to ANTHOME/docs/manual/CoreTasks/find.html </li> | <li>move the find.html to ANTHOME/docs/manual/CoreTasks/find.html </li> | ||||
<li>add a <tt><a href="CoreTasks/find.html">Find</a><br></tt> | |||||
<li>add a <tt><a href="CoreTasks/find.html">Find</a><br></tt> | |||||
in the ANTHOME/docs/manual/coretasklist.html </li> | in the ANTHOME/docs/manual/coretasklist.html </li> | ||||
</ul> | </ul> | ||||
Now our modifications are done and we will retest it: | Now our modifications are done and we will retest it: | ||||
<pre class="output"> | <pre class="output"> | ||||
ANTHOME> build | |||||
ANTHOME> ant run-single-test // 1 | |||||
ANTHOME> build | |||||
ANTHOME> ant run-single-test // 1 | |||||
-Dtestcase=org.apache.tools.ant.taskdefs.FindTest // 2 | -Dtestcase=org.apache.tools.ant.taskdefs.FindTest // 2 | ||||
-Dtest.haltonfailure=false | -Dtest.haltonfailure=false | ||||
</pre> | </pre> | ||||
@@ -799,15 +799,15 @@ failures of our own test (<b>//1 + 2</b>).</p> | |||||
<p>And ... oh, all tests fail: <i>Ant could not find the task or a class this task relies upon.</i></p> | <p>And ... oh, all tests fail: <i>Ant could not find the task or a class this task relies upon.</i></p> | ||||
<p>Ok: in the earlier steps we told Ant to use the Find class for the <find> task (remember the | |||||
<taskdef> statement in the "use.init" target). But now we want to introduce that task as | |||||
<p>Ok: in the earlier steps we told Ant to use the Find class for the <find> task (remember the | |||||
<taskdef> statement in the "use.init" target). But now we want to introduce that task as | |||||
a core task. And nobody wants to taskdef the javac, echo, ... So what to do? The answer is the | a core task. And nobody wants to taskdef the javac, echo, ... So what to do? The answer is the | ||||
src/main/.../taskdefs/default.properties. Here is the mapping between taskname and implementing | src/main/.../taskdefs/default.properties. Here is the mapping between taskname and implementing | ||||
class done. So we add a <tt>find=org.apache.tools.ant.taskdefs.Find</tt> as the last core | class done. So we add a <tt>find=org.apache.tools.ant.taskdefs.Find</tt> as the last core | ||||
task (just before the <tt># optional tasks</tt> line). Now a second try: | task (just before the <tt># optional tasks</tt> line). Now a second try: | ||||
<pre class="output"> | <pre class="output"> | ||||
ANTHOME> build // 1 | |||||
ANTHOME> ant run-single-test | |||||
ANTHOME> build // 1 | |||||
ANTHOME> ant run-single-test | |||||
-Dtestcase=org.apache.tools.ant.taskdefs.FindTest | -Dtestcase=org.apache.tools.ant.taskdefs.FindTest | ||||
-Dtest.haltonfailure=false | -Dtest.haltonfailure=false | ||||
</pre> | </pre> | ||||
@@ -816,7 +816,7 @@ We have to rebuild (<b>//1</b>) Ant because the test look in the %ANT_HOME%\lib\ | |||||
source path. So we have to rebuild that jar. But now all tests pass and we check whether our class | source path. So we have to rebuild that jar. But now all tests pass and we check whether our class | ||||
breaks some other tests. | breaks some other tests. | ||||
<pre class="output"> | <pre class="output"> | ||||
ANTHOME> ant test -Dtest.haltonfailure=false | |||||
ANTHOME> ant test -Dtest.haltonfailure=false | |||||
</pre> | </pre> | ||||
Because there are a lot of tests this step requires a little bit of time. So use the <i>run-single-test</i> | Because there are a lot of tests this step requires a little bit of time. So use the <i>run-single-test</i> | ||||
during development and do the <i>test</i> only at the end (maybe sometimes during development too). | during development and do the <i>test</i> only at the end (maybe sometimes during development too). | ||||
@@ -863,7 +863,7 @@ directory (this feature was added with Ant 1.6).</p> | |||||
<p>So we will run the tests with | <p>So we will run the tests with | ||||
<pre class="output"> | <pre class="output"> | ||||
ANTHOME> ant -f check.xml checkstyle htmlreport | |||||
ANTHOME> ant -f check.xml checkstyle htmlreport | |||||
</pre> | </pre> | ||||
I prefer the HTML report because there are lots of messages and we can navigate faster. | I prefer the HTML report because there are lots of messages and we can navigate faster. | ||||
Open the ANTHOME/build/reports/checkstyle/html/index.html and navigate to the Find.java. Now we | Open the ANTHOME/build/reports/checkstyle/html/index.html and navigate to the Find.java. Now we | ||||
@@ -900,7 +900,7 @@ entry. For both we need some information:</p> | |||||
<tr> | <tr> | ||||
<th>body</th> | <th>body</th> | ||||
<td><i>more details about the path</i></td> | <td><i>more details about the path</i></td> | ||||
<td>This new task looks inside a nested <path/> for occurrences of a file and stores | |||||
<td>This new task looks inside a nested <path/> for occurrences of a file and stores | |||||
all locations as a property. See the included manual for details.</td> | all locations as a property. See the included manual for details.</td> | ||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
@@ -44,52 +44,52 @@ create a text file names <i>build.xml</i>. What should Ant do for us? | |||||
</ul> | </ul> | ||||
So the buildfile contains three targets. | So the buildfile contains three targets. | ||||
<pre class="code"> | <pre class="code"> | ||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="jar"> | |||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="jar"> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="classes"/> | |||||
<delete file="MyTasks.jar"/> | |||||
</target> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="classes"/> | |||||
<delete file="MyTasks.jar"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<javac srcdir="src" destdir="classes"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<javac srcdir="src" destdir="classes"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task"> | |||||
<jar destfile="MyTask.jar" basedir="classes"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task"> | |||||
<jar destfile="MyTask.jar" basedir="classes"/> | |||||
</target> | |||||
</project> | |||||
</project> | |||||
</pre> | </pre> | ||||
This buildfile uses often the same value (src, classes, MyTask.jar), so we should rewrite that | This buildfile uses often the same value (src, classes, MyTask.jar), so we should rewrite that | ||||
using <property>s. On second there are some handicaps: <javac> requires that the destination | |||||
using <property>s. On second there are some handicaps: <javac> requires that the destination | |||||
directory exists; a call of "clean" with a non existing classes directory will fail; "jar" requires | directory exists; a call of "clean" with a non existing classes directory will fail; "jar" requires | ||||
the execution of some steps bofore. So the refactored code is: | the execution of some steps bofore. So the refactored code is: | ||||
<pre class="code"> | <pre class="code"> | ||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="jar"> | |||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="jar"> | |||||
<b><property name="src.dir" value="src"/></b> | |||||
<b><property name="classes.dir" value="classes"/></b> | |||||
<b><property name="src.dir" value="src"/></b> | |||||
<b><property name="classes.dir" value="classes"/></b> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="<b>${classes.dir}</b>" <b>failonerror="false"</b>/> | |||||
<delete file="<b>${ant.project.name}.jar</b>"/> | |||||
</target> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="<b>${classes.dir}</b>" <b>failonerror="false"</b>/> | |||||
<delete file="<b>${ant.project.name}.jar</b>"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<b><mkdir dir="${classes.dir}"/></b> | |||||
<javac srcdir="<b>${src.dir}</b>" destdir="${classes.dir}"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<b><mkdir dir="${classes.dir}"/></b> | |||||
<javac srcdir="<b>${src.dir}</b>" destdir="${classes.dir}"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task" <b>depends="compile"</b>> | |||||
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task" <b>depends="compile"</b>> | |||||
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"/> | |||||
</target> | |||||
</project> | |||||
</project> | |||||
</pre> | </pre> | ||||
<i>ant.project.name</i> is one of the | <i>ant.project.name</i> is one of the | ||||
<a href="http://ant.apache.org/manual/using.html#built-in-props" target="_blank"> | <a href="http://ant.apache.org/manual/using.html#built-in-props" target="_blank"> | ||||
@@ -118,19 +118,19 @@ its <i>depends</i>-clause the "compile" is executed before). | |||||
<p>But after creating the jar we want to use our new Task. Therefore we need a | <p>But after creating the jar we want to use our new Task. Therefore we need a | ||||
new target "use". Before we can use our new task we have to declare it with | new target "use". Before we can use our new task we have to declare it with | ||||
<a href="http://ant.apache.org/manual/CoreTasks/taskdef.html" target="_blank"> | <a href="http://ant.apache.org/manual/CoreTasks/taskdef.html" target="_blank"> | ||||
<taskdef> [2]</a>. And for easier process we change the default clause: | |||||
<taskdef> [2]</a>. And for easier process we change the default clause: | |||||
<pre class="code"> | <pre class="code"> | ||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="<b>use</b>"> | |||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="<b>use</b>"> | |||||
... | ... | ||||
<b><target name="use" description="Use the Task" depends="jar"> | |||||
<taskdef name="helloworld" classname="HelloWorld" classpath="${ant.project.name}.jar"/> | |||||
<helloworld/> | |||||
</target></b> | |||||
<b><target name="use" description="Use the Task" depends="jar"> | |||||
<taskdef name="helloworld" classname="HelloWorld" classpath="${ant.project.name}.jar"/> | |||||
<helloworld/> | |||||
</target></b> | |||||
</project> | |||||
</project> | |||||
</pre> | </pre> | ||||
Important is the <i>classpath</i>-attribute. Ant searches in its /lib directory for | Important is the <i>classpath</i>-attribute. Ant searches in its /lib directory for | ||||
@@ -226,8 +226,8 @@ use: | |||||
<a name="attributes"> | <a name="attributes"> | ||||
<h2>Attributes</h2> | <h2>Attributes</h2> | ||||
<p>Now we want to specify the text of our message (it seems that we are | <p>Now we want to specify the text of our message (it seems that we are | ||||
rewriting the <echo/> task :-). First we well do that with an attribute. | |||||
It is very easy - for each attribute provide a <tt>public void set<attributename>(<type> | |||||
rewriting the <echo/> task :-). First we well do that with an attribute. | |||||
It is very easy - for each attribute provide a <tt>public void set<attributename>(<type> | |||||
newValue)</tt> method and Ant will do the rest via reflection.</p> | newValue)</tt> method and Ant will do the rest via reflection.</p> | ||||
<pre class="code"> | <pre class="code"> | ||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
@@ -257,12 +257,12 @@ the log() method can't handle a <i>null</i> value as parameter and throws a Null | |||||
<p>After that we have to modify our buildfile: | <p>After that we have to modify our buildfile: | ||||
<pre class="code"> | <pre class="code"> | ||||
<target name="use" description="Use the Task" depends="jar"> | |||||
<target name="use" description="Use the Task" depends="jar"> | |||||
<taskdef name="helloworld" | <taskdef name="helloworld" | ||||
classname="HelloWorld" | classname="HelloWorld" | ||||
classpath="${ant.project.name}.jar"/> | |||||
<helloworld <b>message="Hello World"</b>/> | |||||
</target> | |||||
classpath="${ant.project.name}.jar"/> | |||||
<helloworld <b>message="Hello World"</b>/> | |||||
</target> | |||||
</pre> | </pre> | ||||
That's all.</p> | That's all.</p> | ||||
@@ -275,13 +275,13 @@ arguments of the set-method:<ul> | |||||
<a href="http://ant.apache.org/manual/develop.html#set-magic">Manual | <a href="http://ant.apache.org/manual/develop.html#set-magic">Manual | ||||
'Writing Your Own Task' [3]</a>)</li> | 'Writing Your Own Task' [3]</a>)</li> | ||||
</ul> | </ul> | ||||
Before calling the set-method all properties are resolved. So a <tt><helloworld message="${msg}"/></tt> | |||||
Before calling the set-method all properties are resolved. So a <tt><helloworld message="${msg}"/></tt> | |||||
would not set the message string to "${msg}" if there is a property "msg" with a set value. | would not set the message string to "${msg}" if there is a property "msg" with a set value. | ||||
<a name="NestedText"></a> | <a name="NestedText"></a> | ||||
<h2>Nested Text</h2> | <h2>Nested Text</h2> | ||||
<p>Maybe you have used the <echo> task in a way like <tt><echo>Hello World</echo></tt>. | |||||
<p>Maybe you have used the <echo> task in a way like <tt><echo>Hello World</echo></tt>. | |||||
For that you have to provide a <tt>public void addText(String text)</tt> method. | For that you have to provide a <tt>public void addText(String text)</tt> method. | ||||
<pre class="code"> | <pre class="code"> | ||||
... | ... | ||||
@@ -305,7 +305,7 @@ the <a href="http://ant.apache.org/manual/develop.html#nested-elements">Manual [ | |||||
We use the first way of the three described ways. There are several steps for that:<ol> | We use the first way of the three described ways. There are several steps for that:<ol> | ||||
<li>We create a class for collecting all the infos the nested element should contain. | <li>We create a class for collecting all the infos the nested element should contain. | ||||
This class is created by the same rules for attributes and nested elements | This class is created by the same rules for attributes and nested elements | ||||
as for the task (set<attributename>() methods). </li> | |||||
as for the task (set<attributename>() methods). </li> | |||||
<li>The task holds multiple instances of this class in a list.</li> | <li>The task holds multiple instances of this class in a list.</li> | ||||
<li>A factory method instantiates an object, saves the reference in the list | <li>A factory method instantiates an object, saves the reference in the list | ||||
and returns it to Ant Core.</li> | and returns it to Ant Core.</li> | ||||
@@ -346,10 +346,10 @@ The mapping XML-name : classname is defined in the factory method: | |||||
<tt>public <i>classname</i> create<i>XML-name</i>()</tt>. Therefore we write in | <tt>public <i>classname</i> create<i>XML-name</i>()</tt>. Therefore we write in | ||||
the buildfile | the buildfile | ||||
<pre class="code"> | <pre class="code"> | ||||
<helloworld> | |||||
<message msg="Nested Element 1"/> | |||||
<message msg="Nested Element 2"/> | |||||
</helloworld> | |||||
<helloworld> | |||||
<message msg="Nested Element 1"/> | |||||
<message msg="Nested Element 2"/> | |||||
</helloworld> | |||||
</pre> | </pre> | ||||
@@ -357,76 +357,76 @@ the buildfile | |||||
<h2>Our task in a little more complex version</h2> | <h2>Our task in a little more complex version</h2> | ||||
<p>For recapitulation now a little refactored buildfile: | <p>For recapitulation now a little refactored buildfile: | ||||
<pre class="code"> | <pre class="code"> | ||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="use"> | |||||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||||
<project name="MyTask" basedir="." default="use"> | |||||
<property name="src.dir" value="src"/> | |||||
<property name="classes.dir" value="classes"/> | |||||
<property name="src.dir" value="src"/> | |||||
<property name="classes.dir" value="classes"/> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="${classes.dir}" failonerror="false"/> | |||||
<delete file="${ant.project.name}.jar"/> | |||||
</target> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete dir="${classes.dir}" failonerror="false"/> | |||||
<delete file="${ant.project.name}.jar"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<mkdir dir="${classes.dir}"/> | |||||
<javac srcdir="${src.dir}" destdir="${classes.dir}"/> | |||||
</target> | |||||
<target name="compile" description="Compiles the Task"> | |||||
<mkdir dir="${classes.dir}"/> | |||||
<javac srcdir="${src.dir}" destdir="${classes.dir}"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task" depends="compile"> | |||||
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"/> | |||||
</target> | |||||
<target name="jar" description="JARs the Task" depends="compile"> | |||||
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"/> | |||||
</target> | |||||
<target name="use.init" | <target name="use.init" | ||||
description="Taskdef the HelloWorld-Task" | description="Taskdef the HelloWorld-Task" | ||||
depends="jar"> | |||||
depends="jar"> | |||||
<taskdef name="helloworld" | <taskdef name="helloworld" | ||||
classname="HelloWorld" | classname="HelloWorld" | ||||
classpath="${ant.project.name}.jar"/> | |||||
</target> | |||||
classpath="${ant.project.name}.jar"/> | |||||
</target> | |||||
<target name="use.without" | <target name="use.without" | ||||
description="Use without any" | description="Use without any" | ||||
depends="use.init"> | |||||
<helloworld/> | |||||
</target> | |||||
depends="use.init"> | |||||
<helloworld/> | |||||
</target> | |||||
<target name="use.message" | <target name="use.message" | ||||
description="Use with attribute 'message'" | description="Use with attribute 'message'" | ||||
depends="use.init"> | |||||
<helloworld message="attribute-text"/> | |||||
</target> | |||||
depends="use.init"> | |||||
<helloworld message="attribute-text"/> | |||||
</target> | |||||
<target name="use.fail" | <target name="use.fail" | ||||
description="Use with attribute 'fail'" | description="Use with attribute 'fail'" | ||||
depends="use.init"> | |||||
<helloworld fail="true"/> | |||||
</target> | |||||
depends="use.init"> | |||||
<helloworld fail="true"/> | |||||
</target> | |||||
<target name="use.nestedText" | <target name="use.nestedText" | ||||
description="Use with nested text" | description="Use with nested text" | ||||
depends="use.init"> | |||||
<helloworld>nested-text</helloworld> | |||||
</target> | |||||
depends="use.init"> | |||||
<helloworld>nested-text</helloworld> | |||||
</target> | |||||
<target name="use.nestedElement" | <target name="use.nestedElement" | ||||
description="Use with nested 'message'" | description="Use with nested 'message'" | ||||
depends="use.init"> | |||||
<helloworld> | |||||
<message msg="Nested Element 1"/> | |||||
<message msg="Nested Element 2"/> | |||||
</helloworld> | |||||
</target> | |||||
depends="use.init"> | |||||
<helloworld> | |||||
<message msg="Nested Element 1"/> | |||||
<message msg="Nested Element 2"/> | |||||
</helloworld> | |||||
</target> | |||||
<target name="use" | <target name="use" | ||||
description="Try all (w/out use.fail)" | description="Try all (w/out use.fail)" | ||||
depends="use.without,use.message,use.nestedText,use.nestedElement" | depends="use.without,use.message,use.nestedText,use.nestedElement" | ||||
/> | |||||
/> | |||||
</project> | |||||
</project> | |||||
</pre> | </pre> | ||||
And the code of the task: | And the code of the task: | ||||
@@ -505,7 +505,7 @@ public class HelloWorld extends Task { | |||||
And it works: | And it works: | ||||
<pre class="output"> | <pre class="output"> | ||||
C:\tmp\anttests\MyFirstTask>ant | |||||
C:\tmp\anttests\MyFirstTask>ant | |||||
Buildfile: build.xml | Buildfile: build.xml | ||||
compile: | compile: | ||||
@@ -537,7 +537,7 @@ use: | |||||
BUILD SUCCESSFUL | BUILD SUCCESSFUL | ||||
Total time: 3 seconds | Total time: 3 seconds | ||||
C:\tmp\anttests\MyFirstTask>ant use.fail | |||||
C:\tmp\anttests\MyFirstTask>ant use.fail | |||||
Buildfile: build.xml | Buildfile: build.xml | ||||
compile: | compile: | ||||
@@ -552,7 +552,7 @@ BUILD FAILED | |||||
C:\tmp\anttests\MyFirstTask\build.xml:36: Fail requested. | C:\tmp\anttests\MyFirstTask\build.xml:36: Fail requested. | ||||
Total time: 1 second | Total time: 1 second | ||||
C:\tmp\anttests\MyFirstTask> | |||||
C:\tmp\anttests\MyFirstTask> | |||||
</pre> | </pre> | ||||
Next step: test ... | Next step: test ... | ||||
@@ -580,66 +580,66 @@ target "test-jar" or you can download a nightly build from | |||||
<a href="http://gump.covalent.net/jars/latest/ant/ant-testutil.jar"> | <a href="http://gump.covalent.net/jars/latest/ant/ant-testutil.jar"> | ||||
http://gump.covalent.net/jars/latest/ant/ant-testutil.jar [5]</a>.</p> | http://gump.covalent.net/jars/latest/ant/ant-testutil.jar [5]</a>.</p> | ||||
<p>For executing the test and creating a report we need the optional tasks <junit> | |||||
and <junitreport>. So we add to the buildfile: | |||||
<p>For executing the test and creating a report we need the optional tasks <junit> | |||||
and <junitreport>. So we add to the buildfile: | |||||
<pre class="code"> | <pre class="code"> | ||||
... | ... | ||||
<font color="#9F9F9F"><project name="MyTask" basedir="." </font>default="test"<font color="#9F9F9F">></font> | <font color="#9F9F9F"><project name="MyTask" basedir="." </font>default="test"<font color="#9F9F9F">></font> | ||||
... | ... | ||||
<property name="ant.test.lib" value="ant-testutil.jar"/> | |||||
<property name="report.dir" value="report"/> | |||||
<property name="junit.out.dir.xml" value="${report.dir}/junit/xml"/> | |||||
<property name="junit.out.dir.html" value="${report.dir}/junit/html"/> | |||||
<path id="classpath.run"> | |||||
<path path="${java.class.path}"/> | |||||
<path location="${ant.project.name}.jar"/> | |||||
</path> | |||||
<path id="classpath.test"> | |||||
<path refid="classpath.run"/> | |||||
<path location="${ant.test.lib}"/> | |||||
</path> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete failonerror="false" includeEmptyDirs="true"> | |||||
<fileset dir="." includes="${ant.project.name}.jar"/> | |||||
<fileset dir="${classes.dir}"/> | |||||
<fileset dir="${report.dir}"/> | |||||
</delete> | |||||
</target> | |||||
<font color="#9F9F9F"><target name="compile" description="Compiles the Task"> | |||||
<mkdir dir="${classes.dir}"/> | |||||
<javac srcdir="${src.dir}" destdir="${classes.dir}" </font>classpath="${ant.test.lib}"<font color="#9F9F9F">/> | |||||
</target></font> | |||||
<property name="ant.test.lib" value="ant-testutil.jar"/> | |||||
<property name="report.dir" value="report"/> | |||||
<property name="junit.out.dir.xml" value="${report.dir}/junit/xml"/> | |||||
<property name="junit.out.dir.html" value="${report.dir}/junit/html"/> | |||||
<path id="classpath.run"> | |||||
<path path="${java.class.path}"/> | |||||
<path location="${ant.project.name}.jar"/> | |||||
</path> | |||||
<path id="classpath.test"> | |||||
<path refid="classpath.run"/> | |||||
<path location="${ant.test.lib}"/> | |||||
</path> | |||||
<target name="clean" description="Delete all generated files"> | |||||
<delete failonerror="false" includeEmptyDirs="true"> | |||||
<fileset dir="." includes="${ant.project.name}.jar"/> | |||||
<fileset dir="${classes.dir}"/> | |||||
<fileset dir="${report.dir}"/> | |||||
</delete> | |||||
</target> | |||||
<font color="#9F9F9F"><target name="compile" description="Compiles the Task"> | |||||
<mkdir dir="${classes.dir}"/> | |||||
<javac srcdir="${src.dir}" destdir="${classes.dir}" </font>classpath="${ant.test.lib}"<font color="#9F9F9F">/> | |||||
</target></font> | |||||
... | ... | ||||
<target name="junit" description="Runs the unit tests" depends="jar"> | |||||
<delete dir="${junit.out.dir.xml}" /> | |||||
<mkdir dir="${junit.out.dir.xml}" /> | |||||
<junit printsummary="yes" haltonfailure="no"> | |||||
<classpath refid="classpath.test"/> | |||||
<formatter type="xml"/> | |||||
<batchtest fork="yes" todir="${junit.out.dir.xml}"> | |||||
<fileset dir="${src.dir}" includes="**/*Test.java"/> | |||||
</batchtest> | |||||
</junit> | |||||
</target> | |||||
<target name="junitreport" description="Create a report for the rest result"> | |||||
<mkdir dir="${junit.out.dir.html}" /> | |||||
<junitreport todir="${junit.out.dir.html}"> | |||||
<fileset dir="${junit.out.dir.xml}"> | |||||
<include name="*.xml"/> | |||||
</fileset> | |||||
<report format="frames" todir="${junit.out.dir.html}"/> | |||||
</junitreport> | |||||
</target> | |||||
<target name="junit" description="Runs the unit tests" depends="jar"> | |||||
<delete dir="${junit.out.dir.xml}"/> | |||||
<mkdir dir="${junit.out.dir.xml}"/> | |||||
<junit printsummary="yes" haltonfailure="no"> | |||||
<classpath refid="classpath.test"/> | |||||
<formatter type="xml"/> | |||||
<batchtest fork="yes" todir="${junit.out.dir.xml}"> | |||||
<fileset dir="${src.dir}" includes="**/*Test.java"/> | |||||
</batchtest> | |||||
</junit> | |||||
</target> | |||||
<target name="junitreport" description="Create a report for the rest result"> | |||||
<mkdir dir="${junit.out.dir.html}"/> | |||||
<junitreport todir="${junit.out.dir.html}"> | |||||
<fileset dir="${junit.out.dir.xml}"> | |||||
<include name="*.xml"/> | |||||
</fileset> | |||||
<report format="frames" todir="${junit.out.dir.html}"/> | |||||
</junitreport> | |||||
</target> | |||||
<target name="test" | <target name="test" | ||||
depends="junit,junitreport" | depends="junit,junitreport" | ||||
description="Runs unit tests and creates a report" | description="Runs unit tests and creates a report" | ||||
/> | |||||
/> | |||||
... | ... | ||||
</pre></p> | </pre></p> | ||||
@@ -693,7 +693,7 @@ public class HelloWorldTest extends BuildFileTest { | |||||
<p>When starting <tt>ant</tt> we'll get a short message to STDOUT and | <p>When starting <tt>ant</tt> we'll get a short message to STDOUT and | ||||
a nice HTML-report. | a nice HTML-report. | ||||
<pre class="output"> | <pre class="output"> | ||||
C:\tmp\anttests\MyFirstTask>ant | |||||
C:\tmp\anttests\MyFirstTask>ant | |||||
Buildfile: build.xml | Buildfile: build.xml | ||||
compile: | compile: | ||||
@@ -719,7 +719,7 @@ test: | |||||
BUILD SUCCESSFUL | BUILD SUCCESSFUL | ||||
Total time: 7 seconds | Total time: 7 seconds | ||||
C:\tmp\anttests\MyFirstTask> | |||||
C:\tmp\anttests\MyFirstTask> | |||||
</pre></p> | </pre></p> | ||||