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 4.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  19. <title>InputHandler</title>
  20. </head>
  21. <body>
  22. <h1>InputHandler</h1>
  23. <h2>Overview</h2>
  24. <p>When a task wants to prompt a user for input, it doesn't simply
  25. read the input from the console as this would make it impossible to
  26. embed Apache Ant in an IDE. Instead it asks an implementation of the
  27. <code>org.apache.tools.ant.input.InputHandler</code> interface to
  28. prompt the user and hand the user input back to the task.</p>
  29. <p>To do this, the task creates an <code>InputRequest</code> object
  30. and passes it to the <code>InputHandler</code>. Such an
  31. <code>InputRequest</code> may know whether a given user input is valid
  32. and the <code>InputHandler</code> is supposed to reject all invalid
  33. input.</p>
  34. <p>Exactly one <code>InputHandler</code> instance is associated with
  35. every Ant process, users can specify the implementation using the
  36. <code>-inputhandler</code> command line switch.</p>
  37. <h2>InputHandler</h2>
  38. <p>The <code>InputHandler</code> interface contains exactly one
  39. method</p>
  40. <pre>
  41. void handleInput(InputRequest request)
  42. throws org.apache.tools.ant.BuildException;</pre>
  43. <p>with some pre- and postconditions. The main postcondition is that
  44. this method must not return unless the <code>request</code> considers
  45. the user input valid; it is allowed to throw an exception in this
  46. situation.</p>
  47. <p>Ant comes with three built-in implementations of this interface:</p>
  48. <h3 id="defaulthandler">DefaultInputHandler</h3>
  49. <p>This is the implementation you get, when you don't use
  50. the <code>-inputhandler</code> command line switch at all. This
  51. implementation will print the prompt encapsulated in
  52. the <code>request</code> object to Ant's logging system and
  53. re-prompt for input until the user enters something that is considered
  54. valid input by the <code>request</code> object. Input will be read
  55. from the console and the user will need to press the Return key.</p>
  56. <h3>PropertyFileInputHandler</h3>
  57. <p>This implementation is useful if you want to run unattended build
  58. processes. It reads all input from a properties file and makes the
  59. build fail if it cannot find valid input in this file. The name of
  60. the properties file must be specified in the Java system
  61. property <code>ant.input.properties</code>.</p>
  62. <p>The prompt encapsulated in a <code>request</code> will be used as
  63. the key when looking up the input inside the properties file. If no
  64. input can be found, the input is considered invalid and an exception
  65. will be thrown.</p>
  66. <p><strong>Note</strong> that <code>ant.input.properties</code> must
  67. be a Java system property, not an Ant property. I.e. you cannot
  68. define it as a simple parameter to <code>ant</code>, but you can
  69. define it inside the <code>ANT_OPTS</code> environment variable.</p>
  70. <h3>GreedyInputHandler</h3>
  71. <p>Like the default implementation, this InputHandler reads from standard
  72. input. However, it consumes <em>all</em> available input. This behavior is
  73. useful for sending Ant input via an OS pipe. <em>Since Ant 1.7</em></p>
  74. <h3>SecureInputHandler</h3>
  75. <p>This InputHandler calls <code>System.console().readPassword()</code>,
  76. available since Java 6. On earlier platforms it falls back to the
  77. behavior of DefaultInputHandler. <em>Since Ant 1.7.1</em></p>
  78. <h2>InputRequest</h2>
  79. <p>Instances of <code>org.apache.tools.ant.input.InputRequest</code>
  80. encapsulate the information necessary to ask a user for input and
  81. validate this input.</p>
  82. <p>The instances of <code>InputRequest</code> itself will accept any
  83. input, but subclasses may use stricter
  84. validations. <code>org.apache.tools.ant.input.MultipleChoiceInputRequest</code>
  85. should be used if the user input must be part of a predefined set of
  86. choices.</p>
  87. </body>
  88. </html>