<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>teamzone.ch &#187; ANT</title>
	<atom:link href="http://teamzone.ch/category/ant/feed/" rel="self" type="application/rss+xml" />
	<link>http://teamzone.ch</link>
	<description>Welcome to the Joint-Venture Blog from Fabio Cortesi and Stefan Jäger.</description>
	<lastBuildDate>Wed, 01 Jun 2011 22:43:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Perform XPath queries inside Ant</title>
		<link>http://teamzone.ch/2009/05/17/perform-xpath-queries-inside-ant/</link>
		<comments>http://teamzone.ch/2009/05/17/perform-xpath-queries-inside-ant/#comments</comments>
		<pubDate>Sun, 17 May 2009 18:19:00 +0000</pubDate>
		<dc:creator>Stefan Jäger</dc:creator>
				<category><![CDATA[ANT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://teamzone.ch/2009/05/13/perform-xpath-queries-inside-ant/</guid>
		<description><![CDATA[Ant offers some XML features like the xslt task, which transforms XML files into other files. But unfortunately, with Ant you can&#8217;t make simple XPath Queries on a specific XML file. &#160; Luckily, there is a nice open source solution called XmlTask, which offers many possibilities to work with XML files. &#160; Download the latest [...]]]></description>
			<content:encoded><![CDATA[<p>Ant offers some XML features like the xslt task, which transforms XML files into other files. But unfortunately, with Ant you can&#8217;t make simple XPath Queries on a specific XML file. </p>
<p>&#160;</p>
<p>Luckily, there is a nice open source solution called XmlTask, which offers many possibilities to work with XML files.</p>
<p>&#160;</p>
<ol>
<li>Download the latest version of XmlTask from <a href="http://xmltask.sf.net">http://xmltask.sf.net</a></li>
<li>Create a task definition in Ant     

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;xmltask&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;com.oopsconsultancy.xmltask.ant.XmlTask&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;./xmltask-v1.15.1.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

</li>
<li>Use it with the &lt;xmltask&gt; definition<br />
    <br />For example, read out the number of a specific node in the XML file:</p>
<p></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xmltask</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;someFile.xml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;count(//aNode)&quot;</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;numberOfNodes&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xmltask<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Or change an attribute:</p>
<p></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xmltask</span> <span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;someFile.xml&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;toAnotherFile.xml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attr</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;//aNode[1]&quot;</span> <span style="color: #000066;">attr</span>=<span style="color: #ff0000;">&quot;enabled&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xmltask<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
</ol>
<p>&#160;</p>
<p>There are many other possibilites to work with XML files inside Ant. Check out the documentation at <a href="http://xmltask.sf.net">http://xmltask.sf.net</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://teamzone.ch/2009/05/17/perform-xpath-queries-inside-ant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use Groovy inside Ant</title>
		<link>http://teamzone.ch/2009/05/13/use-groovy-inside-ant/</link>
		<comments>http://teamzone.ch/2009/05/13/use-groovy-inside-ant/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:59:27 +0000</pubDate>
		<dc:creator>Stefan Jäger</dc:creator>
				<category><![CDATA[ANT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://teamzone.ch/2009/05/13/use-groovy-inside-ant/</guid>
		<description><![CDATA[There are some kind of tasks, which Ant won&#8217;t do. One of them is the loop. There is no simple way to implement a dynamic for or while loop in Ant. What do i mean with dynamic? Let me make an example. Ant reads out a number of iterations from a property file (we call [...]]]></description>
			<content:encoded><![CDATA[<p>There are some kind of tasks, which Ant won&#8217;t do. One of them is the loop. There is no simple way to implement a dynamic for or while loop in Ant. What do i mean with dynamic? Let me make an example. Ant reads out a number of iterations from a property file (we call it the number x) and should perform a loop x-times to call another Ant task. And this can only hardly be done with Ant.</p>
<p>&#160;</p>
<p>&#160;</p>
<p><a href="http://teamzone.ch/wp-content/uploads/2009/05/image.png"  rel="lightbox" rel="lightbox[roadtrip]"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://teamzone.ch/wp-content/uploads/2009/05/image-thumb.png" width="203" height="100" /></a> But fortunately, there is Groovy. Groovy is a scripting language, which runs in a Java Virtual Machine. And because of that, it can be easily integrated with Ant.</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p> <span id="more-360"></span>
<ol>
<li>Download the latest release of Groovy at <a href="http://groovy.codehaus.org/Download">http://groovy.codehaus.org/Download</a> </li>
<li>Inside the Groovy binary, there is a folder called embeddable. In this folder, there is a file called groovy-all-X.X.X.jar. Take it and copy it near your build file. </li>
<li>Create a task definition in Ant      

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> </span>
<span style="color: #009900;"><span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;groovy&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;./groovy-all-X.X.X.jar&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;org.codehaus.groovy.ant.Groovy&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

</li>
<li>Use Groovy somewhere inside an Ant task:<br />
    </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groovy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   int i = 1
   int numberOfIterations = properties[&quot;numberOfIterations&quot;].toInteger()
   while (i <span style="color: #ddbb00;">&amp;lt;</span>= numberOfIterations) {
    properties[&quot;currentIteration&quot;] = i
    ant.antcall(target:&quot;execute.a.task&quot;)
    i++
   }
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groovy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
</ol>
<p>Isn&#8217;t that groovy? </p>
<p>&#160;</p>
<p>Groovy integrated in Ant offers many possibilities, which can be read here <a href="http://groovy.codehaus.org/The+groovy+Ant+Task">http://groovy.codehaus.org/The+groovy+Ant+Task</a>. I used for my little script the variable <strong>ant</strong>, an instance of the current Ant project and the <strong>properties</strong> map, which holds all properties inside Ant.</p>
]]></content:encoded>
			<wfw:commentRss>http://teamzone.ch/2009/05/13/use-groovy-inside-ant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ant-Contrib</title>
		<link>http://teamzone.ch/2008/02/05/ant-contrib/</link>
		<comments>http://teamzone.ch/2008/02/05/ant-contrib/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 21:16:55 +0000</pubDate>
		<dc:creator>Stefan Jäger</dc:creator>
				<category><![CDATA[ANT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.stefanjaeger.ch/2008/02/05/ant-contrib/</guid>
		<description><![CDATA[In some cases, ANT has it&#8217;s limitations. For example, it is not really easy to create an if-else structure or a for-loop. For this reason, a few people started long time ago the Ant-Contrib project. Just download it and put the jar file in the lib folder of the project. Then, just at following line [...]]]></description>
			<content:encoded><![CDATA[<p>In some cases, ANT has it&#8217;s limitations. For example, it is not really easy to create an if-else structure or a for-loop. For this reason, a few people started long time ago the <a href="http://ant-contrib.sourceforge.net/">Ant-Contrib project</a>. Just download it and put the jar file in the lib folder of the project. Then, just at following line to the build file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;net/sf/antcontrib/antcontrib.properties&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/taskdef<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now, you can start using constructs like <a href="http://ant-contrib.sourceforge.net/tasks/tasks/index.html">if, foreach </a>and combine these tasks with usual ANT tasks. Here a little example:</p>
<p><strong>with antcontrib:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;theultimateconditionmachine&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;equals</span> <span style="color: #000066;">arg1</span>=<span style="color: #ff0000;">&quot;${foo}&quot;</span> <span style="color: #000066;">arg2</span>=<span style="color: #ff0000;">&quot;bar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;then<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;property foo is bar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/then<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;else<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;property foo is not bar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/else<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>without antcontrib:</strong><br />
if you want to perform the same task with ant, you need to create 4 (!) ant targets:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;noway&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;conditionIf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;conditionElse&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conditionDef&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condition</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;conditionIsTrue&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;equals</span> <span style="color: #000066;">arg1</span>=<span style="color: #ff0000;">&quot;${foo}&quot;</span> <span style="color: #000066;">arg2</span>=<span style="color: #ff0000;">&quot;bar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/condition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conditionIf&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;conditionDef&quot;</span> <span style="color: #000066;">if</span>=<span style="color: #ff0000;">&quot;conditionIsTrue&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;property foo is bar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conditionElse&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;conditionDef&quot;</span> <span style="color: #000066;">unless</span>=<span style="color: #ff0000;">&quot;conditionIsTrue&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;property foo is not bar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://teamzone.ch/2008/02/05/ant-contrib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

