Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 37656 invoked from network); 23 Nov 2001 12:17:31 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 23 Nov 2001 12:17:31 -0000 Received: (qmail 25880 invoked by uid 97); 23 Nov 2001 12:17:19 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 25864 invoked by uid 97); 23 Nov 2001 12:17:18 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 25853 invoked by uid 97); 23 Nov 2001 12:17:18 -0000 Date: 23 Nov 2001 12:01:35 -0000 Message-ID: <20011123120135.8618.qmail@icarus.apache.org> From: bodewig@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/xdocs faq.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bodewig 01/11/23 04:01:35 Modified: docs faq.html xdocs faq.xml Log: add some FAQs. Submitted by: Bruce Atherton Revision Changes Path 1.11 +301 -3 jakarta-ant/docs/faq.html Index: faq.html =================================================================== RCS file: /home/cvs/jakarta-ant/docs/faq.html,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- faq.html 2001/11/22 16:36:27 1.10 +++ faq.html 2001/11/23 12:01:35 1.11 @@ -183,6 +183,23 @@ it doesn't seem to work. The files never get deleted. What's wrong? +
  • + I want to execute a particular target only if + multiple conditions are true. +
  • +
  • + I have a target I want to skip if a variable is set, + so I have unless="variable" as an attribute + of the target. The trouble is that all of the targets that this target + depends on are still executed. Why? +
  • +
  • + In my fileset, I've put in an + <exclude> of all files followed by an + <include> of just the files I want, but it + isn't giving me anything at all. What's wrong? + +
  • @@ -227,6 +244,10 @@ How do I send an email with the result of my build process? +
  • + How do I get at the properties that Ant was running + with from inside BuildListener? +
  • @@ -294,10 +315,12 @@

    The page you are looking it is generated from this - document. If you want to add a new question, please submit - a patch against this document, the structure is hoped to be - self-explaining.

    + a patch against this document to one of Ant's mailing lists, + the structure is hoped to be self-explaining.

    +

    If you don't know how to create a patch, see the patches + section of this + page.

    @@ -853,6 +876,233 @@ + + + + +
    + + + I want to execute a particular target only if + multiple conditions are true. + + +
    +
    +

    There are actually several answers to this question.

    +

    If you have only one set and one unset property to test, + you can put both an if and an unless + attribute into the target. The target will act as if they + are "anded" together.

    +

    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.

    +

    To see how this works, assume you have three properties, + prop1, prop2, and prop3. + You want to test that prop1 and prop2 + are set, but that prop3 is not. If the condition + holds true you want to echo "yes".

    +

    Here is the implementation in Ant 1.3 and earlier:

    +
    + + + + + + + + + + + + + + + + +
      +<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>
      +
    +
    +

    Note that <antcall> tasks do not pass + property changes back up to the environment they were called + from.

    +

    Starting with Ant 1.4, you can use the + <condition> task.

    +
    + + + + + + + + + + + + + + + + +
      +<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>
      +
    +
    +

    This version takes advantage of two things:

    +
      +
    • If a property a has not been set, + ${a} will evaluate to ${a}.
    • + +
    • To get a literal $ in Ant, you have to + escape it with another $ - this will also break + the special treatment of the sequence ${.
    • +
    +

    This is neither readable, nor easy to understand, therefore + post-1.4.1 Ant introduces the <isset> element + to the <condition> task.

    +

    Here is the previous example done using + <isset>:

    +
    + + + + + + + + + + + + + + + + +
      +<target name="check-cond">
      +  <condition property="cond-is-true">
      +    <and>
      +      <isset property="prop1"/>
      +      <isset property="prop2"/>
      +      <not>
      +        <isset property="prop3"/>
      +      </not>
      +    </and>
      +  </condition>
      +</target>
      +
    +
    +

    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.

    +
    +
    +
    + + + + +
    + + + I have a target I want to skip if a variable is set, + so I have unless="variable" as an attribute + of the target. The trouble is that all of the targets that this target + depends on are still executed. Why? + + +
    +
    +

    The list of dependencies is generated by Ant before any of the + targets are run. This allows dependent targets such as an + init target to set properties that can control the + execution of the targets higher in the dependency graph. This + is a good thing.

    +

    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: +

    +
      +
    1. Put the same condition on each of the dependent targets.
    2. + +
    3. Execute the steps using <antcall> + instead of specifying them inside the depends + attribute.
    4. +
    +
    +
    +
    + + + + +
    + + + In my fileset, I've put in an + <exclude> of all files followed by an + <include> of just the files I want, but it + isn't giving me anything at all. What's wrong? + + + +
    +
    +

    The order of the <include> and + <exclude> tags within a fileset is ignored + when the fileset is created. Instead, all of the + <include> elements are processed together, + followed by all of the <exclude> + elements. This means that the <exclude> + elements only apply to the file list produced by the + <include> elements.

    +

    To get the files you want, focus on just the + <include> patterns that would be necessary + to get them. If you need to trim the list that the includes + would produce, use excludes.

    +
    +
    +
    +
    @@ -1294,6 +1544,54 @@ activation.jar from the Java Beans Activation Framework in your CLASSPATH.

    + +
    +
    + + + +
    + + + How do I get at the properties that Ant was running + with from inside BuildListener? + + +
    +
    +

    You can get at a hashtable with all the properties that Ant + has been using through the BuildEvent parameter. For + example:

    +
    + + + + + + + + + + + + + + + + +
      +public void buildFinished(BuildEvent e) {
      +    Hashtable table = e.getProject().getProperties();
      +    String buildpath = (String)table.get("build.path");
      +    ...
      +}
      +
    +
    +

    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.

    1.10 +198 -3 jakarta-ant/xdocs/faq.xml Index: faq.xml =================================================================== RCS file: /home/cvs/jakarta-ant/xdocs/faq.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- faq.xml 2001/11/22 16:36:27 1.9 +++ faq.xml 2001/11/23 12:01:35 1.10 @@ -21,10 +21,13 @@

    The page you are looking it is generated from this - document. If you want to add a new question, please submit - a patch against this document, the structure is hoped to be - self-explaining.

    + a patch against this document to one of Ant's mailing lists, + the structure is hoped to be self-explaining.

    + +

    If you don't know how to create a patch, see the patches + section of this + page.

    @@ -316,6 +319,174 @@ + + + I want to execute a particular target only if + multiple conditions are true. + + +

    There are actually several answers to this question.

    + +

    If you have only one set and one unset property to test, + you can put both an if and an unless + attribute into the target. The target will act as if they + are "anded" together.

    + +

    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.

    + +

    To see how this works, assume you have three properties, + prop1, prop2, and prop3. + You want to test that prop1 and prop2 + are set, but that prop3 is not. If the condition + holds true you want to echo "yes".

    + +

    Here is the implementation in Ant 1.3 and earlier:

    + + + + + + + + + + + + + + +]]> + +

    Note that <antcall> tasks do not pass + property changes back up to the environment they were called + from.

    + +

    Starting with Ant 1.4, you can use the + <condition> task.

    + + + + + + + + + + + + + + + + + + + + + + + + +]]> + +

    This version takes advantage of two things:

    + +
      +
    • If a property a has not been set, + ${a} will evaluate to ${a}.
    • + +
    • To get a literal $ in Ant, you have to + escape it with another $ - this will also break + the special treatment of the sequence ${.
    • +
    + +

    This is neither readable, nor easy to understand, therefore + post-1.4.1 Ant introduces the <isset> element + to the <condition> task.

    + +

    Here is the previous example done using + <isset>:

    + + + + + + + + + + + + +]]> + +

    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.

    +
    +
    + + + I have a target I want to skip if a variable is set, + so I have unless="variable" as an attribute + of the target. The trouble is that all of the targets that this target + depends on are still executed. Why? + + +

    The list of dependencies is generated by Ant before any of the + targets are run. This allows dependent targets such as an + init target to set properties that can control the + execution of the targets higher in the dependency graph. This + is a good thing.

    + +

    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: +

    + +
      +
    1. Put the same condition on each of the dependent targets.
    2. + +
    3. Execute the steps using <antcall> + instead of specifying them inside the depends + attribute.
    4. +
    + +
    +
    + + + In my fileset, I've put in an + <exclude> of all files followed by an + <include> of just the files I want, but it + isn't giving me anything at all. What's wrong? + + + +

    The order of the <include> and + <exclude> tags within a fileset is ignored + when the fileset is created. Instead, all of the + <include> elements are processed together, + followed by all of the <exclude> + elements. This means that the <exclude> + elements only apply to the file list produced by the + <include> elements.

    + +

    To get the files you want, focus on just the + <include> patterns that would be necessary + to get them. If you need to trim the list that the includes + would produce, use excludes.

    +
    +
    + @@ -617,6 +788,30 @@ + + How do I get at the properties that Ant was running + with from inside BuildListener? + + +

    You can get at a hashtable with all the properties that Ant + has been using through the BuildEvent parameter. For + example:

    + + + +

    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.

    +
    +
    +
    -- To unsubscribe, e-mail: For additional commands, e-mail: