ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Perevalov" <>
Subject RE: Prompt
Date Fri, 09 Nov 2001 17:15:58 GMT
I wrote my own target which uses javascript to get some user input into
properties and then run another tagets.
You can place this target in common build file and then include it main
build file.
Here is the target itself, after this target you can find example how to use

<target name="doTargetWithUserInput" description="Executes target where some
parameters provided by user from kbd.">
<script language="javascript"> <![CDATA[
  project = doTargetWithUserInput.getProject();
  //get comma separated user prompts
  var prompts = project.getProperty("prompts");
  //get comma separated user properties which should be set
  var properties = project.getProperty("properties");
  //get comma separated targets to be executed
  var targets = project.getProperty("targets");

  //get standart input stream
  var stdin = new BufferedReader(new InputStreamReader(new

  //split prompts,properties and targets to arrays
  var arrPrompts = Split(String(prompts),",");
  var arrProperties = Split(String(properties),",");
  var arrTargets = Split(String(targets),",");

  //fail if number of properties does not match to number of prompts
  if(arrPrompts.length != arrProperties.length){
	fail = project.createTask("fail");
	fail.setMessage("Number of prompts does not match to the number of

  //get value for each property from user by showing corresponding prompt
  var temp = "";
  for (var i = 0; i < arrPrompts.length; i++){
	temp = stdin.readLine();

  //execute each target which now will have access to new properties
  for (var j = 0; j < arrTargets.length; j++){

  function Split(Expression, Delimiter)
	var temp = Expression;
	var a, b = 0;
	var array = new Array();

	if (Delimiter.length == 0)
		array[0] = Expression;
		return (array);

	if (Expression.length == '')
		array[0] = Expression;
		return (array);

	Delimiter = Delimiter.charAt(0);

	for (var i = 0; i < Expression.length; i++)
		a = temp.indexOf(Delimiter);
		if (a == -1)
			array[i] = temp;
			b = (b + a) + 1;
			var temp2 = temp.substring(0, a);
			array[i] = temp2;
			temp = Expression.substr(b, Expression.length - temp2.length);

	return (array);


Then you can use this target to get some user input and run another

<antcall target="doTargetWithUserInput">
	<param name="prompts" value="Enter user ID:,Enter user password:"/>
	<param name="properties" value="user,pwd"/>
	<param name="targets" value="doSomething"/>

<target name="doSomething" description="Do something with user input">
	<echo message="User id: ${user}, password : ${pwd}"/>

Hope this help.

Paul Perevalov

-----Original Message-----
From: Mark Claassen []
Sent: Friday, November 09, 2001 11:51 AM
Subject: Prompt

Is there any way to prompt for information during a script (without writing
a custom task)?  When I compile my code for release, we tag it in CVS.  We
then use this tag name in the code to generate the version numbers.

What I would like to do is have ant prompt me for a tag and a branch.  Then
it could automatically check out the correct tagged version of the files
that contain the $Name$, compile it (with the $Name$ expanded), build jars,
and then checkout the head of the branch again so I am where I left off.

I could do this with command line parameters as well, but using it this way
in netbeans is a little less convenient.

Thanks for your time,

Mark Claassen
Donnell Systems, Inc.
300 S. St. Louis Blvd. Ste. 203
South Bend, IN 46617
Voice: (219)232-3784
Fax: (219)232-4014

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message