You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2004/08/13 17:27:49 UTC
DO NOT REPLY [Bug 30651] New: -
Add ability to pass arbitrary arguments after a special -- marker as special $ properties
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30651>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=30651
Add ability to pass arbitrary arguments after a special -- marker as special $ properties
Summary: Add ability to pass arbitrary arguments after a special
-- marker as special $ properties
Product: Ant
Version: 1.6.2
Platform: All
OS/Version: Other
Status: NEW
Severity: Enhancement
Priority: Other
Component: Core
AssignedTo: dev@ant.apache.org
ReportedBy: ddevienne@lgc.com
Even though Ant is not designed to be a scripting environment, it is a shame
that developpers have to write some (usually crappy) .bat or .sh scripts to
startup little interactive demo/example/benchmark programs, when all the
CLASSPATH/PATH/LD_LIBRARY_PATH is already cleanly encapsulated in the build
file. Furthermore, these scripts duplicate all the path info of the build file
itself (which in my case is computed by custom tasks based on dependency info,
Maven style).
In a different life, I used to startup the X server on Solaris using the
xserver program (I think that's the name), which recognized a special --
argument, after which all other args were not for xserver itself, but for the
process it forked (the separate X11 server program).
I thus added a similar behavior to the new Ant 1.6.x Launcher class. It now
recognizes a new -- argument, and converts all arguments after it into Ant
properties passed in to the traditional Ant main. The properties defined take
the shell/perl like $0, $1, $2, etc... notation, with the special $# property
for the total number of arguments after -- (including $0), and the special $*
property that contains all the arguments (excluding $0) as a string (with
simple logic to quote arguments that contain spaces or tabs).
Given the following command lines, the properties are defined as below using
the following target (that uses custom tasks, but that's beside the point):
<target name="start" xmlns:bm="antlib:com.lgc.buildmagic">
<bm:echo unless="$0" message="Warning: No -- arguments specified" />
<bm:echo><propertyset><propertyref prefix="$" /></propertyset></bm:echo>
</target>
C:\oss\org_apache\ant16>build start
Warning: No -- arguments specified
C:\oss\org_apache\ant16>build start --
The -- argument must be followed by one or more argument(s)
C:\oss\org_apache\ant16>build start -- toto
$0 = toto
$# = 1
$* =
C:\oss\org_apache\ant16>build start -- toto titi tutu
$1 = titi
$0 = toto
$# = 3
$* = titi tutu
$2 = tutu
C:\oss\org_apache\ant16>build start -- toto "titi tyty" tutu
$1 = titi tyty
$0 = toto
$# = 3
$* = "titi tyty" tutu
$2 = tutu
Using this new -- argument passing technique with <java> and <exec>, Ant is now
much more flexible to start up arbitrary Java programs (by using $0 in <java>'s
classname attribute) and either <arg line="${$*}" /> or multiple <arg
value="${$1}" /> style arguments.
Thanks for considering this addition to Ant. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org