Browse Source

How to use propertyvalues as name for properties

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275767 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 21 years ago
parent
commit
903118a6a0
2 changed files with 147 additions and 110 deletions
  1. +66
    -47
      docs/faq.html
  2. +81
    -63
      xdocs/faq.xml

+ 66
- 47
docs/faq.html View File

@@ -239,6 +239,10 @@
<li><a href="#use-zip-instead-of-jar"> <li><a href="#use-zip-instead-of-jar">
How do I use <code>jar</code>'s <code>M</code> switch? How do I use <code>jar</code>'s <code>M</code> switch?
I don't want a MANIFEST. I don't want a MANIFEST.
</a></li>
<li><a href="#propertyvalue-as-name-for-property">
How can I do something like <code>&lt;property name="prop"
value="${${anotherprop}}"/&gt;</code> (double expanding the property)?
</a></li> </a></li>
</ul> </ul>
<h4 class="toc">It doesn't work (as expected)</h4> <h4 class="toc">It doesn't work (as expected)</h4>
@@ -254,8 +258,8 @@
</a></li> </a></li>
<li><a href="#stop-dependency"> <li><a href="#stop-dependency">
I have a target I want to skip if a property is set, I have a target I want to skip if a property is set,
so I have <code>unless="property"</code> as an attribute
of the target, but all the targets this target
so I have <code>unless="property"</code> as an attribute
of the target, but all the targets this target
depends on are still executed. Why? depends on are still executed. Why?
</a></li> </a></li>
<li><a href="#include-order"> <li><a href="#include-order">
@@ -340,13 +344,13 @@
Where do I find the latest version of this Where do I find the latest version of this
document? document?
</p> </p>
<p>The latest version can always be found at Ant's homepage
<p>The latest version can always be found at Ant's homepage
<a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p> <a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p>
<p class="faq"> <p class="faq">
<a name="adding-faqs"></a> <a name="adding-faqs"></a>
How can I contribute to this FAQ? How can I contribute to this FAQ?
</p> </p>
<p>The page you are looking it is generated from
<p>The page you are looking it is generated from
<a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml">this</a> <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml">this</a>
document. If you want to add a new question, please submit document. If you want to add a new question, please submit
a patch against this document to one of Ant's mailing lists; a patch against this document to one of Ant's mailing lists;
@@ -359,7 +363,7 @@
How do you create the HTML version of this How do you create the HTML version of this
FAQ? FAQ?
</p> </p>
<p>We use
<p>We use
<a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a> <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
to render the HTML version from the original XML file.</p> to render the HTML version from the original XML file.</p>
<p>The Velocity stylesheets used to process the XML files can <p>The Velocity stylesheets used to process the XML files can
@@ -386,7 +390,7 @@
<p>According to Ant's original author, James Duncan <p>According to Ant's original author, James Duncan
Davidson, the name is an acronym for "Another Neat Davidson, the name is an acronym for "Another Neat
Tool".</p> Tool".</p>
<p>Later explanations go along the lines of "ants
<p>Later explanations go along the lines of "ants
do an extremely good job at building things", or do an extremely good job at building things", or
"ants are very small and can carry a weight dozens of times "ants are very small and can carry a weight dozens of times
their own" - describing what Ant is intended to their own" - describing what Ant is intended to
@@ -747,7 +751,7 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
to determine the specific state you want to test for.</p> to determine the specific state you want to test for.</p>
<p>To see how this works, assume you have three properties: <p>To see how this works, assume you have three properties:
<code>prop1</code>, <code>prop2</code>, and <code>prop3</code>. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
You want to test that <code>prop1</code> and <code>prop2</code>
You want to test that <code>prop1</code> and <code>prop2</code>
are set, and that <code>prop3</code> is not. If the condition are set, and that <code>prop3</code> is not. If the condition
holds true you want to echo "yes".</p> holds true you want to echo "yes".</p>
<p>Here is the implementation in Ant 1.3 and earlier:</p> <p>Here is the implementation in Ant 1.3 and earlier:</p>
@@ -811,8 +815,8 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
</ul> </ul>
<p>Because testing for a literal <code>${property}</code> string <p>Because testing for a literal <code>${property}</code> string
isn't all that readable or easy to understand, isn't all that readable or easy to understand,
post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
to the <code>&lt;condition&gt;</code> task.</p>
post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
to the <code>&lt;condition&gt;</code> task.</p>
<p>Here is the previous example done using <p>Here is the previous example done using
<code>&lt;isset&gt;</code>:</p> <code>&lt;isset&gt;</code>:</p>
<pre class="code"> <pre class="code">
@@ -866,6 +870,21 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
<code>&lt;zip&gt;</code> uses your platforms default encoding. <code>&lt;zip&gt;</code> uses your platforms default encoding.
Use the encoding attribute of <code>&lt;zip&gt;</code> if Use the encoding attribute of <code>&lt;zip&gt;</code> if
necessary.</p> necessary.</p>
<p class="faq">
<a name="propertyvalue-as-name-for-property"></a>
How can I do something like <code>&lt;property name="prop"
value="${${anotherprop}}"/&gt;</code> (double expanding the property)?
</p>
<p>Without any external help you can not.</p>
<p>With &lt;script/&gt;, which needs external libraries, you can do</p>
<pre class="code">
&lt;script language=&quot;javascript&quot;&gt;
propname = project.getProperty(&quot;anotherprop&quot;);
project.setNewProperty(&quot;prop&quot;, propname);
&lt;/script&gt;
</pre>
<p>With AntContrib (external task library) you can do <code>
&lt;propertycopy name="prop" from="${anotherprop}"/&gt;</code>.</p>
<p class="faq"> <p class="faq">
<a name="always-recompiles"></a> <a name="always-recompiles"></a>
Why does Ant always recompile all my Java files? Why does Ant always recompile all my Java files?
@@ -924,23 +943,23 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
<p class="faq"> <p class="faq">
<a name="stop-dependency"></a> <a name="stop-dependency"></a>
I have a target I want to skip if a property is set, I have a target I want to skip if a property is set,
so I have <code>unless="property"</code> as an attribute
of the target, but all the targets this target
so I have <code>unless="property"</code> as an attribute
of the target, but all the targets this target
depends on are still executed. Why? depends on are still executed. Why?
</p> </p>
<p>The list of dependencies is generated by Ant before any of the <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>
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>However, when your dependencies break down the <p>However, when your dependencies break down the
higher-level task higher-level task
into several smaller steps, this behaviour becomes
into several smaller steps, this behaviour becomes
counter-intuitive. There are a couple of solutions available: counter-intuitive. There are a couple of solutions available:
</p> </p>
<ol> <ol>
<li>Put the same condition on each of the dependent targets.</li> <li>Put the same condition on each of the dependent targets.</li>
<li>Execute the steps using <code>&lt;antcall&gt;</code>, <li>Execute the steps using <code>&lt;antcall&gt;</code>,
instead of specifying them inside the <code>depends</code> instead of specifying them inside the <code>depends</code>
attribute.</li> attribute.</li>
@@ -962,10 +981,10 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
elements only apply to the file list produced by the elements only apply to the file list produced by the
<code>&lt;include&gt;</code> elements.</p> <code>&lt;include&gt;</code> elements.</p>
<p>To get the files you want, focus on just the <p>To get the files you want, focus on just the
<code>&lt;include&gt;</code> patterns that would be necessary
to get them. If you find you need to trim the list that the
<code>&lt;include&gt;</code> elements produce, then use
<code>&lt;exclude&gt;</code> elements.</p>
<code>&lt;include&gt;</code> patterns that would be necessary
to get them. If you find you need to trim the list that the
<code>&lt;include&gt;</code> elements produce, then use
<code>&lt;exclude&gt;</code> elements.</p>
<p class="faq"> <p class="faq">
<a name="properties-not-trimmed"></a> <a name="properties-not-trimmed"></a>
<code>ant</code> failed to build my program via javac <code>ant</code> failed to build my program via javac
@@ -1002,7 +1021,7 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
<a name="integration"></a> <a name="integration"></a>
Is Ant supported by my IDE/Editor? Is Ant supported by my IDE/Editor?
</p> </p>
<p>See the <a href="external.html#IDE and Editor Integration">section
<p>See the <a href="external.html#IDE and Editor Integration">section
on IDE integration</a> on our External Tools and Tasks page.</p> on IDE integration</a> on our External Tools and Tasks page.</p>
<p class="faq"> <p class="faq">
<a name="emacs-mode"></a> <a name="emacs-mode"></a>
@@ -1019,10 +1038,10 @@ shell-prompt&gt; m4 foo.m4 &gt; foo
<code>.antrc</code> (contributed by Ville Skyttä).</p> <code>.antrc</code> (contributed by Ville Skyttä).</p>
<pre class="code"> <pre class="code">
# Detect (X)Emacs compile mode # Detect (X)Emacs compile mode
if [ &quot;$EMACS&quot; = &quot;t&quot; ] ; then
ANT_ARGS=&quot;$ANT_ARGS -emacs&quot;
ANT_OPTS=&quot;$ANT_OPTS -Dbuild.compiler.emacs=true&quot;
fi
if [ &quot;$EMACS&quot; = &quot;t&quot; ] ; then
ANT_ARGS=&quot;$ANT_ARGS -emacs&quot;
ANT_OPTS=&quot;$ANT_OPTS -Dbuild.compiler.emacs=true&quot;
fi
</pre> </pre>
<p>Alternatively, you can add the following snippet to your <p>Alternatively, you can add the following snippet to your
<code>.emacs</code> to make Emacs understand Ant's <code>.emacs</code> to make Emacs understand Ant's
@@ -1030,10 +1049,10 @@ fi
<pre class="code"> <pre class="code">
(require 'compile) (require 'compile)
(setq compilation-error-regexp-alist (setq compilation-error-regexp-alist
(append (list
(append (list
;; works for jikes ;; works for jikes
'(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:&quot; 1 2 3) '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:&quot; 1 2 3)
;; works for javac
;; works for javac
'(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):&quot; 1 2)) '(&quot;^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):&quot; 1 2))
compilation-error-regexp-alist)) compilation-error-regexp-alist))
</pre> </pre>
@@ -1049,16 +1068,16 @@ fi
# #
$|=1; $|=1;
while(&lt;STDIN&gt;) { while(&lt;STDIN&gt;) {
if (s/^(\s+)\[(\w+)\]//) {
if ($2 ne $last) {
print &quot;$1\[$2\]&quot;;
$s = ' ' x length($2);
} else {
print &quot;$1 $s &quot;;
};
$last = $2;
};
print;
if (s/^(\s+)\[(\w+)\]//) {
if ($2 ne $last) {
print &quot;$1\[$2\]&quot;;
$s = ' ' x length($2);
} else {
print &quot;$1 $s &quot;;
};
$last = $2;
};
print;
}; };
</pre> </pre>
<p class="faq"> <p class="faq">
@@ -1072,7 +1091,7 @@ while(&lt;STDIN&gt;) {
<ul> <ul>
<li>It doesn't know about required attributes. Only <li>It doesn't know about required attributes. Only
manual tweaking of this file can help here.</li> manual tweaking of this file can help here.</li>
<li>It is not complete - if you add new tasks via <li>It is not complete - if you add new tasks via
<code>&lt;taskdef&gt;</code> it won't know about it. See <code>&lt;taskdef&gt;</code> it won't know about it. See
<a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
@@ -1162,7 +1181,7 @@ while(&lt;STDIN&gt;) {
BuildListener that sends out an email BuildListener that sends out an email
in the buildFinished() method. Will Glozer in the buildFinished() method. Will Glozer
&lt;will.glozer@jda.com&gt; has written such a listener based &lt;will.glozer@jda.com&gt; has written such a listener based
on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
The source is:</p> The source is:</p>
<pre class="code"> <pre class="code">
import java.io.*; import java.io.*;
@@ -1204,13 +1223,13 @@ public class BuildMonitor implements BuildListener {
public void buildFinished(BuildEvent e) { public void buildFinished(BuildEvent e) {
Throwable th = e.getException(); Throwable th = e.getException();
String status = (th != null) ? &quot;failed&quot; : &quot;succeeded&quot;; String status = (th != null) ? &quot;failed&quot; : &quot;succeeded&quot;;
try { try {
String key = &quot;build.&quot; + status; String key = &quot;build.&quot; + status;
if (props.getProperty(key + &quot;.notify&quot;).equalsIgnoreCase(&quot;false&quot;)) { if (props.getProperty(key + &quot;.notify&quot;).equalsIgnoreCase(&quot;false&quot;)) {
return; return;
} }
Session session = Session.getDefaultInstance(props, null); Session session = Session.getDefaultInstance(props, null);


MimeMessage message = new MimeMessage(session); MimeMessage message = new MimeMessage(session);
@@ -1221,7 +1240,7 @@ public class BuildMonitor implements BuildListener {
BufferedReader br = new BufferedReader(new FileReader( BufferedReader br = new BufferedReader(new FileReader(
props.getProperty(&quot;build.log&quot;))); props.getProperty(&quot;build.log&quot;)));
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
String line = br.readLine(); String line = br.readLine();
while (line != null) { while (line != null) {
sw.write(line); sw.write(line);
@@ -1229,10 +1248,10 @@ public class BuildMonitor implements BuildListener {
line = br.readLine(); line = br.readLine();
} }
br.close(); br.close();
message.setText(sw.toString(), &quot;UTF-8&quot;); message.setText(sw.toString(), &quot;UTF-8&quot;);
sw.close(); sw.close();
Transport transport = session.getTransport(); Transport transport = session.getTransport();
transport.connect(); transport.connect();
transport.send(message); transport.send(message);
@@ -1268,7 +1287,7 @@ public class BuildMonitor implements BuildListener {
public void targetFinished(BuildEvent e) { public void targetFinished(BuildEvent e) {
} }


public void taskStarted(BuildEvent e) {
public void taskStarted(BuildEvent e) {
} }


public void taskFinished(BuildEvent e) { public void taskFinished(BuildEvent e) {
@@ -1300,7 +1319,7 @@ build.succeeded.email.subject=Nightly build succeeded!
ant -listener BuildMonitor -logfile build.log ant -listener BuildMonitor -logfile build.log
</pre> </pre>
<p>Make sure that <code>mail.jar</code> from JavaMail and <p>Make sure that <code>mail.jar</code> from JavaMail and
<code>activation.jar</code> from the
<code>activation.jar</code> from the
<a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p> Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
<p class="faq"> <p class="faq">


+ 81
- 63
xdocs/faq.xml View File

@@ -11,7 +11,7 @@
<question>Where do I find the latest version of this <question>Where do I find the latest version of this
document?</question> document?</question>
<answer> <answer>
<p>The latest version can always be found at Ant&apos;s homepage
<p>The latest version can always be found at Ant&apos;s homepage
<a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p> <a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p>
</answer> </answer>
</faq> </faq>
@@ -19,12 +19,12 @@
<faq id="adding-faqs"> <faq id="adding-faqs">
<question>How can I contribute to this FAQ?</question> <question>How can I contribute to this FAQ?</question>
<answer> <answer>
<p>The page you are looking it is generated from
<p>The page you are looking it is generated from
<a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml">this</a> <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml">this</a>
document. If you want to add a new question, please submit document. If you want to add a new question, please submit
a patch against this document to one of Ant&apos;s mailing lists; a patch against this document to one of Ant&apos;s mailing lists;
hopefully, the structure is self-explanatory.</p> hopefully, the structure is self-explanatory.</p>
<p>If you don&apos;t know how to create a patch, see the patches <p>If you don&apos;t know how to create a patch, see the patches
section of <a href="http://jakarta.apache.org/site/source.html">this section of <a href="http://jakarta.apache.org/site/source.html">this
page</a>.</p> page</a>.</p>
@@ -36,7 +36,7 @@
FAQ?</question> FAQ?</question>


<answer> <answer>
<p>We use
<p>We use
<a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a> <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
to render the HTML version from the original XML file.</p> to render the HTML version from the original XML file.</p>


@@ -73,8 +73,8 @@
<p>According to Ant&apos;s original author, James Duncan <p>According to Ant&apos;s original author, James Duncan
Davidson, the name is an acronym for &quot;Another Neat Davidson, the name is an acronym for &quot;Another Neat
Tool&quot;.</p> Tool&quot;.</p>
<p>Later explanations go along the lines of &quot;ants
<p>Later explanations go along the lines of &quot;ants
do an extremely good job at building things&quot;, or do an extremely good job at building things&quot;, or
&quot;ants are very small and can carry a weight dozens of times &quot;ants are very small and can carry a weight dozens of times
their own&quot; - describing what Ant is intended to their own&quot; - describing what Ant is intended to
@@ -320,7 +320,7 @@
<source><![CDATA[ <source><![CDATA[
shell-prompt> m4 foo.m4 > foo shell-prompt> m4 foo.m4 > foo
]]></source> ]]></source>
<p>and try to translate it into</p> <p>and try to translate it into</p>


<source><![CDATA[ <source><![CDATA[
@@ -334,7 +334,7 @@ shell-prompt> m4 foo.m4 > foo
<p>This will not do what you expect. The output redirection is <p>This will not do what you expect. The output redirection is
performed by your shell, not the command itself, so this performed by your shell, not the command itself, so this
should read:</p> should read:</p>
<source><![CDATA[ <source><![CDATA[
<exec executable="/bin/sh"> <exec executable="/bin/sh">
<arg value="-c" /> <arg value="-c" />
@@ -398,7 +398,7 @@ shell-prompt> m4 foo.m4 > foo


<p>To see how this works, assume you have three properties: <p>To see how this works, assume you have three properties:
<code>prop1</code>, <code>prop2</code>, and <code>prop3</code>. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
You want to test that <code>prop1</code> and <code>prop2</code>
You want to test that <code>prop1</code> and <code>prop2</code>
are set, and that <code>prop3</code> is not. If the condition are set, and that <code>prop3</code> is not. If the condition
holds true you want to echo &quot;yes&quot;.</p> holds true you want to echo &quot;yes&quot;.</p>


@@ -470,8 +470,8 @@ shell-prompt> m4 foo.m4 > foo


<p>Because testing for a literal <code>${property}</code> string <p>Because testing for a literal <code>${property}</code> string
isn&apos;t all that readable or easy to understand, isn&apos;t all that readable or easy to understand,
post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
to the <code>&lt;condition&gt;</code> task.</p>
post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
to the <code>&lt;condition&gt;</code> task.</p>


<p>Here is the previous example done using <p>Here is the previous example done using
<code>&lt;isset&gt;</code>:</p> <code>&lt;isset&gt;</code>:</p>
@@ -501,7 +501,7 @@ shell-prompt> m4 foo.m4 > foo
details.</p> details.</p>
</answer> </answer>
</faq> </faq>
<faq id="encoding"> <faq id="encoding">
<question>How can I include national characters like German <question>How can I include national characters like German
umlauts in my build file?</question> umlauts in my build file?</question>
@@ -510,7 +510,7 @@ shell-prompt> m4 foo.m4 > foo
<p>You need to tell the XML parser which character encoding <p>You need to tell the XML parser which character encoding
your build file uses, this is done inside the <a your build file uses, this is done inside the <a
href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
declaration</a>.</p>
declaration</a>.</p>


<p>By default the parser assumes you are using the UTF-8 <p>By default the parser assumes you are using the UTF-8
encoding instead of your platform&apos;s default. For most Western encoding instead of your platform&apos;s default. For most Western
@@ -540,6 +540,24 @@ shell-prompt> m4 foo.m4 > foo
necessary.</p> necessary.</p>
</answer> </answer>
</faq> </faq>

<faq id="propertyvalue-as-name-for-property">
<question>How can I do something like <code>&lt;property name="prop"
value="${${anotherprop}}"/&gt;</code> (double expanding the property)?</question>

<answer>
<p>Without any external help you can not.</p>
<p>With &lt;script/&gt;, which needs external libraries, you can do</p>
<source><![CDATA[
<script language="javascript">
propname = project.getProperty("anotherprop");
project.setNewProperty("prop", propname);
</script>
]]></source>
<p>With AntContrib (external task library) you can do <code>
&lt;propertycopy name="prop" from="${anotherprop}"/&gt;</code>.</p>
</answer>
</faq>
</faqsection> </faqsection>


<faqsection title="It doesn&apos;t work (as expected)"> <faqsection title="It doesn&apos;t work (as expected)">
@@ -593,7 +611,7 @@ shell-prompt> m4 foo.m4 > foo
<p>Here&apos;s what you probably did:</p> <p>Here&apos;s what you probably did:</p>




<source><![CDATA[
<source><![CDATA[
<delete> <delete>
<fileset dir="${build.src}" includes="**/vssver.scc"/> <fileset dir="${build.src}" includes="**/vssver.scc"/>
</delete> </delete>
@@ -601,13 +619,13 @@ shell-prompt> m4 foo.m4 > foo


<p>You need to switch off the default exclusions, <p>You need to switch off the default exclusions,
and it will work:</p> and it will work:</p>
<source><![CDATA[
<source><![CDATA[
<delete> <delete>
<fileset dir="${build.src}" includes="**/vssver.scc" <fileset dir="${build.src}" includes="**/vssver.scc"
defaultexcludes="no"/> defaultexcludes="no"/>
</delete> </delete>
]]></source> ]]></source>
<p>For a complete listing of the patterns that are excluded <p>For a complete listing of the patterns that are excluded
by default, see <a href="manual/dirtasks.html#defaultexcludes">the user by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
manual</a>.</p> manual</a>.</p>
@@ -617,34 +635,34 @@ shell-prompt> m4 foo.m4 > foo


<faq id="stop-dependency"> <faq id="stop-dependency">
<question>I have a target I want to skip if a property is set, <question>I have a target I want to skip if a property is set,
so I have <code>unless=&quot;property&quot;</code> as an attribute
of the target, but all the targets this target
so I have <code>unless=&quot;property&quot;</code> as an attribute
of the target, but all the targets this target
depends on are still executed. Why?</question> depends on are still executed. Why?</question>


<answer> <answer>
<p>The list of dependencies is generated by Ant before any of the <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>
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>However, when your dependencies break down the <p>However, when your dependencies break down the
higher-level task higher-level task
into several smaller steps, this behaviour becomes
into several smaller steps, this behaviour becomes
counter-intuitive. There are a couple of solutions available: counter-intuitive. There are a couple of solutions available:
</p> </p>


<ol> <ol>
<li>Put the same condition on each of the dependent targets.</li> <li>Put the same condition on each of the dependent targets.</li>
<li>Execute the steps using <code>&lt;antcall&gt;</code>, <li>Execute the steps using <code>&lt;antcall&gt;</code>,
instead of specifying them inside the <code>depends</code> instead of specifying them inside the <code>depends</code>
attribute.</li> attribute.</li>
</ol> </ol>
</answer> </answer>
</faq> </faq>
<faq id="include-order"> <faq id="include-order">
<question>In my <code>&lt;fileset&gt;</code>, I&apos;ve put in an <question>In my <code>&lt;fileset&gt;</code>, I&apos;ve put in an
<code>&lt;exclude&gt;</code> of all files followed by an <code>&lt;exclude&gt;</code> of all files followed by an
@@ -662,14 +680,14 @@ shell-prompt> m4 foo.m4 > foo
elements only apply to the file list produced by the elements only apply to the file list produced by the
<code>&lt;include&gt;</code> elements.</p> <code>&lt;include&gt;</code> elements.</p>


<p>To get the files you want, focus on just the
<code>&lt;include&gt;</code> patterns that would be necessary
to get them. If you find you need to trim the list that the
<code>&lt;include&gt;</code> elements produce, then use
<code>&lt;exclude&gt;</code> elements.</p>
<p>To get the files you want, focus on just the
<code>&lt;include&gt;</code> patterns that would be necessary
to get them. If you find you need to trim the list that the
<code>&lt;include&gt;</code> elements produce, then use
<code>&lt;exclude&gt;</code> elements.</p>
</answer> </answer>
</faq> </faq>
<faq id="properties-not-trimmed"> <faq id="properties-not-trimmed">
<question><code>ant</code> failed to build my program via javac <question><code>ant</code> failed to build my program via javac
even when I put the needed jars in an external even when I put the needed jars in an external
@@ -718,7 +736,7 @@ shell-prompt> m4 foo.m4 > foo
<faq id="integration"> <faq id="integration">
<question>Is Ant supported by my IDE/Editor?</question> <question>Is Ant supported by my IDE/Editor?</question>
<answer> <answer>
<p>See the <a href="external.html#IDE and Editor Integration">section
<p>See the <a href="external.html#IDE and Editor Integration">section
on IDE integration</a> on our External Tools and Tasks page.</p> on IDE integration</a> on our External Tools and Tasks page.</p>
</answer> </answer>
</faq> </faq>
@@ -740,10 +758,10 @@ shell-prompt> m4 foo.m4 > foo


<source><![CDATA[ <source><![CDATA[
# Detect (X)Emacs compile mode # Detect (X)Emacs compile mode
if [ "$EMACS" = "t" ] ; then
ANT_ARGS="$ANT_ARGS -emacs"
ANT_OPTS="$ANT_OPTS -Dbuild.compiler.emacs=true"
fi
if [ "$EMACS" = "t" ] ; then
ANT_ARGS="$ANT_ARGS -emacs"
ANT_OPTS="$ANT_OPTS -Dbuild.compiler.emacs=true"
fi
]]></source> ]]></source>


<p>Alternatively, you can add the following snippet to your <p>Alternatively, you can add the following snippet to your
@@ -753,10 +771,10 @@ fi
<source><![CDATA[ <source><![CDATA[
(require 'compile) (require 'compile)
(setq compilation-error-regexp-alist (setq compilation-error-regexp-alist
(append (list
(append (list
;; works for jikes ;; works for jikes
'("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3) '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
;; works for javac
;; works for javac
'("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2)) '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
compilation-error-regexp-alist)) compilation-error-regexp-alist))
]]></source> ]]></source>
@@ -774,16 +792,16 @@ fi
# #
$|=1; $|=1;
while(<STDIN>) { while(<STDIN>) {
if (s/^(\s+)\[(\w+)\]//) {
if ($2 ne $last) {
print "$1\[$2\]";
$s = ' ' x length($2);
} else {
print "$1 $s ";
};
$last = $2;
};
print;
if (s/^(\s+)\[(\w+)\]//) {
if ($2 ne $last) {
print "$1\[$2\]";
$s = ' ' x length($2);
} else {
print "$1 $s ";
};
$last = $2;
};
print;
}; };
]]></source> ]]></source>


@@ -805,7 +823,7 @@ while(<STDIN>) {
<ul> <ul>
<li>It doesn&apos;t know about required attributes. Only <li>It doesn&apos;t know about required attributes. Only
manual tweaking of this file can help here.</li> manual tweaking of this file can help here.</li>
<li>It is not complete - if you add new tasks via <li>It is not complete - if you add new tasks via
<code>&lt;taskdef&gt;</code> it won&apos;t know about it. See <code>&lt;taskdef&gt;</code> it won&apos;t know about it. See
<a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
@@ -911,7 +929,7 @@ while(<STDIN>) {
BuildListener that sends out an email BuildListener that sends out an email
in the buildFinished() method. Will Glozer in the buildFinished() method. Will Glozer
&lt;will.glozer@jda.com&gt; has written such a listener based &lt;will.glozer@jda.com&gt; has written such a listener based
on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
The source is:</p> The source is:</p>


<source><![CDATA[ <source><![CDATA[
@@ -954,13 +972,13 @@ public class BuildMonitor implements BuildListener {
public void buildFinished(BuildEvent e) { public void buildFinished(BuildEvent e) {
Throwable th = e.getException(); Throwable th = e.getException();
String status = (th != null) ? "failed" : "succeeded"; String status = (th != null) ? "failed" : "succeeded";
try { try {
String key = "build." + status; String key = "build." + status;
if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) { if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
return; return;
} }
Session session = Session.getDefaultInstance(props, null); Session session = Session.getDefaultInstance(props, null);


MimeMessage message = new MimeMessage(session); MimeMessage message = new MimeMessage(session);
@@ -971,7 +989,7 @@ public class BuildMonitor implements BuildListener {
BufferedReader br = new BufferedReader(new FileReader( BufferedReader br = new BufferedReader(new FileReader(
props.getProperty("build.log"))); props.getProperty("build.log")));
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
String line = br.readLine(); String line = br.readLine();
while (line != null) { while (line != null) {
sw.write(line); sw.write(line);
@@ -979,10 +997,10 @@ public class BuildMonitor implements BuildListener {
line = br.readLine(); line = br.readLine();
} }
br.close(); br.close();
message.setText(sw.toString(), "UTF-8"); message.setText(sw.toString(), "UTF-8");
sw.close(); sw.close();
Transport transport = session.getTransport(); Transport transport = session.getTransport();
transport.connect(); transport.connect();
transport.send(message); transport.send(message);
@@ -1018,14 +1036,14 @@ public class BuildMonitor implements BuildListener {
public void targetFinished(BuildEvent e) { public void targetFinished(BuildEvent e) {
} }


public void taskStarted(BuildEvent e) {
public void taskStarted(BuildEvent e) {
} }


public void taskFinished(BuildEvent e) { public void taskFinished(BuildEvent e) {
} }
} }
]]></source> ]]></source>
<p>With a <code>monitor.properties</code> like this:</p> <p>With a <code>monitor.properties</code> like this:</p>


<source><![CDATA[ <source><![CDATA[
@@ -1049,13 +1067,13 @@ build.succeeded.email.subject=Nightly build succeeded!
<p><code>monitor.properties</code> should be placed right next <p><code>monitor.properties</code> should be placed right next
to your compiled <code>BuildMonitor.class</code>. To use it, to your compiled <code>BuildMonitor.class</code>. To use it,
invoke Ant like:</p> invoke Ant like:</p>
<source><![CDATA[ <source><![CDATA[
ant -listener BuildMonitor -logfile build.log ant -listener BuildMonitor -logfile build.log
]]></source> ]]></source>


<p>Make sure that <code>mail.jar</code> from JavaMail and <p>Make sure that <code>mail.jar</code> from JavaMail and
<code>activation.jar</code> from the
<code>activation.jar</code> from the
<a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p> Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>


@@ -1084,7 +1102,7 @@ public void buildFinished(BuildEvent e) {
results for properties that were specified on the Ant command line.</p> results for properties that were specified on the Ant command line.</p>
</answer> </answer>
</faq> </faq>
</faqsection> </faqsection>


<faqsection title="Known Problems"> <faqsection title="Known Problems">
@@ -1119,7 +1137,7 @@ mv /tmp/foo $ANT_HOME/bin/antRun
<faq id="delegating-classloader"> <faq id="delegating-classloader">
<question>&lt;style&gt; or &lt;junit&gt; ignores my <question>&lt;style&gt; or &lt;junit&gt; ignores my
&lt;classpath&gt;</question> &lt;classpath&gt;</question>
<answer> <answer>
<p>These tasks don&apos;t ignore your classpath setting, you <p>These tasks don&apos;t ignore your classpath setting, you
are facing a common problem with delegating classloaders.</p> are facing a common problem with delegating classloaders.</p>
@@ -1318,4 +1336,4 @@ mv /tmp/foo $ANT_HOME/bin/antRun


</faqsection> </faqsection>


</document>
</document>

Loading…
Cancel
Save