CHAPTER 19 ■ AUTOMATED BUILD WITH PHING
Once again, I have a default target: main. This depends on another target, setpass, which is
responsible for ensuring that the dbpass property is populated. To this end, I use the target element’s
unless attribute, which ensures that it will not run if dbpass is already set.
The setpass target consists of a single input task element. An input element can have a message
attribute, which should contain a prompt for the user. The propertyName attribute is required and
defines the property to be populated by user input. If the user presses Enter at the prompt without
setting a value, the property is given a fallback value if the defaultValue attribute is set. Finally, you can
customize the prompt character using the promptChar attribute— this provides a visual cue for the user
to input data. Let’s run Phing using the previous targets:
$ phing
Buildfile: /home/bob/working/megaquiz/build.xml
megaquiz > setpass:
You don't seem to have set a db password [default] > mypass
megaquiz > main:
[echo] pass: mypass
BUILD FINISHED
Total time: 6.0322 seconds
The input element is summarized in Table 19–6.
Table 19–6. The Attributes of the input Element
Attribute Required Description
propertyName Yes The property to populate with user input.
Message No The prompt message.
defaultValue No A value to assign to the property if the user does not provide
input.
validArgs No A list of acceptable input values separated by commas. If the
user inputs a value that is not on this list Phing will re-present
the prompt.
promptChar No A visual cue that the user should provide input.