ANT Condition Conditional if statement - Java

This is a discussion on ANT Condition Conditional if statement - Java ; Your choice of : 1. Modify the project below so that if that when the property doit is assigned then the message "doit" is printed. OR 2. Modify the project below so that if the property of doit is true ...

+ Reply to Thread
Results 1 to 5 of 5

ANT Condition Conditional if statement

  1. Default ANT Condition Conditional if statement

    Your choice of :

    1. Modify the project below so that if that when the property
    doit is assigned then the message "doit" is printed. OR

    2. Modify the project below so that if the property of doit is
    true then the message "doit" is printed, and nothing happens
    otherwise.

    Thanks.


    <project name="inf" default="all" basedir="." >

    <property name="doit" value="true" />

    <target name="go" if="${doit}">
    <echo message="doit"/>
    </target>

    <target name="all">
    <antcall target="go"/>
    </target>

    </project>

  2. Default Re: ANT Condition Conditional if statement

    Do you have a question? Is it a quest or a competition? Do you think you are
    able to demand solutions?

    Or do you simply not understand the description in the manual
    (http://ant.apache.org/manual/using.html#targets) ?

    If the latter is the case RTFM! Understand that "if" and "unless" do not
    check the value of the property only whether the property is set or not.

    A hint for you - apart from reading documentation - is to use commandline
    properties: "ant -Ddoit=doit"

    /nobody important

    "GIMME" <gimme_this_gimme_that@yahoo.com> wrote in message
    news:3f12b4fb.0404231441.7f6e3678@posting.google.com...
    > Your choice of :
    >
    > 1. Modify the project below so that if that when the property
    > doit is assigned then the message "doit" is printed. OR
    >
    > 2. Modify the project below so that if the property of doit is
    > true then the message "doit" is printed, and nothing happens
    > otherwise.
    >
    > Thanks.
    >
    >
    > <project name="inf" default="all" basedir="." >
    >
    > <property name="doit" value="true" />
    >
    > <target name="go" if="${doit}">
    > <echo message="doit"/>
    > </target>
    >
    > <target name="all">
    > <antcall target="go"/>
    > </target>
    >
    > </project>




  3. Default Re: ANT Condition Conditional if statement

    I read the manual, and as I understood it, ANT was not behaving
    like like the manual said it should.

    I did experiment with it, as the manual describes, checking whether or
    not *ANT properties* are set. It didn't work. I didn't even occur
    to me to use command line properties instead.

    The propose of writing the question the way I did was to make it
    easy for someone to provide a useful response.

    Also, it makes it so that anyone else having the same question
    who searches on Google can find a working example.


    > Do you have a question? Is it a quest or a competition? Do you think you are
    > able to demand solutions?


  4. Default Re: ANT Condition Conditional if statement

    Well, did you get it to work for you?


    "GIMME" <gimme_this_gimme_that@yahoo.com> wrote in message
    news:3f12b4fb.0404260844.676abdd7@posting.google.com...
    > I read the manual, and as I understood it, ANT was not behaving
    > like like the manual said it should.
    >


    No, ANT is just implemented that way - IMHO: really annoying. And you
    cannot - in strict ANT - reset a property. And yes, IMHO, the manual is not
    the quality of a bestseller, but neither are "man"-pages.

    Your problem with ANT properties, whether they are set or not would possibly
    be solved by considering the ANT property-holder as a modified
    java.util.Properties (in which you cannot put already existing properties) -
    an Ant property is set if it exist within the Properties - that is,
    Properties.getProperty("propertyName") does not return null. You could use
    Properties.containsKey("propertyName") for better understanding.

    That is: ANT's " if='doit' " equals "Does the project in this Ant-file
    contain a property key called 'doit' ?"
    It's not: "Does the project in this Ant-file contain a property key called
    'doit' and is the text value of that property 'true' " as there's no reason
    to assume need of parsing any property for arbitrary values in specific
    types: int, boolean, double.

    The great fun is when you set a property to "false" and later, someone else
    is trying to understand what the script is doing, misses the point, that a
    property set to "false" (notice the "set to" here) means the property is
    actually set, and any " if = 'property' " will be executed.

    > I did experiment with it, as the manual describes, checking whether or
    > not *ANT properties* are set. It didn't work. I didn't even occur
    > to me to use command line properties instead.
    >
    > The propose of writing the question the way I did was to make it
    > easy for someone to provide a useful response.
    >
    > Also, it makes it so that anyone else having the same question
    > who searches on Google can find a working example.
    >
    >
    > > Do you have a question? Is it a quest or a competition? Do you think you

    are
    > > able to demand solutions?


    /nobody important



  5. Default Re: ANT Condition Conditional if statement

    My ant build file looks like this:

    <!-- build.xml -->
    <project name="TestIf" default="TestIf">
    <target name="Initialize">
    <condition property="isAuto">
    <isset property="buildLabel" />
    </condition>
    <echo>isAuto: ${isAuto}</echo>
    </target>

    <target name="TestIf" depends="Initialize" if="${isAuto}">
    <echo>buildLabel: ${buildLabel}</echo>
    </target>
    </project>


    I use ant from command line like this:
    ant -f build.xml -DbuildLabel=2.6.4

    For some reason, the echo statement inside target "TestIf" never gets executed. I even tried doing this (but in vain):

    <target name="TestIf" depends="Initialize" if="${buildLabel}">
    ...
    </target>


    I have tried every possible link (including the Apache ant documentation) to look for a solution. Somehow, I am unable to find a solution. I am using ant version 1.7.1

    Can you please let me know what am I doing wrong?

    Thanks

+ Reply to Thread

Similar Threads

  1. Can we use break statement in conditional operator?
    By Application Development in forum C
    Replies: 6
    Last Post: 10-30-2007, 07:31 AM
  2. Re: Conditional wait statement in a verilog testbench
    By Application Development in forum verilog
    Replies: 2
    Last Post: 09-21-2007, 12:49 PM
  3. Additional condition in IF statement doesn't work
    By Application Development in forum verilog
    Replies: 4
    Last Post: 05-19-2007, 02:25 AM
  4. Replies: 5
    Last Post: 04-19-2007, 02:38 PM
  5. Conditional statement to generate HTML?
    By Application Development in forum Perl
    Replies: 3
    Last Post: 07-18-2004, 03:57 AM