diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecuteWatchdog.java similarity index 95% rename from proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java rename to proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecuteWatchdog.java index 670622c51..4425f890e 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ExecuteWatchdog.java @@ -5,7 +5,7 @@ * version 1.1, a copy of which has been included with this distribution in * the LICENSE file. */ -package org.apache.tools.ant.taskdefs.exec; +package org.apache.myrmidon.framework.exec; import org.apache.myrmidon.api.TaskException; @@ -65,7 +65,7 @@ public class ExecuteWatchdog { throw new IllegalArgumentException( "timeout lesser than 1." ); } - this.m_timeout = timeout; + m_timeout = timeout; } /** @@ -175,14 +175,14 @@ public class ExecuteWatchdog { throw new NullPointerException( "process is null." ); } - if( this.m_process != null ) + if( m_process != null ) { throw new IllegalStateException( "Already running." ); } - this.m_caught = null; - this.m_killedProcess = false; - this.m_watch = true; - this.m_process = process; + m_caught = null; + m_killedProcess = false; + m_watch = true; + m_process = process; final Thread thread = new Thread( this, "WATCHDOG" ); thread.setDaemon( true ); thread.start(); diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java index 6b04016dd..e298f6811 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecTask.java @@ -17,6 +17,7 @@ import java.io.StringReader; import java.util.Iterator; import java.util.Properties; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Commandline; diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java index 3fae7a5f7..8aa835c33 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/Execute.java @@ -18,6 +18,7 @@ import org.apache.myrmidon.framework.exec.CommandLauncher; import org.apache.myrmidon.framework.exec.Environment; import org.apache.myrmidon.framework.exec.ExecException; import org.apache.myrmidon.framework.exec.ExecMetaData; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; import org.apache.myrmidon.framework.exec.launchers.ScriptCommandLauncher; diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 49156097a..7dec5cb8c 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -22,7 +22,7 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.exec.Execute; -import org.apache.tools.ant.taskdefs.exec.ExecuteWatchdog; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.tools.ant.taskdefs.exec.LogOutputStream; import org.apache.tools.ant.taskdefs.exec.LogStreamHandler; import org.apache.tools.ant.types.Commandline; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java index 6b04016dd..e298f6811 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecTask.java @@ -17,6 +17,7 @@ import java.io.StringReader; import java.util.Iterator; import java.util.Properties; import org.apache.myrmidon.api.TaskException; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Commandline; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java index 3fae7a5f7..8aa835c33 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/Execute.java @@ -18,6 +18,7 @@ import org.apache.myrmidon.framework.exec.CommandLauncher; import org.apache.myrmidon.framework.exec.Environment; import org.apache.myrmidon.framework.exec.ExecException; import org.apache.myrmidon.framework.exec.ExecMetaData; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.myrmidon.framework.exec.launchers.DefaultCommandLauncher; import org.apache.myrmidon.framework.exec.launchers.MacCommandLauncher; import org.apache.myrmidon.framework.exec.launchers.ScriptCommandLauncher; diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java deleted file mode 100644 index 670622c51..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) The Apache Software Foundation. All rights reserved. - * - * This software is published under the terms of the Apache Software License - * version 1.1, a copy of which has been included with this distribution in - * the LICENSE file. - */ -package org.apache.tools.ant.taskdefs.exec; - -import org.apache.myrmidon.api.TaskException; - -/** - * Destroys a process running for too long. For example:
- * ExecuteWatchdog watchdog = new ExecuteWatchdog(30000); - * Execute exec = new Execute(myloghandler, watchdog); - * exec.setCommandLine(mycmdline); - * int exitvalue = exec.execute(); - * if (exitvalue != SUCCESS && watchdog.killedProcess()){ - * // it was killed on purpose by the watchdog - * } - *- * - * @author thomas.haas@softwired-inc.com - * @author Stephane Bailliez - * @see Execute - */ -public class ExecuteWatchdog - implements Runnable -{ - /** - * say whether or not the watchog is currently monitoring a process - */ - private boolean m_watch; - - /** - * exception that might be thrown during the process execution - */ - private Exception m_caught; - - /** - * say whether or not the process was killed due to running overtime - */ - private boolean m_killedProcess; - - /** - * the process to execute and watch for duration - */ - private Process m_process; - - /** - * timeout duration. Once the process running time exceeds this it should be - * killed - */ - private int m_timeout; - - /** - * Creates a new watchdog with a given timeout. - * - * @param timeout the timeout for the process in milliseconds. It must be - * greather than 0. - */ - public ExecuteWatchdog( int timeout ) - { - if( timeout < 1 ) - { - throw new IllegalArgumentException( "timeout lesser than 1." ); - } - this.m_timeout = timeout; - } - - /** - * Indicates whether or not the watchdog is still monitoring the process. - * - * @return true if the process is still running, otherwise - * false . - */ - public boolean isWatching() - { - return m_watch; - } - - /** - * This method will rethrow the exception that was possibly caught during - * the run of the process. It will only remains valid once the process has - * been terminated either by 'error', timeout or manual intervention. - * Information will be discarded once a new process is ran. - * - * @throws TaskException a wrapped exception over the one that was silently - * swallowed and stored during the process run. - */ - public void checkException() - throws TaskException - { - if( m_caught != null ) - { - throw new TaskException( "Exception in ExecuteWatchdog.run: " - + m_caught.getMessage(), m_caught ); - } - } - - /** - * Indicates whether the last process run was killed on timeout or not. - * - * @return true if the process was killed otherwise false - * . - */ - public boolean killedProcess() - { - return m_killedProcess; - } - - /** - * Watches the process and terminates it, if it runs for to long. - */ - public synchronized void run() - { - try - { - // This isn't a Task, don't have a Project object to log. - // project.log("ExecuteWatchdog: timeout = "+timeout+" msec", Project.MSG_VERBOSE); - final long until = System.currentTimeMillis() + m_timeout; - long now; - while( m_watch && until > ( now = System.currentTimeMillis() ) ) - { - try - { - wait( until - now ); - } - catch( InterruptedException e ) - { - } - } - - // if we are here, either someone stopped the watchdog, - // we are on timeout and the process must be killed, or - // we are on timeout and the process has already stopped. - try - { - // We must check if the process was not stopped - // before being here - m_process.exitValue(); - } - catch( IllegalThreadStateException e ) - { - // the process is not terminated, if this is really - // a timeout and not a manual stop then kill it. - if( m_watch ) - { - m_killedProcess = true; - m_process.destroy(); - } - } - } - catch( Exception e ) - { - m_caught = e; - } - finally - { - cleanUp(); - } - } - - /** - * Watches the given process and terminates it, if it runs for too long. All - * information from the previous run are reset. - * - * @param process the process to monitor. It cannot be null - * @throws IllegalStateException thrown if a process is still being - * monitored. - */ - public synchronized void start( Process process ) - { - if( process == null ) - { - throw new NullPointerException( "process is null." ); - } - if( this.m_process != null ) - { - throw new IllegalStateException( "Already running." ); - } - this.m_caught = null; - this.m_killedProcess = false; - this.m_watch = true; - this.m_process = process; - final Thread thread = new Thread( this, "WATCHDOG" ); - thread.setDaemon( true ); - thread.start(); - } - - /** - * Stops the watcher. It will notify all threads possibly waiting on this - * object. - */ - public synchronized void stop() - { - m_watch = false; - notifyAll(); - } - - /** - * reset the monitor flag and the process. - */ - protected void cleanUp() - { - m_watch = false; - m_process = null; - } -} - diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 49156097a..7dec5cb8c 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -22,7 +22,7 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.exec.Execute; -import org.apache.tools.ant.taskdefs.exec.ExecuteWatchdog; +import org.apache.myrmidon.framework.exec.ExecuteWatchdog; import org.apache.tools.ant.taskdefs.exec.LogOutputStream; import org.apache.tools.ant.taskdefs.exec.LogStreamHandler; import org.apache.tools.ant.types.Commandline;