Adapt to changes in ExecUtil (#8690)
Signed-off-by: Connor Petty <mistercpp2000+gitsignoff@gmail.com>
This commit is contained in:
parent
178e657d80
commit
0496d35f32
@ -18,9 +18,11 @@ import java.net.DatagramSocket;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InterfaceAddress;
|
import java.net.InterfaceAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@ -73,8 +75,8 @@ public class WakeOnLanUtility {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String cmd = String.format(COMMAND, hostName);
|
String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
|
||||||
String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
|
String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
|
||||||
Matcher matcher = MAC_REGEX.matcher(response);
|
Matcher matcher = MAC_REGEX.matcher(response);
|
||||||
String macAddress = null;
|
String macAddress = null;
|
||||||
|
|
||||||
@ -90,7 +92,8 @@ public class WakeOnLanUtility {
|
|||||||
if (macAddress != null) {
|
if (macAddress != null) {
|
||||||
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
|
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
|
||||||
} else {
|
} 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;
|
return macAddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,25 @@ package org.openhab.binding.network.internal.utils;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.*;
|
import java.net.ConnectException;
|
||||||
import java.util.*;
|
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 java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
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.
|
* Return true if the external arp ping utility (arping) is available and executable on the given path.
|
||||||
*/
|
*/
|
||||||
public ArpPingUtilEnum determineNativeARPpingMethod(String arpToolPath) {
|
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)) {
|
if (StringUtils.isBlank(result)) {
|
||||||
return ArpPingUtilEnum.UNKNOWN_TOOL;
|
return ArpPingUtilEnum.UNKNOWN_TOOL;
|
||||||
} else if (result.contains("Thomas Habets")) {
|
} else if (result.contains("Thomas Habets")) {
|
||||||
|
|||||||
@ -18,9 +18,11 @@ import java.net.DatagramSocket;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InterfaceAddress;
|
import java.net.InterfaceAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@ -73,8 +75,8 @@ public class WakeOnLanUtility {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String cmd = String.format(COMMAND, hostName);
|
String[] cmds = Stream.of(COMMAND.split(" ")).map(arg -> String.format(arg, hostName)).toArray(String[]::new);
|
||||||
String response = ExecUtil.executeCommandLineAndWaitResponse(cmd, CMD_TIMEOUT_MS);
|
String response = ExecUtil.executeCommandLineAndWaitResponse(Duration.ofMillis(CMD_TIMEOUT_MS), cmds);
|
||||||
Matcher matcher = MAC_REGEX.matcher(response);
|
Matcher matcher = MAC_REGEX.matcher(response);
|
||||||
String macAddress = null;
|
String macAddress = null;
|
||||||
|
|
||||||
@ -90,7 +92,8 @@ public class WakeOnLanUtility {
|
|||||||
if (macAddress != null) {
|
if (macAddress != null) {
|
||||||
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
|
LOGGER.debug("MAC address of host {} is {}", hostName, macAddress);
|
||||||
} else {
|
} 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;
|
return macAddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.transform.exec.internal;
|
package org.openhab.transform.exec.internal;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.core.io.net.exec.ExecUtil;
|
import org.openhab.core.io.net.exec.ExecUtil;
|
||||||
@ -64,7 +66,8 @@ public class ExecTransformationService implements TransformationService {
|
|||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
String formattedCommandLine = String.format(commandLine, source);
|
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);
|
logger.trace("command line execution elapsed {} ms", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user