source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/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: 3.4 KB
Line 
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
15read the input from the console as this would make it impossible to
16embed Ant in an IDE. Instead it asks an implementation of the
17<code>org.apache.tools.ant.input.InputHandler</code> interface to
18prompt 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
21and passes it to the <code>InputHandler</code> Such an
22<code>InputRequest</code> may know whether a given user input is valid
23and the <code>InputHandler</code> is supposed to reject all invalid
24input.</p>
25
26<p>Exactly one <code>InputHandler</code> instance is associated with
27every 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
33method</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
41this method must not return unless the <code>request</code> considers
42the user input valid, it is allowed to throw an exception in this
43situation.</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
51implementation will print the prompt encapsulated in the
52<code>request</code> object to Ant's logging system and re-prompt for
53input until the user enters something that is considered valid input
54by the <code>request</code> object. Input will be read from the
55console 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
60processes. It reads all input from a properties file and makes the
61build fail if it cannot find valid input in this file. The name of
62the 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
66the key when looking up the input inside the properties file. If no
67input can be found, the input is considered invalid and an exception
68will be thrown.</p>
69
70<p><strong>Note</strong> that <code>ant.input.properties</code> must
71be a Java system property, not an Ant property. I.e. you cannot
72define it as a simple parameter to <code>ant</code>, but you can
73define 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>
78encapsulate the information necessary to ask a user for input and
79validate this input.</p>
80
81<p>The instances of <code>InputRequest</code> itself will accept any
82input, but subclasses may use stricter validations.
83<code>org.apache.tools.ant.input.MultipleChoiceInputRequest</code>
84should be used if the user input must be part of a predefined set of
85choices.</p>
86
87<hr>
88<p align="center">Copyright &copy; 2002,2004 The Apache Software Foundation. All rights
89Reserved.</p>
90</html>
Note: See TracBrowser for help on using the repository browser.