Hello,

Attached is a patch to fix an annoying deficiency in the debug logging for
the <exec> task and other tasks that call the Execute class.  Currently,
there's no logging that will output the exact command being sent to
Runtime.exec().  Since the various Command Launcher classes take the
specified command and modify it in various ways, you don't really know
what's being passed to Runtime.exec().

This patch rectifies this issue by added a project.log call outputting the
command and it's arguments to the superclasses of the various Command
Launcher classes.  The result is you can see exactly what's being passed
to Runtime.exec() when the -debug option is specified.

Here are a couple of examples of the output first using the JDK 1.2.2 on
Win NT 4.0:

$ export JAVA_HOME=/d/jdk1.2.2
$ ant -f execdirtest.xml -debug -Dexec=dir -Ddir=g:\archives -Darg='*.bat'
...
Build sequence for target `main' is [main]
Complete build sequence is [main]

main:
     [exec] Myos = Windows NT
     [exec] dir *.bat
Execute:CommandLauncher: cmd /c cd G:\\archives && dir *.bat
     [exec]  Volume in drive D has no label.
     [exec]  Volume Serial Number is E8BD-8AE3
     [exec]
     [exec]  Directory of D:\Work\anttest
...

Now using the SDK 1.3.0 also on Win NT 4.0:

$ export JAVA_HOME=/d/jdk1.3
$ ant -f execdirtest.xml -debug -Dexec=lsdir.bat -Darg='*.bat'
...
Build sequence for target `main' is [main]
Complete build sequence is [main]

main:
     [exec] Myos = Windows NT
     [exec] lsdir.bat *.bat
Execute:Java13CommandLauncher: lsdir.bat *.bat
     [exec]
     [exec] D:\Work\anttest>dir  *.bat
     [exec]  Volume in drive D has no label.
     [exec]  Volume Serial Number is E8BD-8AE3
     [exec]
     [exec]  Directory of D:\Work\anttest
...

The Execute class doesn't have access to the task instance that called it
so it can't call task.log which would prefix the output with the "[exec]"
or whatever appropriate decoration for the current task.  For debugging
output, I don't think this is an issue.

It would be nice if this could go into 1.3.

Thanks,
-Bill Burton
--- Execute.java.orig   Fri Jan 12 09:08:50 2001
+++ Execute.java        Mon Feb 12 12:29:43 2001
@@ -428,6 +428,8 @@
          */
         public Process exec(Project project, String[] cmd, String[] env) 
throws IOException
         {
+            project.log("Execute:CommandLauncher: " +
+                        Commandline.toString(cmd), Project.MSG_DEBUG);
             return Runtime.getRuntime().exec(cmd, env);
         }
 
@@ -469,6 +471,8 @@
             for ( int i = 0; i < cmd.length; i++ ) {
                 newcmd[i] = Commandline.quoteArgument(cmd[i]);
             }
+            project.log("Execute:Java11CommandLauncher: " +
+                        Commandline.toString(newcmd), Project.MSG_DEBUG);
             return Runtime.getRuntime().exec(newcmd, env);
         }
     }
@@ -493,6 +497,8 @@
             throws IOException
         {
             try {
+                project.log("Execute:Java13CommandLauncher: " +
+                            Commandline.toString(cmd), Project.MSG_DEBUG);
                 Object[] arguments = { cmd, env, workingDir };
                 return (Process)_execWithCWD.invoke(Runtime.getRuntime(), 
arguments);
             } 

Reply via email to