source: release-kits/lirk3/bin/ant-installer/web/manual1.7.0/manual/inputhandler.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 4.3 KB
Line 
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
31read the input from the console as this would make it impossible to
32embed Ant in an IDE. Instead it asks an implementation of the
33<code>org.apache.tools.ant.input.InputHandler</code> interface to
34prompt 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
37and passes it to the <code>InputHandler</code> Such an
38<code>InputRequest</code> may know whether a given user input is valid
39and the <code>InputHandler</code> is supposed to reject all invalid
40input.</p>
41
42<p>Exactly one <code>InputHandler</code> instance is associated with
43every 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
49method</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
57this method must not return unless the <code>request</code> considers
58the user input valid, it is allowed to throw an exception in this
59situation.</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
67implementation will print the prompt encapsulated in the
68<code>request</code> object to Ant's logging system and re-prompt for
69input until the user enters something that is considered valid input
70by the <code>request</code> object. Input will be read from the
71console 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
76processes. It reads all input from a properties file and makes the
77build fail if it cannot find valid input in this file. The name of
78the 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
82the key when looking up the input inside the properties file. If no
83input can be found, the input is considered invalid and an exception
84will be thrown.</p>
85
86<p><strong>Note</strong> that <code>ant.input.properties</code> must
87be a Java system property, not an Ant property. I.e. you cannot
88define it as a simple parameter to <code>ant</code>, but you can
89define 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
94input. However, it consumes <i>all</i> available input. This behavior is
95useful 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>
100encapsulate the information necessary to ask a user for input and
101validate this input.</p>
102
103<p>The instances of <code>InputRequest</code> itself will accept any
104input, but subclasses may use stricter validations.
105<code>org.apache.tools.ant.input.MultipleChoiceInputRequest</code>
106should be used if the user input must be part of a predefined set of
107choices.</p>
108
109
110</html>
Note: See TracBrowser for help on using the repository browser.