ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mattias J" <matt...@expertsystem.se>
Subject RE: Password task
Date Fri, 21 Feb 2003 14:29:32 GMT
Seems it didn't allow attachments

/**
 * Created: Feb 21, 2003 1:12:19 PM
 * @author Mattias Jiderhamn
 */

package se.exder.anttasks;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;

public class Password extends Task {
  private String name;
  private String message;

  public void setName(String name) {
    this.name = name;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public void execute() throws BuildException {
    if (name == null) {
      throw new BuildException("<password> task requires 'name='
attribute.");
    }

    System.err.print(message);
    System.err.flush();

    Eraser eraser = new Eraser();
    eraser.start();

    BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
    String password = null;
    try {
      password = in.readLine();
    } catch ( IOException ioex ) {
      throw new BuildException(ioex);
    }
    eraser.finished();

    if(password != null)
      getProject().setProperty(name, password);
  }


  private static class Eraser extends Thread {
    boolean finish = false;
    public Eraser () {
    }
    public void run () {
      while ( !finish ) {
        System.out.print("\b ");
        System.out.flush();
        try {
          sleep(10);
        } catch ( InterruptedException intex ) {
        }
      }
    }

    public void finished()
    { finish = true; }
  }
}



> -----Original Message-----
> From: Mattias J [mailto:mattias@expertsystem.se] 
> Sent: Friday, February 21, 2003 3:26 PM
> To: user@ant.apache.org
> Subject: Password task
> 
> 
> I need the user to input a password (for ftp) into an ant 
> script, without it
> being echoed to the screen. I know this is a common issue on 
> this mailing
> list, but I have searched all over and found no final answer.
> 
> I should state that the ant script is run (on a Linux box) 
> through telnet,
> so a GUI popup is no alternative.
> 
> I started off trying to write a shell script to read the 
> password for me,
> but then I found out Ant steals all the input...
> 
> So I tried to write an ant task which read the password and 
> ereased the
> input, using information from
> http://java.sun.com/features/2002/09/pword_mask.html and
> http://www.jguru.com/faq/view.jsp?EID=23448. I succeded in 
> making something
> that works (if you don't type to fast...), but somehow it inserts a
> linebreak for each key pressed.
> 
> Has really nobody else made a command line password input 
> task for ant???
> 
> Would somebody care to look at this code and help me improve it?
> 
> (Now, let's hope this list allows attachements)
> 
>   Mattias Jiderhamn
>   Expert Systems
> 
>   mattias@expertsystem.se
>   www.expertsystem.se 
> 
> 


Mime
View raw message