Hello,

Here is a patch to ant.bat which fixes problems with spaces in the value
specified by a property such as -Dfoo="a b c".  Between the Ant 1.2
release and the current CVS version, someone changed the test in the
argument looping from %1a==a to "%1"=="" which broke the way quoted
arguments are appended together causing the script to fail.  In addition
to reverting this change, I made a small optimization for NT/2K so %* is
used to grab all the arguments instead of looping to get them.  As a
result, I renamed the target from "start" to "win9xArgs" which is now more
accurate.  Also made minor changes to a few of the comments.

This fix was tested on Windows NT 4.0 SP5 and Windows 98SE.

Here's a simple build file, proptest.xml:
<project name="PropTest" basedir="." default="main">
  <property name="p1" value="p1"/>
  <property name="p2" value="p2"/>
  <property name="p3" value="p3"/>
  <target name="main">
    <echo>
    p1="${p1}"
    p2="${p2}"
    p3="${p3}"
    </echo>
  </target>
</project>

Sure -debug will output the properties but you have to run against some
build file.  Here is a sample command:
  ant -f proptest.xml -Dp1="C:\Prog files" -Dp2=hello2 -Dp3="D:\ant home"
which should output:
main:
     [echo]
    p1="C:\Prog files"
    p2="hello2"
    p3="D:\ant home"

-Bill Burton
--- ant.bat.orig        Sat Jan 13 01:10:58 2001
+++ ant.bat     Fri Jan 26 00:29:03 2001
@@ -2,7 +2,7 @@
 
 if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat"
 
-if not "%OS%"=="Windows_NT" goto start
+if not "%OS%"=="Windows_NT" goto win9xArgs
 
 rem %~dp0 is name of current script under NT
 set DEFAULT_ANT_HOME=%~dp0
@@ -13,22 +13,24 @@
 if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
 set DEFAULT_ANT_HOME=
 
-:start
-
-rem Slurp the command line arguments.  This loop allows for an unlimited 
number of 
-rem agruments (up to the command line limit, anyway).
+rem On NT/2K grab all arguments at once
+set ANT_CMD_LINE_ARGS=%*
+goto doneArgs
+
+:win9xArgs
+rem Slurp the command line arguments.  Allow for an unlimited number of 
+rem arguments (up to the command line limit, anyway).
 
 set ANT_CMD_LINE_ARGS=
-
 :setupArgs
-if "%1"=="" goto doneArgs
+if %1a==a goto doneArgs
 set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1
 shift
 goto setupArgs
 
 :doneArgs
-rem The doneArgs label is here just to provide a place for the argument list 
loop
-rem to break out to.
+rem This label provides a place for the argument list loop to break out 
+rem and for NT handling to skip to.
 
 rem find ANT_HOME
 if not "%ANT_HOME%"=="" goto checkJava

Reply via email to