You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/02/21 15:31:10 UTC
svn commit: r1448650 -
/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
Author: rmannibucau
Date: Thu Feb 21 14:31:09 2013
New Revision: 1448650
URL: http://svn.apache.org/r1448650
Log:
ctrl+c protection in tomee:run mvn command
Modified:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
Modified: tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java?rev=1448650&r1=1448649&r2=1448650&view=diff
==============================================================================
--- tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java (original)
+++ tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java Thu Feb 21 14:31:09 2013
@@ -230,7 +230,6 @@ public abstract class AbstractTomEEMojo
protected Settings settings;
protected File deployedFile = null;
- protected Thread shutdownHook = null;
protected RemoteServer server = null;
private String additionalCp = null;
@@ -674,23 +673,15 @@ public abstract class AbstractTomEEMojo
serverCmd(server, strings);
if (getWaitTomEE()) {
- if (!useConsole) {
- final CountDownLatch stopCondition = new CountDownLatch(1);
- shutdownHook = new Thread() {
- @Override
- public void run() {
- stopServer();
- stopCondition.countDown();
- }
- };
- Runtime.getRuntime().addShutdownHook(shutdownHook);
-
- try {
- stopCondition.await();
- } catch (InterruptedException e) {
- // no-op
+ final CountDownLatch stopCondition = new CountDownLatch(1);
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ stopServer(stopCondition);
}
- } else {
+ });
+
+ if (useConsole) {
final Scanner reader = new Scanner(originalIn);
getLog().info("Waiting for command: " + availableCommands());
@@ -707,7 +698,13 @@ public abstract class AbstractTomEEMojo
}
reader.close();
- stopServer();
+ stopServer(stopCondition); // better than using shutdown hook since it doesn't rely on the hook which are not sent by eclipse for instance
+ }
+
+ try {
+ stopCondition.await();
+ } catch (InterruptedException e) {
+ // no-op
}
}
}
@@ -716,7 +713,11 @@ public abstract class AbstractTomEEMojo
return Arrays.asList(QUIT_CMD, EXIT_CMD);
}
- protected void stopServer() {
+ protected synchronized void stopServer(final CountDownLatch stopCondition) {
+ if (server == null) {
+ return;
+ }
+
try {
server.stop();
} catch (Exception e) {
@@ -728,6 +729,9 @@ public abstract class AbstractTomEEMojo
} catch (Exception e) {
getLog().error("Can't stop TomEE", e);
}
+
+ server = null;
+ stopCondition.countDown();
}
protected boolean handleLine(final String line) {