Author: radu
Date: Thu Aug 24 11:00:19 2017
New Revision: 1806025

URL: http://svn.apache.org/viewvc?rev=1806025&view=rev
Log:
SLING-7083 - The StopMojo should block until the process is finished

* allowed the mojo to uniformly block until the instances it tries to stop
are either stopped through the control listener or through sending the
terminate signal
* enforced Java 8, since its java.util.concurrent.Process implementation
provides built-in feature for blocking until a process is terminated

Modified:
    sling/trunk/tooling/maven/slingstart-maven-plugin/pom.xml
    
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java

Modified: sling/trunk/tooling/maven/slingstart-maven-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/pom.xml?rev=1806025&r1=1806024&r2=1806025&view=diff
==============================================================================
--- sling/trunk/tooling/maven/slingstart-maven-plugin/pom.xml (original)
+++ sling/trunk/tooling/maven/slingstart-maven-plugin/pom.xml Thu Aug 24 
11:00:19 2017
@@ -33,6 +33,7 @@
     <properties>
         <maven.version>3.0.5</maven.version>
         
<maven.site.path>${project.artifactId}-archives/${project.artifactId}-LATEST</maven.site.path>
+        <sling.java.version>8</sling.java.version>
     </properties>
 
     <scm>
@@ -52,6 +53,27 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-enforcer-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>enforce-java</id>
+                        <goals>
+                            <goal>enforce</goal>
+                        </goals>
+                        <configuration>
+                            <rules>
+                                <requireJavaVersion>
+                                    <message>${project.name} must be compiled 
with Java 1.8 or higher.</message>
+                                    
<version>1.${sling.java.version}.0</version>
+                                </requireJavaVersion>
+                            </rules>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
                 <groupId>org.codehaus.plexus</groupId>
                 <artifactId>plexus-component-metadata</artifactId>
                 <version>1.5.5</version>

Modified: 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java?rev=1806025&r1=1806024&r2=1806025&view=diff
==============================================================================
--- 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
 (original)
+++ 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/run/LauncherCallable.java
 Thu Aug 24 11:00:19 2017
@@ -29,6 +29,7 @@ import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.plugin.logging.Log;
@@ -294,20 +295,9 @@ public class LauncherCallable implements
                 final Process process = cfg.getProcess();
 
                 if (!destroy) {
-                    // as shutdown might block forever, we use a timeout
-                    final long now = System.currentTimeMillis();
-                    final long end = now + twoMinutes;
-
                     LOG.debug("Waiting for process to stop...");
-
-                    while (isAlive(process) && (System.currentTimeMillis() < 
end)) {
-                        try {
-                            Thread.sleep(2500);
-                        } catch (InterruptedException e) {
-                            // ignore
-                        }
-                    }
-                    if (isAlive( process)) {
+                    process.waitFor(twoMinutes, TimeUnit.MILLISECONDS);
+                    if (process.isAlive()) {
                         LOG.debug("Process timeout out after 2 minutes");
                         destroy = true;
                     } else {
@@ -318,6 +308,7 @@ public class LauncherCallable implements
                 if (destroy) {
                     LOG.debug("Destroying process...");
                     process.destroy();
+                    process.waitFor(twoMinutes, TimeUnit.MILLISECONDS);
                     LOG.debug("Process destroyed");
                 }
 
@@ -328,19 +319,10 @@ public class LauncherCallable implements
         }
     }
 
-    private static boolean isAlive(Process process) {
-        try {
-            process.exitValue();
-            return false;
-        } catch (IllegalThreadStateException e) {
-            return true;
-        }
-    }
-
     private static File getControlPortFile(final File directory) {
         final File launchpadDir = new File(directory, 
LaunchpadEnvironment.WORK_DIR_NAME);
         final File confDir = new File(launchpadDir, "conf");
         final File controlPortFile = new File(confDir, "controlport");
         return controlPortFile;
     }
-}
\ No newline at end of file
+}


Reply via email to