jhm 2003/12/09 08:52:14 Modified: xdocs Tag: ANT_16_BRANCH faq.xml docs Tag: ANT_16_BRANCH faq.html Log: Sync with HEAD Revision Changes Path No revision No revision 1.38.2.6 +81 -63 ant/xdocs/faq.xml Index: faq.xml =================================================================== RCS file: /home/cvs/ant/xdocs/faq.xml,v retrieving revision 1.38.2.5 retrieving revision 1.38.2.6 diff -u -r1.38.2.5 -r1.38.2.6 --- faq.xml 13 Oct 2003 15:28:36 -0000 1.38.2.5 +++ faq.xml 9 Dec 2003 16:52:13 -0000 1.38.2.6 @@ -11,7 +11,7 @@ <question>Where do I find the latest version of this document?</question> <answer> - <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> </answer> </faq> @@ -19,12 +19,12 @@ <faq id="adding-faqs"> <question>How can I contribute to this FAQ?</question> <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> document. If you want to add a new question, please submit a patch against this document to one of Ant's mailing lists; hopefully, the structure is self-explanatory.</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> @@ -36,7 +36,7 @@ FAQ?</question> <answer> - <p>We use + <p>We use <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a> to render the HTML version from the original XML file.</p> @@ -73,8 +73,8 @@ <p>According to Ant's original author, James Duncan Davidson, the name is an acronym for "Another Neat 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 "ants are very small and can carry a weight dozens of times their own" - describing what Ant is intended to @@ -320,7 +320,7 @@ <source><![CDATA[ shell-prompt> m4 foo.m4 > foo ]]></source> - + <p>and try to translate it into</p> <source><![CDATA[ @@ -334,7 +334,7 @@ <p>This will not do what you expect. The output redirection is performed by your shell, not the command itself, so this should read:</p> - + <source><![CDATA[ <exec executable="/bin/sh"> <arg value="-c" /> @@ -398,7 +398,7 @@ <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> + You want to test that <code>prop1</code> and <code>prop2</code> are set, and that <code>prop3</code> is not. If the condition holds true you want to echo "yes".</p> @@ -470,8 +470,8 @@ <p>Because testing for a literal <code>${property}</code> string isn't all that readable or easy to understand, - post-1.4.1 Ant introduces the <code><isset></code> element - to the <code><condition></code> task.</p> + 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> @@ -501,7 +501,7 @@ details.</p> </answer> </faq> - + <faq id="encoding"> <question>How can I include national characters like German umlauts in my build file?</question> @@ -510,7 +510,7 @@ <p>You need to tell the XML parser which character encoding your build file uses, this is done inside the <a 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 encoding instead of your platform's default. For most Western @@ -540,6 +540,24 @@ necessary.</p> </answer> </faq> + + <faq id="propertyvalue-as-name-for-property"> + <question>How can I do something like <code><property name="prop" + value="${${anotherprop}}"/></code> (double expanding the property)?</question> + + <answer> + <p>Without any external help you can not.</p> + <p>With <script/>, 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> + <propertycopy name="prop" from="${anotherprop}"/></code>.</p> + </answer> + </faq> </faqsection> <faqsection title="It doesn't work (as expected)"> @@ -593,7 +611,7 @@ <p>Here's what you probably did:</p> - <source><![CDATA[ + <source><![CDATA[ <delete> <fileset dir="${build.src}" includes="**/vssver.scc"/> </delete> @@ -601,13 +619,13 @@ <p>You need to switch off the default exclusions, and it will work:</p> - <source><![CDATA[ + <source><![CDATA[ <delete> <fileset dir="${build.src}" includes="**/vssver.scc" defaultexcludes="no"/> </delete> ]]></source> - + <p>For a complete listing of the patterns that are excluded by default, see <a href="manual/dirtasks.html#defaultexcludes">the user manual</a>.</p> @@ -617,34 +635,34 @@ <faq id="stop-dependency"> <question>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?</question> <answer> <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 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: </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> - + </answer> </faq> - + <faq id="include-order"> <question>In my <code><fileset></code>, I've put in an <code><exclude></code> of all files followed by an @@ -662,14 +680,14 @@ 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 find you need to trim the list that the - <code><include></code> elements produce, then use - <code><exclude></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 find you need to trim the list that the + <code><include></code> elements produce, then use + <code><exclude></code> elements.</p> </answer> </faq> - + <faq id="properties-not-trimmed"> <question><code>ant</code> failed to build my program via javac even when I put the needed jars in an external @@ -718,7 +736,7 @@ <faq id="integration"> <question>Is Ant supported by my IDE/Editor?</question> <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> </answer> </faq> @@ -740,10 +758,10 @@ <source><![CDATA[ # 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> <p>Alternatively, you can add the following snippet to your @@ -753,10 +771,10 @@ <source><![CDATA[ (require 'compile) (setq compilation-error-regexp-alist - (append (list + (append (list ;; works for jikes '("^\\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)) compilation-error-regexp-alist)) ]]></source> @@ -774,16 +792,16 @@ # $|=1; 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> @@ -805,7 +823,7 @@ <ul> <li>It doesn't know about required attributes. Only manual tweaking of this file can help here.</li> - + <li>It is not complete - if you add new tasks via <code><taskdef></code> it won't know about it. See <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this @@ -911,7 +929,7 @@ BuildListener that sends out an email in the buildFinished() method. Will Glozer <[EMAIL PROTECTED]> 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> <source><![CDATA[ @@ -954,13 +972,13 @@ public void buildFinished(BuildEvent e) { Throwable th = e.getException(); String status = (th != null) ? "failed" : "succeeded"; - + try { String key = "build." + status; if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) { return; } - + Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); @@ -971,7 +989,7 @@ BufferedReader br = new BufferedReader(new FileReader( props.getProperty("build.log"))); StringWriter sw = new StringWriter(); - + String line = br.readLine(); while (line != null) { sw.write(line); @@ -979,10 +997,10 @@ line = br.readLine(); } br.close(); - + message.setText(sw.toString(), "UTF-8"); sw.close(); - + Transport transport = session.getTransport(); transport.connect(); transport.send(message); @@ -1018,14 +1036,14 @@ public void targetFinished(BuildEvent e) { } - public void taskStarted(BuildEvent e) { + public void taskStarted(BuildEvent e) { } public void taskFinished(BuildEvent e) { } } ]]></source> - + <p>With a <code>monitor.properties</code> like this:</p> <source><![CDATA[ @@ -1049,13 +1067,13 @@ <p><code>monitor.properties</code> should be placed right next to your compiled <code>BuildMonitor.class</code>. To use it, invoke Ant like:</p> - + <source><![CDATA[ ant -listener BuildMonitor -logfile build.log ]]></source> <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 Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p> @@ -1084,7 +1102,7 @@ results for properties that were specified on the Ant command line.</p> </answer> </faq> - + </faqsection> <faqsection title="Known Problems"> @@ -1119,7 +1137,7 @@ <faq id="delegating-classloader"> <question><style> or <junit> ignores my <classpath></question> - + <answer> <p>These tasks don't ignore your classpath setting, you are facing a common problem with delegating classloaders.</p> @@ -1318,4 +1336,4 @@ </faqsection> -</document> +</document> \ No newline at end of file No revision No revision 1.77.2.6 +66 -47 ant/docs/faq.html Index: faq.html =================================================================== RCS file: /home/cvs/ant/docs/faq.html,v retrieving revision 1.77.2.5 retrieving revision 1.77.2.6 diff -u -r1.77.2.5 -r1.77.2.6 --- faq.html 13 Oct 2003 15:28:36 -0000 1.77.2.5 +++ faq.html 9 Dec 2003 16:52:13 -0000 1.77.2.6 @@ -237,6 +237,10 @@ How do I use <code>jar</code>'s <code>M</code> switch? I don't want a MANIFEST. </a></li> + <li><a href="#propertyvalue-as-name-for-property"> + How can I do something like <code><property name="prop" + value="${${anotherprop}}"/></code> (double expanding the property)? + </a></li> </ul> <h4 class="toc">It doesn't work (as expected)</h4> <ul> @@ -251,8 +255,8 @@ </a></li> <li><a href="#stop-dependency"> 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? </a></li> <li><a href="#include-order"> @@ -337,13 +341,13 @@ Where do I find the latest version of this document? </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> <p class="faq"> <a name="adding-faqs"></a> How can I contribute to this FAQ? </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> document. If you want to add a new question, please submit a patch against this document to one of Ant's mailing lists; @@ -356,7 +360,7 @@ How do you create the HTML version of this FAQ? </p> - <p>We use + <p>We use <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a> to render the HTML version from the original XML file.</p> <p>The Velocity stylesheets used to process the XML files can @@ -383,7 +387,7 @@ <p>According to Ant's original author, James Duncan Davidson, the name is an acronym for "Another Neat 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 "ants are very small and can carry a weight dozens of times their own" - describing what Ant is intended to @@ -744,7 +748,7 @@ to determine the specific state you want 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> + You want to test that <code>prop1</code> and <code>prop2</code> are set, and 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> @@ -808,8 +812,8 @@ </ul> <p>Because testing for a literal <code>${property}</code> string isn't all that readable or easy to understand, - post-1.4.1 Ant introduces the <code><isset></code> element - to the <code><condition></code> task.</p> + 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> <pre class="code"> @@ -863,6 +867,21 @@ <code><zip></code> uses your platforms default encoding. Use the encoding attribute of <code><zip></code> if necessary.</p> + <p class="faq"> + <a name="propertyvalue-as-name-for-property"></a> + How can I do something like <code><property name="prop" + value="${${anotherprop}}"/></code> (double expanding the property)? + </p> + <p>Without any external help you can not.</p> + <p>With <script/>, which needs external libraries, you can do</p> + <pre class="code"> +<script language="javascript"> + propname = project.getProperty("anotherprop"); + project.setNewProperty("prop", propname); +</script> +</pre> + <p>With AntContrib (external task library) you can do <code> + <propertycopy name="prop" from="${anotherprop}"/></code>.</p> <p class="faq"> <a name="always-recompiles"></a> Why does Ant always recompile all my Java files? @@ -921,23 +940,23 @@ <p class="faq"> <a name="stop-dependency"></a> 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? </p> <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 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: </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> @@ -959,10 +978,10 @@ 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 find you need to trim the list that the - <code><include></code> elements produce, then use - <code><exclude></code> elements.</p> + <code><include></code> patterns that would be necessary + to get them. If you find you need to trim the list that the + <code><include></code> elements produce, then use + <code><exclude></code> elements.</p> <p class="faq"> <a name="properties-not-trimmed"></a> <code>ant</code> failed to build my program via javac @@ -999,7 +1018,7 @@ <a name="integration"></a> Is Ant supported by my IDE/Editor? </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> <p class="faq"> <a name="emacs-mode"></a> @@ -1016,10 +1035,10 @@ <code>.antrc</code> (contributed by Ville Skyttä).</p> <pre class="code"> # 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 </pre> <p>Alternatively, you can add the following snippet to your <code>.emacs</code> to make Emacs understand Ant's @@ -1027,10 +1046,10 @@ <pre class="code"> (require 'compile) (setq compilation-error-regexp-alist - (append (list + (append (list ;; works for jikes '("^\\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)) compilation-error-regexp-alist)) </pre> @@ -1046,16 +1065,16 @@ # $|=1; 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; }; </pre> <p class="faq"> @@ -1069,7 +1088,7 @@ <ul> <li>It doesn't know about required attributes. Only manual tweaking of this file can help here.</li> - + <li>It is not complete - if you add new tasks via <code><taskdef></code> it won't know about it. See <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this @@ -1159,7 +1178,7 @@ BuildListener that sends out an email in the buildFinished() method. Will Glozer <[EMAIL PROTECTED]> 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> <pre class="code"> import java.io.*; @@ -1201,13 +1220,13 @@ public void buildFinished(BuildEvent e) { Throwable th = e.getException(); String status = (th != null) ? "failed" : "succeeded"; - + try { String key = "build." + status; if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) { return; } - + Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); @@ -1218,7 +1237,7 @@ BufferedReader br = new BufferedReader(new FileReader( props.getProperty("build.log"))); StringWriter sw = new StringWriter(); - + String line = br.readLine(); while (line != null) { sw.write(line); @@ -1226,10 +1245,10 @@ line = br.readLine(); } br.close(); - + message.setText(sw.toString(), "UTF-8"); sw.close(); - + Transport transport = session.getTransport(); transport.connect(); transport.send(message); @@ -1265,7 +1284,7 @@ public void targetFinished(BuildEvent e) { } - public void taskStarted(BuildEvent e) { + public void taskStarted(BuildEvent e) { } public void taskFinished(BuildEvent e) { @@ -1297,7 +1316,7 @@ ant -listener BuildMonitor -logfile build.log </pre> <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 Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p> <p class="faq">
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]