ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kev Jackson <>
Subject Re: Java6-rc Ant bootstraps fine
Date Wed, 25 Jan 2006 09:58:47 GMT
Kevin Jackson wrote:

>On 1/24/06, Steve Loughran <> wrote:
>>One thing to look at is <apt> processing; I see hints that apt is
>>properly integrated with the compiler (for which there is now a public API).
>>We also get a secure console:
>>This makes me think we need an extended input handler for passwords; the
>>first impls would support swing and the "legacy" echoing console;
>>java1.6 could be engaged if present. hmm.
>That would fix at least one long-standing bug (if only on Java6) :)
OK, well with the release candiadate, on winxp pro sp2, the new 
System.console() feature works.  I've done a quick input handler 
(ConsoleInputHandler) that will use the secure prompt if a property is set.

My only problem now is how to set the property so that the user can 
decide to use the secure prompt or not - any way just for kicks (if 
anyone else has Java6 installed)... // perhaps a better name 
 * Copyright  2002-2006 The Apache Software Foundation
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.




 * Uses Java6 new classes to handle secure input
 * @since Ant 1.7
public class ConsoleInputHandler implements InputHandler {

    //how do I set this from a build file?  Can the input task pass 
extra params to the handlers?
    private boolean isPassword = true;
    private Console c;
    public ConsoleInputHandler() {
        this.c = System.console();

    public void handleInput(InputRequest request) throws BuildException {
        Object[] prompt = {getPrompt(request)};
        if (isPassword) {
            //prompt and wait
            do {
                char[] password = c.readPassword("[%s]", prompt); //note 
the new formatting which uses Java5 style
                //clear out password array
                java.util.Arrays.fill(password, ' ');
            } while(!request.isInputValid());
        } else {
            //prompt and wait
            request.setInput(c.readLine("[%s]", prompt));

    protected String getPrompt(InputRequest request) {
        return request.getPrompt();

<?xml version="1.0"?>
<project name="console" basedir="." default="test">

  <target name="test">
      <echo message="Entered: ${pwd}" />


to play with it (or similar)
java -inputhandler -f ../console.xml


Buildfile: ..\console.xml

     [echo] Entered: [C@787171 // after clearing the array all you get 
is this - so I'm not sure the addproperty feature will work if the array 
is cleared (as advised)

Total time: 1 second

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

View raw message