vmassol 01/08/09 10:53:39 Modified: cactus/src/ant/org/apache/commons/cactus/ant RunServerTestsTask.java StartServerHelper.java StopServerHelper.java StopServerTask.java Log: The Cactus runservertests custom Ant task will now not stop the server if it was running before the task was executed. This is to allow to run and rerun Cactus tests without starting/stopping the server every time you run the tests. Thanks to Paul Dillon ([EMAIL PROTECTED]) for this suggestion Revision Changes Path 1.2 +40 -4 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/RunServerTestsTask.java Index: RunServerTestsTask.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/RunServerTestsTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RunServerTestsTask.java 2001/04/09 11:52:34 1.1 +++ RunServerTestsTask.java 2001/08/09 17:53:38 1.2 @@ -60,23 +60,56 @@ import org.apache.tools.ant.taskdefs.*; /** + * Task to automate running in-container unit test. It has the following + * syntax when used in Ant : + * <code><pre> + * <runservertests testURL="&t;url>" + * startTarget="<start target name>" + * stopTarget="<stop target name>" + * testTarget="<test target name>"/> + * </pre></code> + * where <code><url></code> is the URL that is used by this task to + * ensure that the server is running. Indeed, the algorithm is as follow : + * <ul> + * <li>Checks if server is running by trying to open an HTTP connection to + * the URL,</li> + * <li>If it fails, call the start target and loop until the HTTP connection + * the URL can be established,</li> + * <li>Call the test target. This target is supposed to start the test, + * usually by running the junit Ant task,</li> + * <li>When the tests are finished, call the stop target to stop the server. + * Note: The stop target is called only if the server was not already running + * when this task was executed.</li> + * </ul> * * @version @version@ */ public class RunServerTestsTask extends Task { + /** + * the test target name. + */ private String m_TestTarget; /** - * + * The helper object used to start the server. We use a helper so that it + * can also be reused in the <code>StartServerTask</code> task. Indeed, + * with Ant 1.3 and before there are classloaders issues with calling a + * custom task from another custom task. Using a helper is a workaround. */ private StartServerHelper m_StartHelper; /** - * + * The helper object used to stop the server. We use a helper so that it + * can also be reused in the <code>StopServerTask</code> task. Indeed, + * with Ant 1.3 and before there are classloaders issues with calling a + * custom task from another custom task. Using a helper is a workaround. */ private StopServerHelper m_StopHelper; + /** + * Initialize the task. + */ public void init() { m_StartHelper = new StartServerHelper(this); @@ -92,8 +125,11 @@ callStart(); callTests(); } finally { - // Make sure we stop the server - callStop(); + // Make sure we stop the server but only if it were not already + // started before the execution of this task. + if (!m_StartHelper.isServerAlreadyStarted()) { + callStop(); + } } } 1.4 +18 -3 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StartServerHelper.java Index: StartServerHelper.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StartServerHelper.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StartServerHelper.java 2001/05/02 15:16:41 1.3 +++ StartServerHelper.java 2001/08/09 17:53:39 1.4 @@ -89,8 +89,18 @@ private Task m_Task; /** - * + * True if the server was already started when this task is executed. */ + private boolean m_IsServerAlreadyStarted = false; + + public boolean isServerAlreadyStarted() + { + return m_IsServerAlreadyStarted; + } + + /** + * @param theTask the Ant task that is calling this helper + */ public StartServerHelper(Task theTask) { m_Task = theTask; @@ -114,15 +124,20 @@ // Try connecting in case the server is already running. If so, does // nothing try { + HttpURLConnection connection = (HttpURLConnection)m_TestURL.openConnection(); connection.connect(); readFully(connection); connection.disconnect(); - // Server is already running. Make this task a no-op. + // Server is already running. Record this information so that we + // don't stop it afterwards. + m_IsServerAlreadyStarted = true; + return; + } catch (IOException e) { - // An error occurred. It just measn the server is not running. Do + // An error occurred. It just means the server is not running. Do // nothing } 1.4 +1 -1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerHelper.java Index: StopServerHelper.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerHelper.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StopServerHelper.java 2001/05/02 15:16:43 1.3 +++ StopServerHelper.java 2001/08/09 17:53:39 1.4 @@ -85,7 +85,7 @@ private Task m_Task; /** - * + * @param theTask the Ant task that is calling this helper */ public StopServerHelper(Task theTask) { 1.2 +3 -1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerTask.java Index: StopServerTask.java =================================================================== RCS file: /home/cvs/jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- StopServerTask.java 2001/04/09 11:52:35 1.1 +++ StopServerTask.java 2001/08/09 17:53:39 1.2 @@ -62,7 +62,9 @@ /** * Call an Ant stop target in another thread and wait for the servlet engine * to be stopped by trying to continously connect to a test URL. If it succeeds - *it means the server is not stopped yet ! + * it means the server is not stopped yet ! If the server was already running + * when the start task was invoked, then it is not stopped when this tasks + * executes. * * @version @version@ */