ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Martin <antu...@gmail.com>
Subject Re: Basic question re Antform and conditional execution of tasks
Date Fri, 26 Feb 2010 10:09:28 GMT
Hello,

Indeed, if your 'Omit_Optional_Partx'  targets are not part of any
depends attribute, they will not get called.
You should probably have something like:

<target name="buildall" depends="verify_switches, Omit_Optional_Part1,
Omit_Optional_Part2, Omit_Optional_Part3">
...
</target>
<target name="verify_switches" description="Let the user choose which
content to omit.">
...
</target>
<target name="Omit_Optional_Part1" description="Omit optional part 1"
if="omit.optional.part1">
...
</target>
<target name="Omit_Optional_Part2" description="Omit optional part 2"
if="omit.optional.part2">
...
</target>
<target name="Omit_Optional_Part3" description="Omit optional part 3"
if="omit.optional.part3">
...
</target>

Rgds,

Patrick

On Thu, Feb 25, 2010 at 6:43 PM, Rhino <rhino1@sympatico.ca> wrote:
> Thank you, Patrick, for your helpful suggestion. I've changed to a
> booleanProperty. Unfortunately, my script still doesn't work. The
> 'verify_switches' target now looks like the following and everything else is
> the same:
>
> <!--   Let the user choose to show or hide specific items. -->
> <target name="verify_switches" description="Let the user choose which
> content to omit.">
>   <antform title="Choose Information Which Will Not Be Displayed">
>       <label>Use the checkboxes to control which of the following content is
> shown. Choose Abort to cancel the build.</label>
>       <booleanProperty label="Omit Optional Part 1"
> property="omit.optional.part1"/>
>       <booleanProperty label="Omit Optional Part 2"
> property="omit.optional.part2"/>
>       <booleanProperty label="Omit Optional Part 3"
> property="omit.optional.part3"/>
>       <controlbar>
>           <button label="Abort" target="abort2" type="cancel"/>
>           <button label="Ok" type="ok"/>
>           </controlbar>
>   </antform>
> </target>
>
> When I run the script with -debug and -verbose in effect and check only the
> middle checkbox from the AntForm, it indicates:
>
>   Overriding previous definition of property "omit.optional.part2"
>
> However, the 'Omit_Optional_Part2' task is NOT executed. Am I using the
> 'depends' or 'if' parameters incorrectly? Also, why does it say that the
> previous definition of omit.optional.part2 is being overridden? I thought I
> was _creating_ that property as the AntForm was being executed but that
> wording suggests that it already existed and just had its value changed.
>
> As I said in my earlier note, I am VERY rusty with Ant. I fear that I am not
> remembering the proper use of 'depends' and 'if'. Or do I need to put the
> 'Omit_Optional_Partx' targets in the 'buildall' target and then rely on the
> depends/if to bypass those targets if the property was not set in tne
> AntForm?
>
> I think we're on the right track here but I just need a little more
> information in order to get this working correctly.
> --
> Rhino
>
>
> Patrick Martin wrote:
>>
>> Hello,
>>
>> You probably want to use a booleanProperty instead of a
>> checkSelectionProperty.
>>
>> The checkSelectionProperty allows to select multiple values (you use
>> it only for one). It always set the property (even if empty), so your
>> <target if=""> statements will get executed as they test the property
>> existence and not value.
>> You could still go with checkSelectionProperty, using an antcontrib
>> <for> or <foreach> to loop on the result list.
>> But it might be easier to just go with booleanProperty.
>>
>> Rgds,
>>
>> Patrick
>>
>> On Thu, Feb 25, 2010 at 12:41 AM, Rhino <rhino1@sympatico.ca> wrote:
>>
>>>
>>> I was reasonably comfortable with Ant a few years ago but haven't touched
>>> it
>>> in quite a while so I need a bit of a refresher. I've tried looking in
>>> the
>>> manua but it always seems to answer only part of the question so I
>>> thought
>>> I'd try here.
>>>
>>> Among the things that my Ant script needs to do is write a specific
>>> document. That document has three optional parts, each of which the
>>> person
>>> running the script may choose to write or omit. I'm leaning toward using
>>> an
>>> Ant form with a checkSelectionProperty for each of the three optional
>>> parts.
>>>
>>> The relevant bit of my script is:
>>>
>>>
>>> =====================================================================================
>>> <!--   Let the user choose to show or hide specific items. -->
>>> <target name="verify_switches" description="Let the user choose which
>>> content to omit.">
>>>  <antform title="Choose Information Which Will Not Be Displayed">
>>>      <label>Use the checkboxes to control which of the following content
>>> is
>>> shown. Choose Abort to cancel the build.</label>
>>>      <checkSelectionProperty label="" property="omit.optional.part1"
>>> values="Omit Optional Part 1"/>
>>>      <checkSelectionProperty label="" property="omit.optional.part2"
>>> values="Omit Optional Part 2"/>
>>>      <checkSelectionProperty label="" property="omit.optional.part3"
>>> values="Omit Optional Part 3"/>
>>>      <controlbar>
>>>          <button label="Abort" target="abort2" type="cancel"/>
>>>          <button label="Ok" type="ok"/>
>>>          </controlbar>
>>>  </antform>
>>> </target>
>>>
>>> <target name="Omit_Optional_Part1" description="Omit optional part 1."
>>> if="omit.optional.part1">
>>>  <replaceregexp file="${baz.src}\${baz.pkg}\ResumeConstants.java"
>>>      match="^[\s]*public static final boolean
>>> SHOW_OPTIONAL_PART1[\s]*=[\s]*([^;]+);[\s]*$"
>>>      replace="    public static final boolean SHOW_OPTIONAL_PART1 =
>>> false;"
>>>      byline="true"/>
>>> </target>
>>>             <target name="Omit_Optional_Part2" description="Omit optional
>>> part 2." if="omit.optional.part2">
>>>  <replaceregexp file="${baz.src}\${baz.pkg}\ResumeConstants.java"
>>>      match="^[\s]*public static final boolean
>>> SHOW_OPTIONAL_PART2[\s]*=[\s]*([^;]+);[\s]*$"
>>>      replace="    public static final boolean SHOW_OPTIONAL_PART2 =
>>> false;"
>>>      byline="true"/>
>>> </target>
>>>                 <target name="Omit_Optional_Part3" description="Omit
>>> optional part 3." if="omit.optional.part3">
>>>  <replaceregexp file="${baz.src}\${baz.pkg}\ResumeConstants.java"
>>>      match="^[\s]*public static final boolean
>>> SHOW_OPTIONAL_PART3[\s]*=[\s]*([^;]+);[\s]*$"
>>>      replace="    public static final boolean SHOW_OPTIONAL_PART3 =
>>> false;"
>>>      byline="true"/>
>>> </target>
>>>                 <target name="abort2" description="Display a message
that
>>> the build was cancelled.">
>>>  <fail message="The user chose not to proceed with the build."/>
>>> </target>
>>>
>>>
>>> =====================================================================================
>>>
>>> The "verify_switches" target is part of the "depends" on my 'buildall'
>>> target.
>>>
>>> What I'm TRYING to do is get the form to display three separate
>>> checkboxes.
>>> Each checkbox identifies a different one of the three optional parts of
>>> the
>>> document. The user puts a checkmark beside each of the optional parts
>>> that
>>> he wants to OMIT in the document; if he doesn't put a checkmark beside a
>>> given part, that part will be written in the document. For each checkbox
>>> that is checked, a new property is created
>>>
>>> Then, the other three targets, Omit_Optional_Part1, Omit_Optional_Part2,
>>> and
>>> Omit_Optional_Part3 are supposed to be invoked but ONLY if the relevant
>>> checkbox was checked on the AntForm. The three "omit" targets simply edit
>>> a
>>> class containing constants and change the value of one boolean each from
>>> true, the default, to false. In other words, if the user chooses to omit
>>> part 1 from the document, the "Omit_Optional_Part1" target changes a
>>> constant named SHOW_OPTIONAL_PART1 from true to false. And so on for the
>>> other two "optional" targets.
>>>
>>> Unfortunately, this code doesn't work. While the AntForm displays just
>>> fine,
>>> it doesn't seem to be creating the relevant properties. Or maybe it is
>>> and
>>> the "optional" targets just aren't coded correctly. The fact is that the
>>> the
>>> "optional" targets sometimes run regardless of the existence of the
>>> properties created in the form and sometimes DON'T run, even if the
>>> property
>>> should have been created.
>>>
>>> Obviously, I'm doing something wrong but I can't figure it out from the
>>> documentation I've been able to find. AntForm is especially poorly
>>> documented in that it has very few examples and none that illustrate how
>>> to
>>> work with checkSelectionProperty.
>>>
>>> Can someone kindly tell me what I'm doing wrong?
>>>
>>>
>>>
>>> I am running Ant 1.7.1 in Eclipse 3.5.1 (Galileo). My OS is Windows XP
>>> SP2.
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message