antoine 2003/07/28 03:39:31 Modified: . WHATSNEW src/main/org/apache/tools/ant/taskdefs Execute.java ExecTask.java docs/manual/CoreTasks exec.html Log: This change allows exec to start a process which will run independently of ant. I have used the patch prepared by Charles Hudak and Peter Nimmervoll, but made it even simpler, in the sense that I do not connect at all the new process to stream handlers and the ant logging system, disabling input, output, error, and return exec attributes in the case of spawn. Strangely, it works well on Windows if one puts a sleep of one second after having spawned the process. Why ? No idea. PR: 5907 Submitted by: Charles Hudak ( CHudak at arrowheadgrp dot com) Revision Changes Path 1.471 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.470 retrieving revision 1.471 diff -u -r1.470 -r1.471 --- WHATSNEW 28 Jul 2003 00:22:00 -0000 1.470 +++ WHATSNEW 28 Jul 2003 10:39:29 -0000 1.471 @@ -521,6 +521,9 @@ * <exec> will now work on OpenVMS (please read the notes in <exec>'s manual page). Bugzilla Report 21877. +* <exec> will now have a new attribute spawn (default false). +If set to true, the process will be spawned. Bugzilla Report 5907. + * <parallel> now supports a timeout which can be used to recover from deadlocks, etc in the parallel threads. <parallel> also now supports a <daemons> nested element. This can be used to 1.62 +36 -0 ant/src/main/org/apache/tools/ant/taskdefs/Execute.java Index: Execute.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Execute.java,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- Execute.java 27 Jul 2003 23:22:00 -0000 1.61 +++ Execute.java 28 Jul 2003 10:39:30 -0000 1.62 @@ -77,6 +77,7 @@ * * @author [EMAIL PROTECTED] * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Tulley</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Charles Hudak</a> * * @since Ant 1.2 * @@ -103,6 +104,7 @@ private static CommandLauncher vmLauncher = null; private static CommandLauncher shellLauncher = null; private static Vector procEnvironment = null; + private boolean spawn = false; /** Used to destroy processes when the VM exits. */ private static ProcessDestroyer processDestroyer = new ProcessDestroyer(); @@ -171,6 +173,17 @@ } } + /** + * set whether or not you want the process to be spawned + * default is not spawned + * + * @param spawn if true you do not want ant to wait for the end of the process + * + * @since ant 1.6 + */ + public void setSpawn(boolean spawn) { + this.spawn = spawn; + } /** * Find the list of environment variables for this process. @@ -504,6 +517,29 @@ // processDestroyer.remove(process); } + } + + /** + * Starts a process defined by the command line. + * Ant will not wait for this process, nor log its output + * + * @throws java.io.IOException The exception is thrown, if launching + * of the subprocess failed + * @since ant 1.6 + */ + public void spawn() throws IOException { + final Process process = launch(project, getCommandline(), + getEnvironment(), workingDirectory, + useVMLauncher); + if (Os.isFamily("windows")) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + project.log("interruption in the sleep after having spawned a process", + Project.MSG_VERBOSE); + } + } + project.log("spawned process " + process.toString(), Project.MSG_VERBOSE); } /** 1.58 +30 -13 ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java Index: ExecTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- ExecTask.java 27 Jul 2003 23:22:01 -0000 1.57 +++ ExecTask.java 28 Jul 2003 10:39:30 -0000 1.58 @@ -71,6 +71,7 @@ * @author [EMAIL PROTECTED] * @author Stefan Bodewig * @author <a href="mailto:[EMAIL PROTECTED]">Mariusz Nowostawski</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Charles Hudak</a> * * @since Ant 1.2 * @@ -90,6 +91,7 @@ private boolean failIfExecFails = true; private String executable; private boolean resolveExecutable = false; + private boolean spawn = false; private Redirector redirector = new Redirector(this); @@ -100,6 +102,16 @@ private boolean vmLauncher = true; /** + * set whether or not you want the process to be spawned + * default is not spawned + * @param spawn if true you do not want ant to wait for the end of the process + * @since ant 1.6 + */ + public void setSpawn(boolean spawn) { + this.spawn = spawn; + } + + /** * Timeout in milliseconds after which the process will be killed. * * @param value timeout in milliseconds @@ -455,6 +467,7 @@ exe.setAntRun(getProject()); exe.setWorkingDirectory(dir); exe.setVMLauncher(vmLauncher); + exe.setSpawn(spawn); String[] environment = env.getVariables(); if (environment != null) { for (int i = 0; i < environment.length; i++) { @@ -479,22 +492,26 @@ protected final void runExecute(Execute exe) throws IOException { int returnCode = -1; // assume the worst - returnCode = exe.execute(); + if (!spawn) { + returnCode = exe.execute(); - //test for and handle a forced process death - if (exe.killedProcess()) { - log("Timeout: killed the sub-process", Project.MSG_WARN); - } - maybeSetResultPropertyValue(returnCode); - if (Execute.isFailure(returnCode)) { - if (failOnError) { - throw new BuildException(getTaskType() + " returned: " - + returnCode, getLocation()); - } else { - log("Result: " + returnCode, Project.MSG_ERR); + //test for and handle a forced process death + if (exe.killedProcess()) { + log("Timeout: killed the sub-process", Project.MSG_WARN); + } + maybeSetResultPropertyValue(returnCode); + if (Execute.isFailure(returnCode)) { + if (failOnError) { + throw new BuildException(getTaskType() + " returned: " + + returnCode, getLocation()); + } else { + log("Result: " + returnCode, Project.MSG_ERR); + } } + redirector.complete(); + } else { + exe.spawn(); } - redirector.complete(); } /** 1.28 +9 -0 ant/docs/manual/CoreTasks/exec.html Index: exec.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/exec.html,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- exec.html 25 Jul 2003 10:06:31 -0000 1.27 +++ exec.html 28 Jul 2003 10:39:31 -0000 1.28 @@ -60,6 +60,15 @@ <td align="center" valign="top">No</td> </tr> <tr> + <td valign="top">spawn</td> + <td valign="top">whether or not you want the command to be spawned<br/> + Default is false.<br> + If you spawn a command, its output will not be logged by ant.<br/> + The input, output, error, and result property settings are not active when spawning a process. + </td> + <td align="center" valign="top">No</td> + </tr> + <tr> <td valign="top">output</td> <td valign="top">Name of a file to which to write the output. If the error stream is not also redirected to a file or property, it will appear in this output.</td>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]