ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: Java6-rc Ant bootstraps fine
Date Wed, 25 Jan 2006 11:32:57 GMT

Kev Jackson wrote:
> Kevin Jackson wrote:
> 
>> On 1/24/06, Steve Loughran <stevel@apache.org> 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:
>>> http://download.java.net/jdk6/docs/api/java/io/Console.html
>>>
>>> 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)...

well, <input> could be extended to say "secure"; we could extend 
inputRequest to ask for a prompt. Then the default handler would 
delegate to the console if the code was built in.

One caveat: would we really want to ship ant built with a prerelease 
runtime? It's that or reflection time.


> org.apache.tools.ant.input.ConsoleInputHandler // perhaps a better name 
> too...
> /*
> * 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
> *
> *      http://www.apache.org/licenses/LICENSE-2.0
> *
> *  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.
> *
> */
> 
> package org.apache.tools.ant.input;
> 
> import java.io.Console;
> 
> import org.apache.tools.ant.BuildException;
> 
> 
> /**
> * Uses Java6 new java.io.console 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
>                request.setInput(password.toString());
>                //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();
>    }
> }
> 
> console.xml
> <?xml version="1.0"?>
> <project name="console" basedir="." default="test">
> 
>  <target name="test">
>    <input
>      message="Password:"
>      addproperty="pwd"
>      />
>      <echo message="Entered: ${pwd}" />
>  </target>
> 
> </project>
> 
> to play with it (or similar)
> java org.apache.tools.ant.Main -inputhandler 
> org.apache.tools.ant.input.ConsoleInputHandler -f ../console.xml
> 
> results
> 
> Buildfile: ..\console.xml
> 
> test:
> [Password:]
>     [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)
> 
> BUILD SUCCESSFUL
> Total time: 1 second
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 


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


Mime
View raw message