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 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  16. <html>
  17. <head>
  18. <meta http-equiv="Content-Language" content="en-us">
  19. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  20. <title>InputHandler</title>
  21. </head>
  22. <body>
  23. <h1>InputHandler</h1>
  24. <h2>Overview</h2>
  25. <p>When a task wants to prompt a user for input, it doesn't simply
  26. read the input from the console as this would make it impossible to
  27. embed Ant in an IDE. Instead it asks an implementation of the
  28. <code>org.apache.tools.ant.input.InputHandler</code> interface to
  29. prompt the user and hand the user input back to the task.</p>
  30. <p>To do this, the task creates an <code>InputRequest</code> object
  31. and passes it to the <code>InputHandler</code> Such an
  32. <code>InputRequest</code> may know whether a given user input is valid
  33. and the <code>InputHandler</code> is supposed to reject all invalid
  34. input.</p>
  35. <p>Exactly one <code>InputHandler</code> instance is associated with
  36. every Ant process, users can specify the implementation using the
  37. <code>-inputhandler</code> command line switch.</p>
  38. <h2>InputHandler</h2>
  39. <p>The <code>InputHandler</code> interface contains exactly one
  40. method</p>
  41. <pre>
  42. void handleInput(InputRequest request)
  43. throws org.apache.tools.ant.BuildException;
  44. </pre>
  45. <p>with some pre- and postconditions. The main postcondition is that
  46. this method must not return unless the <code>request</code> considers
  47. the user input valid, it is allowed to throw an exception in this
  48. situation.</p>
  49. <p>Ant comes with three built-in implementations of this interface:</p>
  50. <h3><a name="defaulthandler">DefaultInputHandler</a></h3>
  51. <p>This is the implementation you get, when you don't use the
  52. <code>-inputhandler</code> command line switch at all. This
  53. implementation will print the prompt encapsulated in the
  54. <code>request</code> object to Ant's logging system and re-prompt for
  55. input until the user enters something that is considered valid input
  56. by the <code>request</code> object. Input will be read from the
  57. console and the user will need to press the Return key.</p>
  58. <h3>PropertyFileInputHandler</h3>
  59. <p>This implementation is useful if you want to run unattended build
  60. processes. It reads all input from a properties file and makes the
  61. build fail if it cannot find valid input in this file. The name of
  62. the properties file must be specified in the Java system property
  63. <code>ant.input.properties</code>.</p>
  64. <p>The prompt encapsulated in a <code>request</code> will be used as
  65. the key when looking up the input inside the properties file. If no
  66. input can be found, the input is considered invalid and an exception
  67. will be thrown.</p>
  68. <p><strong>Note</strong> that <code>ant.input.properties</code> must
  69. be a Java system property, not an Ant property. I.e. you cannot
  70. define it as a simple parameter to <code>ant</code>, but you can
  71. define it inside the <code>ANT_OPTS</code> environment variable.</p>
  72. <h3>GreedyInputHandler</h3>
  73. <p>Like the default implementation, this InputHandler reads from standard
  74. input. However, it consumes <i>all</i> available input. This behavior is
  75. useful for sending Ant input via an OS pipe. <b>Since Ant 1.7</b>.</p>
  76. <h3>SecureInputHandler</h3>
  77. <p>This InputHandler calls <code>System.console().readPassword()</code>,
  78. available since Java 1.6. On earlier platforms it falls back to the
  79. behavior of DefaultInputHandler. <b>Since Ant 1.7.1</b>.</p>
  80. <h2>InputRequest</h2>
  81. <p>Instances of <code>org.apache.tools.ant.input.InputRequest</code>
  82. encapsulate the information necessary to ask a user for input and
  83. validate this input.</p>
  84. <p>The instances of <code>InputRequest</code> itself will accept any
  85. input, but subclasses may use stricter validations.
  86. <code>org.apache.tools.ant.input.MultipleChoiceInputRequest</code>
  87. should be used if the user input must be part of a predefined set of
  88. choices.</p>
  89. </html>