|
|
@@ -182,6 +182,23 @@ |
|
|
|
sourcesafe control files (CVS files, editor backup files), but |
|
|
|
it doesn't seem to work. The files never get deleted. What's |
|
|
|
wrong? |
|
|
|
</a></li> |
|
|
|
<li><a href="#multi-conditions"> |
|
|
|
I want to execute a particular target only if |
|
|
|
multiple conditions are true. |
|
|
|
</a></li> |
|
|
|
<li><a href="#stop-dependency"> |
|
|
|
I have a target I want to skip if a variable is set, |
|
|
|
so I have <code>unless="variable"</code> as an attribute |
|
|
|
of the target. The trouble is that all of the targets that this target |
|
|
|
depends on are still executed. Why? |
|
|
|
</a></li> |
|
|
|
<li><a href="#include-order"> |
|
|
|
In my fileset, I've put in an |
|
|
|
<code><exclude></code> of all files followed by an |
|
|
|
<code><include></code> of just the files I want, but it |
|
|
|
isn't giving me anything at all. What's wrong? |
|
|
|
|
|
|
|
</a></li> |
|
|
|
</ul> |
|
|
|
</blockquote> |
|
|
@@ -226,6 +243,10 @@ |
|
|
|
<li><a href="#mail-logger"> |
|
|
|
How do I send an email with the result of my build |
|
|
|
process? |
|
|
|
</a></li> |
|
|
|
<li><a href="#listener-properties"> |
|
|
|
How do I get at the properties that Ant was running |
|
|
|
with from inside BuildListener? |
|
|
|
</a></li> |
|
|
|
</ul> |
|
|
|
</blockquote> |
|
|
@@ -294,10 +315,12 @@ |
|
|
|
<blockquote> |
|
|
|
<p>The page you are looking it is generated from |
|
|
|
<a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/jakarta-ant/xdocs/faq.xml">this</a> |
|
|
|
|
|
|
|
document. If you want to add a new question, please submit |
|
|
|
a patch against this document, the structure is hoped to be |
|
|
|
self-explaining.</p> |
|
|
|
a patch against this document to one of Ant's mailing lists, |
|
|
|
the structure is hoped to be self-explaining.</p> |
|
|
|
<p>If you don't know how to create a patch, see the patches |
|
|
|
section of <a href="http://jakarta.apache.org/site/source.html">this |
|
|
|
page</a>.</p> |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
@@ -852,6 +875,233 @@ shell-prompt> cat < foo |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="multi-conditions"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
|
<tr><td bgcolor="#828DA6"> |
|
|
|
<font color="#ffffff" face="arial,helvetica,sanserif"> |
|
|
|
<strong> |
|
|
|
I want to execute a particular target only if |
|
|
|
multiple conditions are true. |
|
|
|
</strong> |
|
|
|
</font> |
|
|
|
</td></tr> |
|
|
|
<tr><td> |
|
|
|
<blockquote> |
|
|
|
<p>There are actually several answers to this question.</p> |
|
|
|
<p>If you have only one set and one unset property to test, |
|
|
|
you can put both an <code>if</code> and an <code>unless</code> |
|
|
|
attribute into the target. The target will act as if they |
|
|
|
are "anded" together.</p> |
|
|
|
<p>If you are using a version of Ant 1.3 or earlier, the |
|
|
|
way to work with all other cases is to chain targets together |
|
|
|
to determine the specific state you wish to test for.</p> |
|
|
|
<p>To see how this works, assume you have three properties, |
|
|
|
<code>prop1</code>, <code>prop2</code>, and <code>prop3</code>. |
|
|
|
You want to test that <code>prop1</code> and <code>prop2</code> |
|
|
|
are set, but that <code>prop3</code> is not. If the condition |
|
|
|
holds true you want to echo "yes".</p> |
|
|
|
<p>Here is the implementation in Ant 1.3 and earlier:</p> |
|
|
|
<div align="left"> |
|
|
|
<table cellspacing="4" cellpadding="0" border="0"> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#ffffff"><pre> |
|
|
|
<target name="cond" depends="cond-if"/> |
|
|
|
|
|
|
|
<target name="cond-if" if="prop1"> |
|
|
|
<antcall target="cond-if-2"/> |
|
|
|
</target> |
|
|
|
|
|
|
|
<target name="cond-if-2" if="prop2"> |
|
|
|
<antcall target="cond-if-3"/> |
|
|
|
</target> |
|
|
|
|
|
|
|
<target name="cond-if-3" unless="prop3"> |
|
|
|
<echo message="yes"/> |
|
|
|
</target> |
|
|
|
</pre></td> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<p>Note that <code><antcall></code> tasks do not pass |
|
|
|
property changes back up to the environment they were called |
|
|
|
from.</p> |
|
|
|
<p>Starting with Ant 1.4, you can use the |
|
|
|
<code><condition></code> task.</p> |
|
|
|
<div align="left"> |
|
|
|
<table cellspacing="4" cellpadding="0" border="0"> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#ffffff"><pre> |
|
|
|
<target name="cond" depends="cond-if,cond-else"/> |
|
|
|
|
|
|
|
<target name="check-cond"> |
|
|
|
<condition property="cond-is-true"> |
|
|
|
<and> |
|
|
|
<not> |
|
|
|
<equals arg1="${prop1}" arg2="$${prop1}" /> |
|
|
|
</not> |
|
|
|
<not> |
|
|
|
<equals arg1="${prop2}" arg2="$${prop2}" /> |
|
|
|
</not> |
|
|
|
<equals arg1="${prop3}" arg2="$${prop3}" /> |
|
|
|
</and> |
|
|
|
</condition> |
|
|
|
</target> |
|
|
|
|
|
|
|
<target name="cond-if" depends="check-cond" if="cond-is-true"> |
|
|
|
<echo message="yes"/> |
|
|
|
</target> |
|
|
|
|
|
|
|
<target name="cond-else" depends="check-cond" unless="cond-is-true"> |
|
|
|
<echo message="no"/> |
|
|
|
</target> |
|
|
|
</pre></td> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<p>This version takes advantage of two things:</p> |
|
|
|
<ul> |
|
|
|
<li>If a property <code>a</code> has not been set, |
|
|
|
<code>${a}</code> will evaluate to <code>${a}</code>.</li> |
|
|
|
|
|
|
|
<li>To get a literal <code>$</code> in Ant, you have to |
|
|
|
escape it with another <code>$</code> - this will also break |
|
|
|
the special treatment of the sequence <code>${</code>.</li> |
|
|
|
</ul> |
|
|
|
<p>This is neither readable, nor easy to understand, therefore |
|
|
|
post-1.4.1 Ant introduces the <code><isset></code> element |
|
|
|
to the <code><condition></code> task.</p> |
|
|
|
<p>Here is the previous example done using |
|
|
|
<code><isset></code>:</p> |
|
|
|
<div align="left"> |
|
|
|
<table cellspacing="4" cellpadding="0" border="0"> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#ffffff"><pre> |
|
|
|
<target name="check-cond"> |
|
|
|
<condition property="cond-is-true"> |
|
|
|
<and> |
|
|
|
<isset property="prop1"/> |
|
|
|
<isset property="prop2"/> |
|
|
|
<not> |
|
|
|
<isset property="prop3"/> |
|
|
|
</not> |
|
|
|
</and> |
|
|
|
</condition> |
|
|
|
</target> |
|
|
|
</pre></td> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<p>The last option is to use a scripting language to set the |
|
|
|
properties. This can be particularly handy when you need much |
|
|
|
better control than the simple conditions shown here, but of |
|
|
|
course comes with the overhead of adding JAR files to support |
|
|
|
the language, to say nothing of the added maintenance in requiring |
|
|
|
two languages to implement a single system.</p> |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="stop-dependency"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
|
<tr><td bgcolor="#828DA6"> |
|
|
|
<font color="#ffffff" face="arial,helvetica,sanserif"> |
|
|
|
<strong> |
|
|
|
I have a target I want to skip if a variable is set, |
|
|
|
so I have <code>unless="variable"</code> as an attribute |
|
|
|
of the target. The trouble is that all of the targets that this target |
|
|
|
depends on are still executed. Why? |
|
|
|
</strong> |
|
|
|
</font> |
|
|
|
</td></tr> |
|
|
|
<tr><td> |
|
|
|
<blockquote> |
|
|
|
<p>The list of dependencies is generated by Ant before any of the |
|
|
|
targets are run. This allows dependent targets such as an |
|
|
|
<code>init</code> target to set properties that can control the |
|
|
|
execution of the targets higher in the dependency graph. This |
|
|
|
is a good thing.</p> |
|
|
|
<p>When your dependencies actually break down the higher level task |
|
|
|
into several simpler steps, though, this behaviour becomes |
|
|
|
counterintuitive. There are a couple of solutions available: |
|
|
|
</p> |
|
|
|
<ol> |
|
|
|
<li>Put the same condition on each of the dependent targets.</li> |
|
|
|
|
|
|
|
<li>Execute the steps using <code><antcall></code> |
|
|
|
instead of specifying them inside the <code>depends</code> |
|
|
|
attribute.</li> |
|
|
|
</ol> |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="include-order"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
|
<tr><td bgcolor="#828DA6"> |
|
|
|
<font color="#ffffff" face="arial,helvetica,sanserif"> |
|
|
|
<strong> |
|
|
|
In my fileset, I've put in an |
|
|
|
<code><exclude></code> of all files followed by an |
|
|
|
<code><include></code> of just the files I want, but it |
|
|
|
isn't giving me anything at all. What's wrong? |
|
|
|
|
|
|
|
</strong> |
|
|
|
</font> |
|
|
|
</td></tr> |
|
|
|
<tr><td> |
|
|
|
<blockquote> |
|
|
|
<p>The order of the <code><include></code> and |
|
|
|
<code><exclude></code> tags within a fileset is ignored |
|
|
|
when the fileset is created. Instead, all of the |
|
|
|
<code><include></code> elements are processed together, |
|
|
|
followed by all of the <code><exclude></code> |
|
|
|
elements. This means that the <code><exclude></code> |
|
|
|
elements only apply to the file list produced by the |
|
|
|
<code><include></code> elements.</p> |
|
|
|
<p>To get the files you want, focus on just the |
|
|
|
<code><include></code> patterns that would be necessary |
|
|
|
to get them. If you need to trim the list that the includes |
|
|
|
would produce, use excludes.</p> |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="integration"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
@@ -1297,6 +1547,54 @@ ant -listener BuildMonitor |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="listener-properties"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
|
<tr><td bgcolor="#828DA6"> |
|
|
|
<font color="#ffffff" face="arial,helvetica,sanserif"> |
|
|
|
<strong> |
|
|
|
How do I get at the properties that Ant was running |
|
|
|
with from inside BuildListener? |
|
|
|
</strong> |
|
|
|
</font> |
|
|
|
</td></tr> |
|
|
|
<tr><td> |
|
|
|
<blockquote> |
|
|
|
<p>You can get at a hashtable with all the properties that Ant |
|
|
|
has been using through the BuildEvent parameter. For |
|
|
|
example:</p> |
|
|
|
<div align="left"> |
|
|
|
<table cellspacing="4" cellpadding="0" border="0"> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#ffffff"><pre> |
|
|
|
public void buildFinished(BuildEvent e) { |
|
|
|
Hashtable table = e.getProject().getProperties(); |
|
|
|
String buildpath = (String)table.get("build.path"); |
|
|
|
... |
|
|
|
} |
|
|
|
</pre></td> |
|
|
|
<td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
<td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td> |
|
|
|
</tr> |
|
|
|
</table> |
|
|
|
</div> |
|
|
|
<p>This is more accurate than just reading the same property |
|
|
|
files that your project does, since it will give the correct |
|
|
|
results for properties that are specified on the command line |
|
|
|
when running Ant.</p> |
|
|
|
</blockquote> |
|
|
|
</td></tr> |
|
|
|
</table> |
|
|
|
</a> |
|
|
|
<a name="remove-cr"> |
|
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%"> |
|
|
|