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