ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From RADEMAKERS Tanguy <Tanguy.RADEMAK...@swift.com>
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>

    <target name="ftp.config" depends="front.config,ask.ftp"
description="uploads config files to the server">
        <ftp server="${WLS.HOST}"
            userid="${FTP.USER_NAME}"
            password="${FTP.PASSWORD}"
            action="put"
 
remotedir="/opt/geo/bea/user_projects/domains/${DOMAIN}/config"
            verbose="no">
            <fileset refid="fileset.config"/>
        </ftp>
    </target>


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.

/t

>-----Original Message-----
>From: Ivan Ivanov [mailto:rambiusparkisanius@yahoo.com] 
>Sent: Wednesday, October 27, 2004 6:05 PM
>To: user@ant.apache.org
>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
>PropertyFileInputHandler</description>
>
>    <target name="input">
>        <input message="Enter Your Name"
>addproperty="pfh.name"/>
>        <echo>pfh.name is ${pfh.name}</echo>
>    </target>
></project>
>
>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
>
>#inputp.properties
>Enter Your Name=Rambius Parkisanius
>
>and start the script in this way
>export
>ANT_OPTS=-Dant.input.properties=/home/rambius/drafts/ih/inputp.
>properties
>ant -f inputpfih.xml -inputhandler
>org.apache.tools.ant.input.PropertyFileInputHandler
>
>The build fails like this:
>
>Buildfile: inputpfih.xml
>
>input:
>
>BUILD FAILED
>/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:
>
>#inputpfih.properties
>pfh.name=Rambius Parkisanius
>
>and start the ant script in this way
>
>export
>ANT_OPTS=-Dant.input.properties=/home/rambius/drafts/ih/inputpf
>ih.properties
>ant -f inputpfih.xml -inputhandler
>org.apache.tools.ant.input.PropertyFileInputHandler
>
>The result is as expected:
>
>Buildfile: inputpfih.xml
>
>input:
>     [echo] pfh.name is Rambius Parkisanius
>
>BUILD SUCCESSFUL
>
>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
>keys.
>
>Regards and let me know your opinion
>Ivan
>
>
>		
>__________________________________
>Do you Yahoo!?
>Y! Messenger - Communicate in real time. Download now. 
>http://messenger.yahoo.com
>

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


Mime
View raw message