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