SLIDER-353 killJavaProcesses doesn't work on windows

Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/38c2a138
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/38c2a138
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/38c2a138

Branch: refs/heads/develop
Commit: 38c2a138b54d9a87794446447a19707f0a51c4d4
Parents: 1d62a81
Author: Steve Loughran <ste...@apache.org>
Authored: Mon Aug 25 13:01:54 2014 +0100
Committer: Steve Loughran <ste...@apache.org>
Committed: Mon Aug 25 13:01:54 2014 +0100

----------------------------------------------------------------------
 .../apache/slider/test/SliderTestUtils.groovy   | 30 +++++++++++++-------
 1 file changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/38c2a138/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy 
b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 8057356..0036db7 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -743,17 +743,27 @@ class SliderTestUtils extends Assert {
    * Kill any java process with the given grep pattern
    * @param grepString string to grep for
    */
-  public void killJavaProcesses(String grepString, int signal) {
-
-//    assume(!Shell.WINDOWS, "failed to kill -$signal $grepString - no windows 
support ")
-    
-    GString bashCommand = "jps -l| grep ${grepString} | awk '{print \$1}' | 
xargs kill $signal"
-    log.info("Bash command = $bashCommand" )
-    Process bash = ["bash", "-c", bashCommand].execute()
-    bash.waitFor()
+  public int killJavaProcesses(String grepString, int signal) {
+
+    def commandString
+    if (!Shell.WINDOWS) {
+      GString killCommand = "jps -l| grep ${grepString} | awk '{print \$1}' | 
xargs kill $signal"
+      log.info("Command command = $killCommand" )
+
+      commandString = ["bash", "-c", killCommand]
+    } else {
+      /*
+      "jps -l | grep "String" | awk "{print $1}" | xargs -n 1 taskkill /PID"
+       */
+      GString killCommand = "\"jps -l | grep \"${grepString}\" | awk \"{print 
\$1}\" | xargs -n 1 taskkill /PID\""
+      commandString = ["CMD", "/C", killCommand]
+    }
+    Process command = commandString.execute()
+    def exitCode = command.waitFor()
 
-    log.info(bash.in.text)
-    log.error(bash.err.text)
+    log.info(command.in.text)
+    log.error(command.err.text)
+    return exitCode
   }
 
   /**

Reply via email to