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.3 KiB

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