1 8 9 import java.io.InputStreamReader ; 10 import java.io.BufferedReader ; 11 import java.io.IOException ; 12 import org.apache.tools.ant.taskdefs.Property; 13 14 21 public class UserInputTask extends org.apache.tools.ant.Task { 22 23 private String question; 24 private String name; 25 private String value; 26 27 30 public UserInputTask() { 31 super(); 32 } 33 34 37 public void init() { 38 super.init(); 39 question = "?"; 40 } 41 42 46 public void execute() throws org.apache.tools.ant.BuildException { 47 value = project.getProperty(name); 48 String defaultvalue = value; 49 50 if (value != null) { 52 53 System.out.println("\n"+question + " ["+value + "] "); 54 55 BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); 56 57 try 58 { 59 value = reader.readLine(); 60 } 61 catch (IOException e) 62 { 63 value = defaultvalue; 64 } 65 66 if (!value.equals("")) { 67 project.setProperty(name, value); 68 } else { 69 project.setProperty(name, defaultvalue); 70 } 71 } 72 } 73 74 78 public void addText(String question) { 79 this.question=question; 80 } 81 82 public void setQuestion(String question) { 83 this.question = question; 84 } 85 86 public void setName(String name) { 87 this.name = name; 88 } 89 90 } 91 92 | Popular Tags |