ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From RADEMAKERS Tanguy <>
Subject RE: Propostion for improving PropertyFileInputHandler
Date Wed, 27 Oct 2004 16:17:36 GMT
Hello Ivan,

I agree that the property name makes a better key than the message
string. I routinely wrap my <input> tasks in their own targets, using
"unless" to allow those devs who want to to put things in a properties
file instead:

    <target name="ask.ftp" unless="FTP.USER_NAME" description="prompts
the user for the username and password to use when uploading files">
        <input message="FTP username?" addproperty="FTP.USER_NAME"/>
        <input message="FTP password?" addproperty="FTP.PASSWORD"/>

    <target name="ftp.config" depends="front.config,ask.ftp"
description="uploads config files to the server">
        <ftp server="${WLS.HOST}"
            <fileset refid="fileset.config"/>

so your suggestion seems like a good idea for me since I could cut down
on the number of targets and still acheive the same thing.


>-----Original Message-----
>From: Ivan Ivanov [] 
>Sent: Wednesday, October 27, 2004 6:05 PM
>Subject: Propostion for improving PropertyFileInputHandler
>Dear Colleagues,
>Consider the following ant xml file:
><!-- inputpfih.xml -->
><project name="inputpfih" basedir="." default="input">
>    <description>Test Script for
>    <target name="input">
>        <input message="Enter Your Name"
>        <echo> is ${}</echo>
>    </target>
>If used with DefaultInputHanlder, it works like a
>charm. Now let's try to start it with
>PropertyFileInputHandler and make it read the input
>from a properties file (residing in the directory of
>inputpfih.xml). According to Ant docs: The prompt
>encapsulated in a request will be used as the key when
>looking up the input inside the properties file. If no
>input can be found, the input is considered invalid
>and an exception will be thrown.
>So we create the following properties file
>Enter Your Name=Rambius Parkisanius
>and start the script in this way
>ant -f inputpfih.xml -inputhandler
>The build fails like this:
>Buildfile: inputpfih.xml
>/home/rambius/drafts/ih/inputpfih.xml:6: Unable to
>find input for 'Enter Your Name'
>The cause of the failure is that the key 'Enter Your
>Name' used in the properties file contains spaces and
>thus cannot be picked up. While in this simple case we
>can remove the spaces, I am not sure we should use the
>request's propmt as a key. First, spaces sometimes
>must be used; second, prompts are subject of frequent
>change - on a customer demand, on a QA demand, etc and
>when changed we should change the properties file.
>What remains "hidden" and is not changed is
>addproperty attribute, so I suggest that we use it as
>a key in the properties file.
>In fact, it does not requires so much coding. Here are
>the steps:
>1) Add a String field in InputRequest, called property
>(for example) with a getter and a setter;
>2) Call 
>	request.setProperty(addproperty); 
>in Input.execute() method before
>getInputHandler().handleInput(request) is called.
>3) Call
>Object o = props.get(request.getProperty());
>instead of 
>Object o = props.get(request.getPrompt());
>in PropertyFileInputHandler.handleInput(InputRequest).
>(Two more lines should be changed but this is one is
>most important)
>After building ant with the above change, we create
>the following properties file:
> Parkisanius
>and start the ant script in this way
>ant -f inputpfih.xml -inputhandler
>The result is as expected:
>Buildfile: inputpfih.xml
>     [echo] is Rambius Parkisanius
>I am sending also the patches generated against the
>CVS HEAD and if Ant developers find them useful, I
>would be more than glad to contribute them and if
>needed I can also write the unit tests.
>I encountered this behaviour of
>PropertyFileInputHandler while writing a custom task,
>from which I call Input task several times. The
>prompts in it are dynamically created Strings with new
>lines in them and I tried to use
>PropertyFileInputHandler to automate the testing of
>this task. Even if I could read keys with spaces from
>properties file, it would be hard to manage multiline
>Regards and let me know your opinion
>Do you Yahoo!?
>Y! Messenger - Communicate in real time. Download now. 

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

View raw message