Author: rgodfrey
Date: Sat Jun 20 17:34:44 2015
New Revision: 1686657

URL: http://svn.apache.org/r1686657
Log:
NO-JIRA : Only look for Windows PIDs on Windows

Modified:
    
qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java

Modified: 
qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java?rev=1686657&r1=1686656&r2=1686657&view=diff
==============================================================================
--- 
qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
 (original)
+++ 
qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
 Sat Jun 20 17:34:44 2015
@@ -277,71 +277,74 @@ public class SpawnedBrokerHolder impleme
 
     private List<String> retrieveWindowsPidsIfPossible()
     {
-        try
+        if(SystemUtils.isWindows())
         {
-            Process p = Runtime.getRuntime().exec(new String[] {"wmic", 
"process", "list"});
-            try(BufferedReader reader = new BufferedReader(new 
InputStreamReader(p.getInputStream())))
+            try
             {
-                String line;
-                String headers = reader.readLine();
-                int processIdOffset = headers.indexOf(" ProcessId") + 1;
-                int parentProcessIdOffset = headers.indexOf(" 
ParentProcessId") + 1;
-                String parentProcess = null;
-                Map<String, List<String>> parentProcessMap = new 
HashMap<String, List<String>>();
-
-                while ((line = reader.readLine()) != null)
+                Process p = Runtime.getRuntime().exec(new String[]{"wmic", 
"process", "list"});
+                try (BufferedReader reader = new BufferedReader(new 
InputStreamReader(p.getInputStream())))
                 {
-                    if (line.length() > processIdOffset)
+                    String line;
+                    String headers = reader.readLine();
+                    int processIdOffset = headers.indexOf(" ProcessId") + 1;
+                    int parentProcessIdOffset = headers.indexOf(" 
ParentProcessId") + 1;
+                    String parentProcess = null;
+                    Map<String, List<String>> parentProcessMap = new 
HashMap<String, List<String>>();
+
+                    while ((line = reader.readLine()) != null)
                     {
-                        String processIdStr = line.substring(processIdOffset);
-                        processIdStr = processIdStr.substring(0, 
processIdStr.indexOf(' '));
-                        processIdStr = processIdStr.trim();
-
-                        String parentProcessIdStr = 
line.substring(parentProcessIdOffset);
-                        parentProcessIdStr = parentProcessIdStr.substring(0, 
parentProcessIdStr.indexOf(' '));
-                        parentProcessIdStr = parentProcessIdStr.trim();
-                        if (parentProcessIdStr.length() > 0 && (parentProcess 
== null || parentProcess.equals(
-                                parentProcessIdStr)))
+                        if (line.length() > processIdOffset)
                         {
-                            List<String> children = 
parentProcessMap.get(parentProcessIdStr);
-                            if (children == null)
+                            String processIdStr = 
line.substring(processIdOffset);
+                            processIdStr = processIdStr.substring(0, 
processIdStr.indexOf(' '));
+                            processIdStr = processIdStr.trim();
+
+                            String parentProcessIdStr = 
line.substring(parentProcessIdOffset);
+                            parentProcessIdStr = 
parentProcessIdStr.substring(0, parentProcessIdStr.indexOf(' '));
+                            parentProcessIdStr = parentProcessIdStr.trim();
+                            if (parentProcessIdStr.length() > 0 && 
(parentProcess == null || parentProcess.equals(
+                                    parentProcessIdStr)))
                             {
-                                children = new ArrayList<String>();
-                                parentProcessMap.put(parentProcessIdStr, 
children);
+                                List<String> children = 
parentProcessMap.get(parentProcessIdStr);
+                                if (children == null)
+                                {
+                                    children = new ArrayList<String>();
+                                    parentProcessMap.put(parentProcessIdStr, 
children);
+                                }
+                                children.add(processIdStr);
                             }
-                            children.add(processIdStr);
-                        }
-                        if (line.toLowerCase()
-                                .contains(_brokerCommand.toLowerCase()))
-                        {
-                            parentProcess = processIdStr;
+                            if (line.toLowerCase()
+                                    .contains(_brokerCommand.toLowerCase()))
+                            {
+                                parentProcess = processIdStr;
+                            }
+
                         }
 
                     }
-
-                }
-                LOGGER.debug("Parent process: " + parentProcess);
-                if (parentProcess != null)
-                {
-                    List<String> returnVal = new ArrayList<>();
-                    returnVal.add(parentProcess);
-                    List<String> children = 
parentProcessMap.get(parentProcess);
-                    if (children != null)
+                    LOGGER.debug("Parent process: " + parentProcess);
+                    if (parentProcess != null)
                     {
-                        for (String child : children)
+                        List<String> returnVal = new ArrayList<>();
+                        returnVal.add(parentProcess);
+                        List<String> children = 
parentProcessMap.get(parentProcess);
+                        if (children != null)
                         {
-                            returnVal.add(child);
+                            for (String child : children)
+                            {
+                                returnVal.add(child);
+                            }
                         }
+                        return returnVal;
                     }
-                    return returnVal;
-                }
 
 
+                }
+            }
+            catch (IOException e)
+            {
+                LOGGER.error("Error whilst killing process " + _brokerCommand, 
e);
             }
-        }
-        catch (IOException e)
-        {
-            LOGGER.error("Error whilst killing process " + _brokerCommand, e);
         }
         return null;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to