]> git.basschouten.com Git - openhab-addons.git/commitdiff
Adapt to changes in ExecUtil (#8690)
authorConnor Petty <mistercpp2000@gmail.com>
Thu, 8 Oct 2020 19:08:11 +0000 (12:08 -0700)
committerGitHub <noreply@github.com>
Thu, 8 Oct 2020 19:08:11 +0000 (21:08 +0200)
Signed-off-by: Connor Petty <mistercpp2000+gitsignoff@gmail.com>
bundles/org.openhab.binding.lgwebos/src/main/java/org/openhab/binding/lgwebos/internal/WakeOnLanUtility.java
bundles/org.openhab.binding.network/src/main/java/org/openhab/binding/network/internal/utils/NetworkUtils.java
bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/WakeOnLanUtility.java
bundles/org.openhab.transform.exec/src/main/java/org/openhab/transform/exec/internal/ExecTransformationService.java

index 3592f01a02718407b330962687e3eb272a9e9b0d..913e8230665125e694aadf33c17ddefb124b6ed1 100644 (file)
@@ -18,9 +18,11 @@ import java.net.DatagramSocket;
 import java.net.InetAddress;
 import java.net.InterfaceAddress;
 import java.net.NetworkInterface;
+import java.time.Duration;
 import java.util.Enumeration;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -73,8 +75,8 @@ public class WakeOnLanUtility {
             return null;
         }
 
-        String cmd = String.format(COMMAND, hostName);
-        String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
+        String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
+        String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
         Matcher matcher = MAC_REGEX.matcher(response);
         String macAddress = null;
 
@@ -90,7 +92,8 @@ public class WakeOnLanUtility {
         if (macAddress != null) {
             LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
         } else {
-            LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}", cmd, hostName, response);
+            LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}",
+                    String.format(COMMAND, hostName), hostName, response);
         }
         return macAddress;
     }
index 0f7d350a50d49360a5bdbae4ba5d774b8426e522..072e2059644cdab01caf20fdb56ad603907389b7 100644 (file)
@@ -15,8 +15,25 @@ package org.openhab.binding.network.internal.utils;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.net.*;
-import java.util.*;
+import java.net.ConnectException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.NoRouteToHostException;
+import java.net.PortUnreachableException;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.time.Duration;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Optional;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.apache.commons.lang.StringUtils;
@@ -185,7 +202,7 @@ public class NetworkUtils {
      * Return true if the external arp ping utility (arping) is available and executable on the given path.
      */
     public ArpPingUtilEnum determineNativeARPpingMethod(String arpToolPath) {
-        String result = ExecUtil.executeCommandLineAndWaitResponse(arpToolPath + " --help", 100);
+        String result = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(100), arpToolPath, "--help");
         if (StringUtils.isBlank(result)) {
             return ArpPingUtilEnum.UNKNOWN_TOOL;
         } else if (result.contains("Thomas Habets")) {
index 2b4c97f30613833be00213b707941da9c9b5a594..2a7e563f6dca52949fb80a4f9e550f2c113f6b85 100644 (file)
@@ -18,9 +18,11 @@ import java.net.DatagramSocket;
 import java.net.InetAddress;
 import java.net.InterfaceAddress;
 import java.net.NetworkInterface;
+import java.time.Duration;
 import java.util.Enumeration;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -73,8 +75,8 @@ public class WakeOnLanUtility {
             return null;
         }
 
-        String cmd = String.format(COMMAND, hostName);
-        String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
+        String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
+        String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
         Matcher matcher = MAC_REGEX.matcher(response);
         String macAddress = null;
 
@@ -90,7 +92,8 @@ public class WakeOnLanUtility {
         if (macAddress != null) {
             LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
         } else {
-            LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}", cmd, hostName, response);
+            LOGGER.debug("Problem executing command {} to retrieve MAC address for {}: {}",
+                    String.format(COMMAND, hostName), hostName, response);
         }
         return macAddress;
     }
index 85e283447cbe5a2cbd66d2336382024d6074ed3c..3d74b563d7f308f883e84e095674ccb8bbf83710 100644 (file)
@@ -12,6 +12,8 @@
  */
 package org.openhab.transform.exec.internal;
 
+import java.time.Duration;
+
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.core.io.net.exec.ExecUtil;
@@ -64,7 +66,8 @@ public class ExecTransformationService implements TransformationService {
         long startTime = System.currentTimeMillis();
 
         String formattedCommandLine = String.format(commandLine, source);
-        String result = ExecUtil.executeCommandLineAndWaitResponse(formattedCommandLine, 5000);
+        String result = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofSeconds(5),
+                formattedCommandLine.split(" "));
         logger.trace("command line execution elapsed {} ms", System.currentTimeMillis() - startTime);
 
         return result;