actually this break tomee maven plugin we shouldn't redirect stdin so we need to use
pb.redirectOutput(Redirect.INHERIT) .redirectError(Redirect.INHERIT) Romain Manni-Bucau Twitter: @rmannibucau Blog: http://rmannibucau.wordpress.com/ LinkedIn: http://fr.linkedin.com/in/rmannibucau Github: https://github.com/rmannibucau ---------- Forwarded message ---------- From: <[email protected]> Date: 2014-07-22 11:41 GMT+02:00 Subject: svn commit: r1612521 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java To: [email protected] Author: andygumbrecht Date: Tue Jul 22 09:41:47 2014 New Revision: 1612521 URL: http://svn.apache.org/r1612521 Log: RemoteServer - Use ProcessBuilder ContainersImplTomEE - Finals & format Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java tomee/tomee/trunk/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1612521&r1=1612520&r2=1612521&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java Tue Jul 22 09:41:47 2014 @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.concurrent.atomic.AtomicReference; /** * NOTE: don't add inner classes or anonymous one or dependency without updating ExecMojo @@ -64,7 +65,7 @@ public class RemoteServer { private boolean serverHasAlreadyBeenStarted = true; private Properties properties; - private Process server; + private final AtomicReference<Process> server = new AtomicReference<Process>(); private final int tries; private final boolean verbose; private final int portShutdown; @@ -128,29 +129,16 @@ public class RemoteServer { stop(); - if (server != null) { - final Process sp = server; - final Thread t = new Thread(new Runnable() { - @Override - public void run() { + final Process p = server.get(); + if (p != null) { try { - sp.waitFor(); - } catch (final InterruptedException e) { - // no-op + p.waitFor(); + } catch (final Throwable t) { + t.printStackTrace(System.err); } - } - }, "RemoteServer-destroy"); - t.start(); - try { - t.join(15000); - } catch (final InterruptedException e) { - //Ignore - } finally { - server.destroy(); } } - } public void start() { start(Collections.<String>emptyList(), START, true); @@ -340,14 +328,19 @@ public class RemoteServer { } // kill3UNIXDebug(); + final ProcessBuilder pb = new ProcessBuilder(args).inheritIO().directory(home.getAbsoluteFile()); + Process p = pb.start(); - final Process process = Runtime.getRuntime().exec(args); - Pipe.pipeOut(process); // why would we need to redirect System.in to the process, TomEE doesn't use it + //Process p = Runtime.getRuntime().exec(args); + //Pipe.pipeOut(p); // why would we need to redirect System.in to the process, TomEE doesn't use it if (START.equals(cmd)) { - server = process; - } else if (STOP.equals(cmd) && server != null) { - server.waitFor(); + server.set(p); + } else if (STOP.equals(cmd)) { + p.waitFor(); + p = server.get(); + if (p != null) + p.waitFor(); } } catch (final Exception e) { @@ -378,9 +371,9 @@ public class RemoteServer { } try { - final Field f = server.getClass().getDeclaredField("pid"); + final Field f = server.get().getClass().getDeclaredField("pid"); f.setAccessible(true); - final int pid = (Integer) f.get(server); + final int pid = (Integer) f.get(server.get()); Pipe.pipe(Runtime.getRuntime().exec("kill -3 " + pid)); } catch (final Exception e1) { e1.printStackTrace(); @@ -428,7 +421,7 @@ public class RemoteServer { } public Process getServer() { - return server; + return server.get(); } private void addIfSet(final List<String> argsList, final String key) { @@ -553,10 +546,10 @@ public class RemoteServer { } public void killOnExit() { - if (!serverHasAlreadyBeenStarted && kill.contains(this.server)) { + if (!serverHasAlreadyBeenStarted && kill.contains(this.server.get())) { return; } - kill.add(this.server); + kill.add(this.server.get()); } // Shutdown hook for recursive delete on tmp directories Modified: tomee/tomee/trunk/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java?rev=1612521&r1=1612520&r2=1612521&view=diff ============================================================================== --- tomee/tomee/trunk/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java (original) +++ tomee/tomee/trunk/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/ContainersImplTomEE.java Tue Jul 22 09:41:47 2014 @@ -44,31 +44,33 @@ public class ContainersImplTomEE extends private Exception exception; private AppInfo appInfo; private File currentFile = null; - private int port = Integer.getInteger("server.http.port", 8080); + private final int port = Integer.getInteger("server.http.port", 8080); private Deployer lookup() { final Options options = new Options(System.getProperties()); final Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName()); - props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL," http://localhost:" + port + "/tomee/ejb")); + props.put(Context.PROVIDER_URL, options.get(Context.PROVIDER_URL, " http://localhost:" + port + "/tomee/ejb")); final String deployerJndi = System.getProperty("openejb.deployer.jndiname", "openejb/DeployerBusinessRemote"); try { - InitialContext context = new InitialContext(props); + final InitialContext context = new InitialContext(props); return (Deployer) context.lookup(deployerJndi); - } catch (Exception e) { + } catch (final Exception e) { throw new OpenEJBTCKRuntimeException(e); } } + public ContainersImplTomEE() { System.out.println("ContainersImpl=" + ContainersImplTomEE.class.getName()); System.out.println("Initialized ContainersImplTomEE " + (++count)); server = new RemoteServer(); server.setPortStartup(this.port); } + @Override - public boolean deploy(InputStream archive, String name) throws IOException { + public boolean deploy(final InputStream archive, final String name) throws IOException { exception = null; appInfo = null; @@ -82,7 +84,7 @@ public class ContainersImplTomEE extends deployer = lookup(); } appInfo = deployer.deploy(currentFile.getAbsolutePath()); - } catch (Exception ex) { + } catch (final Exception ex) { Exception e = ex; if (e.getCause() instanceof ValidationException) { e = (Exception) e.getCause(); @@ -108,14 +110,14 @@ public class ContainersImplTomEE extends public DeploymentException getDeploymentException() { try { return (DeploymentException) exception; - } catch (Exception e) { + } catch (final Exception e) { System.out.println("BADCAST"); return new DeploymentException("", exception); } } @Override - public void undeploy(String name) throws IOException { + public void undeploy(final String name) throws IOException { if (appInfo == null) { if (!(exception instanceof DeploymentException)) { System.out.println("Nothing to undeploy" + name); @@ -126,19 +128,19 @@ public class ContainersImplTomEE extends System.out.println("Undeploying " + name); try { deployer.undeploy(appInfo.path); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); throw new OpenEJBTCKRuntimeException(e); } - File toDelete; + final File toDelete; if (currentFile != null && (toDelete = currentFile.getParentFile()).exists()) { System.out.println("deleting " + toDelete.getAbsolutePath()); delete(toDelete); } } - protected File getFile(String name) { + protected File getFile(final String name) { final File dir = new File(tmpDir, Math.random() + ""); if (!dir.exists() && !dir.mkdir()) { throw new RuntimeException("Failed to create directory: " + dir); @@ -152,6 +154,7 @@ public class ContainersImplTomEE extends System.out.println("Setup called"); server.start(Arrays.asList("-Dopenejb.classloader.forced-load=org.apache.openejb.tck"), "start", true); } + @Override public void cleanup() throws IOException { System.out.println("Cleanup called");
