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 <rhi...@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-unsubscr...@ant.apache.org > For additional commands, e-mail: user-h...@ant.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional commands, e-mail: user-h...@ant.apache.org