Author: veithen Date: Fri Jan 6 17:05:14 2012 New Revision: 1228276 URL: http://svn.apache.org/viewvc?rev=1228276&view=rev Log: Allow the integration test server to be started in debug mode.
Modified: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java Modified: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java?rev=1228276&r1=1228275&r2=1228276&view=diff ============================================================================== --- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java (original) +++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java Fri Jan 6 17:05:14 2012 @@ -21,7 +21,10 @@ package org.apache.axis.maven; import java.io.File; import java.net.URL; import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.xml.namespace.QName; @@ -41,17 +44,21 @@ public class DefaultServerManager implem this.logger = logger; } - public void startServer(String jvm, String[] classpath, int port, File workDir, String[] wsddFiles) throws Exception { + public void startServer(String jvm, String[] classpath, int port, String[] vmArgs, File workDir, String[] wsddFiles, int timeout) throws Exception { AdminClient adminClient = new AdminClient(true); adminClient.setTargetEndpointAddress(new URL("http://localhost:" + port + "/axis/services/AdminService")); - Process process = Runtime.getRuntime().exec(new String[] { - jvm, - "-cp", - StringUtils.join(classpath, File.pathSeparator), - "org.apache.axis.transport.http.SimpleAxisServer", - "-p", - String.valueOf(port) - }, null, workDir); + List cmdline = new ArrayList(); + cmdline.add(jvm); + cmdline.add("-cp"); + cmdline.add(StringUtils.join(classpath, File.pathSeparator)); + cmdline.addAll(Arrays.asList(vmArgs)); + cmdline.add("org.apache.axis.transport.http.SimpleAxisServer"); + cmdline.add("-p"); + cmdline.add(String.valueOf(port)); + if (logger.isDebugEnabled()) { + logger.debug("Starting process with command line: " + cmdline); + } + Process process = Runtime.getRuntime().exec((String[])cmdline.toArray(new String[cmdline.size()]), null, workDir); servers.put(Integer.valueOf(port), new Server(process, adminClient)); // TODO: need to set up stdout/stderr forwarding; otherwise the process will hang @@ -59,16 +66,24 @@ public class DefaultServerManager implem String versionUrl = "http://localhost:" + port + "/axis/services/Version"; Call call = new Call(new URL(versionUrl)); call.setOperationName(new QName(versionUrl, "getVersion")); + long start = System.currentTimeMillis(); for (int i=0; ; i++) { try { String result = (String)call.invoke(new Object[0]); logger.info("Server ready on port " + port + ": " + result.replace('\n', ' ')); break; } catch (RemoteException ex) { - if (i == 50) { + if (System.currentTimeMillis() > start + timeout) { throw ex; } } + try { + int exitValue = process.exitValue(); + // TODO: choose a better exception here + throw new RemoteException("The server process unexpectedly died with exit status " + exitValue); + } catch (IllegalThreadStateException ex) { + // This means that the process is still running; continue + } Thread.sleep(200); } Modified: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java?rev=1228276&r1=1228275&r2=1228276&view=diff ============================================================================== --- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java (original) +++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/ServerManager.java Fri Jan 6 17:05:14 2012 @@ -21,6 +21,6 @@ package org.apache.axis.maven; import java.io.File; public interface ServerManager { - void startServer(String jvm, String[] classpath, int port, File workDir, String[] wsddFiles) throws Exception; + void startServer(String jvm, String[] classpath, int port, String[] vmArgs, File workDir, String[] wsddFiles, int timeout) throws Exception; void stopServer(int port) throws Exception; } Modified: axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java?rev=1228276&r1=1228275&r2=1228276&view=diff ============================================================================== --- axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java (original) +++ axis/axis1/java/trunk/axis-maven-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java Fri Jan 6 17:05:14 2012 @@ -21,6 +21,7 @@ package org.apache.axis.maven; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.axis.transport.http.SimpleAxisServer; @@ -94,6 +95,22 @@ public class StartServerMojo extends Abs */ private boolean foreground; + /** + * The arguments to pass to the server JVM when debug mode is enabled. + * + * @parameter default-value="-Xdebug -Xrunjdwp:transport=dt_socket,address=8899,server=y,suspend=y" + */ + private String debugArgs; + + /** + * Indicates whether the server should be started in debug mode. This flag can only be set from + * the command lined. + * + * @parameter expression="${axis.server.debug}" default-value="false" + * @readonly + */ + private boolean debug; + public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); @@ -143,6 +160,15 @@ public class StartServerMojo extends Abs wsddFiles = null; } + // Compute JVM arguments + List vmArgs = new ArrayList(); + if (debug) { + vmArgs.addAll(Arrays.asList(debugArgs.split(" "))); + } + if (log.isDebugEnabled()) { + log.debug("Additional VM args: " + vmArgs); + } + // Prepare a work directory where the server can create a server-config.wsdd file File workDir = new File(workDirBase, String.valueOf(getPort())); if (workDir.exists()) { @@ -160,8 +186,10 @@ public class StartServerMojo extends Abs getServerManager().startServer(executable, (String[])classPathElements.toArray(new String[classPathElements.size()]), getPort(), + (String[])vmArgs.toArray(new String[vmArgs.size()]), workDir, - wsddFiles == null ? null : (String[])wsddFiles.toArray(new String[wsddFiles.size()])); + wsddFiles == null ? null : (String[])wsddFiles.toArray(new String[wsddFiles.size()]), + debug || foreground ? Integer.MAX_VALUE : 20000); } catch (Exception ex) { throw new MojoFailureException("Failed to start server", ex); }