Hiding password input in Ant
When writting Ant scripts I always have Ant prompt for passwords be it for SVN, SFTP, or anything else that needs to be logged into. Typically would have the following:
<input message="Please enter SVN password:" addproperty="svn.password" />
The only problem is that it echos the password back at you, there has to be a better way. So of to Google I went and found this with an interesting Ant script fragment:
<input message="secure-input:" addproperty="the.password"> <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> </input>
I did not know there could be nested elements in
<input>. Apparently Ant 1.7 added
<handler> nested element for
<input>. But nowhere is there any documentation on SecureInputHandler.
So I tried out the fragment and as the post noted there are a few requirements to get it to work:
- Ant 1.7.1
- Java 6, if it is run on Java 5 it will fallback to a “normal”
One downside, I have not been able to get it to work from within Eclipse 3.5 (since Ant 1.7.1 is bundled with it) and using Java 6 runtime. Eclipse will just hang when it gets to the SecureInputHandler and you have to stop the build script. It does work great from command line which is how I run all my Ant scripts anyway so it is not a real issue for me, but might be for others.