You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

inputhandler.html 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  6. <title>InputHandler</title>
  7. </head>
  8. <body>
  9. <h1>InputHandler</h1>
  10. <h2>Overview</h2>
  11. <p>When a task wants to prompt a user for input, it doesn't simply
  12. read the input from the console as this would make it impossible to
  13. embed Ant in an IDE. Instead it asks an implementation of the
  14. <code>org.apache.tools.ant.input.InputHandler</code> interface to
  15. prompt the user and hand the user input back to the task.</p>
  16. <p>To do this, the task creates an <code>InputRequest</code> object
  17. and passes it to the <code>InputHandler</code> Such an
  18. <code>InputRequest</code> may know whether a given user input is valid
  19. and the <code>InputHandler</code> is supposed to reject all invalid
  20. input.</p>
  21. <p>Exactly one <code>InputHandler</code> instance is associated with
  22. every Ant process, users can specify the implementation using the
  23. <code>-inputhandler</code> command line switch.</p>
  24. <h2>InputHandler</h2>
  25. <p>The <code>InputHandler</code> interface contains exactly one
  26. method</p>
  27. <pre>
  28. void handleInput(InputRequest request)
  29. throws org.apache.tools.ant.BuildException;
  30. </pre>
  31. <p>with some pre- and postconditions. The main postcondition is that
  32. this method must not return unless the <code>request</code> considers
  33. the user input valid, it is allowed to throw an exception in this
  34. situation.</p>
  35. <p>Ant comes with two built-in implementations of this interface:</p>
  36. <h3><a name="defaulthandler">DefaultInputHandler</a></h3>
  37. <p>This is the implementation you get, when you don't use the
  38. <code>-inputhandler</code> command line switch at all. This
  39. implementation will print the prompt encapsulated in the
  40. <code>request</code> object to Ant's logging system and re-prompt for
  41. input until the user enters something that is considered valid input
  42. by the <code>request</code> object. Input will be read from the
  43. console and the user will need to press the Return key.</p>
  44. <h3>PropertyFileInputHandler</h3>
  45. <p>This implementation is useful if you want to run unattended build
  46. processes. It reads all input from a properties file and makes the
  47. build fail if it cannot find valid input in this file. The name of
  48. the properties file must be specified in the Java system property
  49. <code>ant.input.properties</code>.</p>
  50. <p>The prompt encapsulated in a <code>request</code> will be used as
  51. the key when looking up the input inside the properties file. If no
  52. input can be found, the input is considered invalid and an exception
  53. will be thrown.</p>
  54. <p><strong>Note</strong> that <code>ant.input.properties</code> must
  55. be a Java system property, not an Ant property. I.e. you cannot
  56. define it as a simple parameter to <code>ant</code>, but you can
  57. define it inside the <code>ANT_OPTS</code> environment variable.</p>
  58. <h2>InputRequest</h2>
  59. <p>Instances of <code>org.apache.tools.ant.input.InputRequest</code>
  60. encapsulate the information necessary to ask a user for input and
  61. validate this input.</p>
  62. <p>The instances of <code>InputRequest</code> itself will accept any
  63. input, but subclasses may use stricter validations.
  64. <code>org.apache.tools.ant.input.MultipleChoiceInputRequest</code>
  65. should be used if the user input must be part of a predefined set of
  66. choices.</p>
  67. <hr>
  68. <p align="center">Copyright &copy; 2002,2004-2005 The Apache Software Foundation. All rights
  69. Reserved.</p>
  70. </html>