In my quest to be able to use the <input/> task, I found it necessary to
be able to set the value of a property to a default value if the user
does not enter a value. What do you think of adding this to the
existing implementation? If it looks good to add, I can submit a patch
to the documentation as well.
To use it, do something like this:
<input message="Where is xxx installed? [/opt/foo]"
defaultvalue="/opt/foo" addproperty="xxx.install.dir"/>
Index: src/main/org/apache/tools/ant/taskdefs/Input.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Input
.java,v
retrieving revision 1.12
diff -u -r1.12 Input.java
--- src/main/org/apache/tools/ant/taskdefs/Input.java 22 Jun 2002
23:38:31 -0000 1.12
+++ src/main/org/apache/tools/ant/taskdefs/Input.java 28 Jun 2002
08:04:33 -0000
@@ -77,6 +77,7 @@
private String validargs = null;
private String message = "";
private String addproperty = null;
+ private String defaultvalue = null;
/**
* Defines valid input parameters as comma separated strings. If
set, input
@@ -102,6 +103,16 @@
}
/**
+ * Defines the default value of the property to be created from
input.
+ * Property value will be set to default if not input is received.
+ *
+ * @param defaultvalue Default value for the property if no input
is received
+ */
+ public void setDefaultvalue (String defaultvalue) {
+ this.defaultvalue = defaultvalue;
+ }
+
+ /**
* Sets the Message which gets displayed to the user during the
build run.
* @param message The message to be displayed.
*/
@@ -137,9 +148,13 @@
getProject().getInputHandler().handleInput(request);
+ String value = request.getInput();
+ if ((value == null) || (value.trim().length() == 0)) {
+ value = defaultvalue;
+ }
if (addproperty != null) {
- project.setNewProperty(addproperty, request.getInput());
+ project.setNewProperty(addproperty, value);
}
}
-}
+}
\ No newline at end of file
Cheers,
Scott Sanders
Perfection is achieved, not when there is nothing more to add,
but when there is nothing left to take away. - Antoine de Saint-Exupery
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>