ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse Glick <Jesse.Gl...@netbeans.com>
Subject [PATCH] make Execute take advantage of 1.3's CWD support
Date Tue, 08 Aug 2000 20:18:29 GMT
The attached patch (only lightly tested and only on Linux, please note)
should make ExecTask/Execute (<exec>) take advantage of JDK 1.3's new
Runtime.exec accepting a working directory, thus avoiding the need to
use antRun. It should also correct a bug in ExecTask that antRun was
used even when no 'dir' attribute was given (the working directory did
not need to be set at all). And hopefully the code should be a little
clearer (all the alternative strategies are listed in order in one
method).

Previous code had this:

    private static String antWorkingDirectory = 
        (new File((new File(".")).getAbsolutePath())).getParent();

(Written by Mariusz.) I've replaced that with
System.getProperty("user.dir") which is defined from JDK 1.1 to give the
intended result, so hopefully the older code was not a workaround for an
obscure broken JDK.

Two other thoughts about using antRun (not antRun.bat, only the POSIX
version):

1. At least on Bash and I thought other Bourne shells, $@ should be "$@"
to preserve spaces correctly, I think. (But why <<echo $CMD $@ | sh>>
instead of simply <<exec $CMD $@>> or better <<exec "$CMD" "$@">>?)

2. If /bin/sh is found to exist at runtime, why not use it rather than
rely on some shell script? Take the command array cmdl, then construct a
new one of three strings: "/bin/sh", "-c", and then: "cd
${workingDirectory}; " plus each element of cmdl, separated by spaces,
surrounded by ticks ('), and properly escaped (' -> '"'"'). Is there
something special antRun does beyond this?

-Jesse

-- 
Jesse Glick   <mailto:Jesse.Glick@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR
Mime
View raw message