From 98661fde91c5a5b366f3aa142c0513b19e754093 Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sun, 13 Oct 2024 13:44:19 +0200 Subject: [PATCH] [pjlinkdevice] Remove org.apache.common (#14430) * Remove org.apache.common Signed-off-by: Leo Siepel Signed-off-by: Ciprian Pascu --- .../AbstractDiscoveryParticipant.java | 31 ++----------------- .../discovery/DiscoveryParticipantClass1.java | 30 ++---------------- 2 files changed, 5 insertions(+), 56 deletions(-) diff --git a/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/AbstractDiscoveryParticipant.java b/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/AbstractDiscoveryParticipant.java index 04c338ca54f..3415350fd4a 100644 --- a/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/AbstractDiscoveryParticipant.java +++ b/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/AbstractDiscoveryParticipant.java @@ -13,11 +13,7 @@ package org.openhab.binding.pjlinkdevice.internal.discovery; import java.net.InetAddress; -import java.net.InterfaceAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -27,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.pjlinkdevice.internal.PJLinkDeviceBindingConstants; import org.openhab.core.config.discovery.AbstractDiscoveryService; +import org.openhab.core.net.NetUtil; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingUID; import org.slf4j.Logger; @@ -63,7 +60,7 @@ public abstract class AbstractDiscoveryParticipant extends AbstractDiscoveryServ @Override protected void startScan() { logger.trace("PJLinkProjectorDiscoveryParticipant startScan"); - Set addressesToScan = generateAddressesToScan(); + List addressesToScan = NetUtil.getFullRangeOfAddressesToScan(); scannedIPcount = 0; for (InetAddress ip : addressesToScan) { getExecutorService().execute(() -> { @@ -106,26 +103,4 @@ public abstract class AbstractDiscoveryParticipant extends AbstractDiscoveryServ } protected abstract void checkAddress(InetAddress ip, int tcpPort, int timeout); - - private Set generateAddressesToScan() { - try { - Set addressesToScan = new HashSet<>(); - ArrayList interfaces = java.util.Collections - .list(NetworkInterface.getNetworkInterfaces()); - for (NetworkInterface networkInterface : interfaces) { - if (networkInterface.isLoopback() || !networkInterface.isUp()) { - continue; - } - for (InterfaceAddress i : networkInterface.getInterfaceAddresses()) { - collectAddressesToScan(addressesToScan, i); - } - } - return addressesToScan; - } catch (SocketException e) { - logger.debug("Could not enumerate network interfaces", e); - } - return new HashSet<>(); - } - - protected abstract void collectAddressesToScan(Set addressesToScan, InterfaceAddress i); } diff --git a/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/DiscoveryParticipantClass1.java b/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/DiscoveryParticipantClass1.java index 642fd515375..10dbe7aef7a 100644 --- a/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/DiscoveryParticipantClass1.java +++ b/bundles/org.openhab.binding.pjlinkdevice/src/main/java/org/openhab/binding/pjlinkdevice/internal/discovery/DiscoveryParticipantClass1.java @@ -13,15 +13,11 @@ package org.openhab.binding.pjlinkdevice.internal.discovery; import java.io.IOException; -import java.net.Inet4Address; import java.net.InetAddress; -import java.net.InterfaceAddress; -import java.net.UnknownHostException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Set; -import org.apache.commons.net.util.SubnetUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.pjlinkdevice.internal.PJLinkDeviceBindingConstants; import org.openhab.binding.pjlinkdevice.internal.device.PJLinkDevice; @@ -41,33 +37,11 @@ import org.osgi.service.component.annotations.Component; @NonNullByDefault public class DiscoveryParticipantClass1 extends AbstractDiscoveryParticipant { public DiscoveryParticipantClass1() throws IllegalArgumentException { - super(Set.of(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true); + super(Collections.singleton(PJLinkDeviceBindingConstants.THING_TYPE_PJLINK), 60, true); logger.trace("PJLinkProjectorDiscoveryParticipant constructor"); } - @Override - protected void collectAddressesToScan(Set addressesToScan, InterfaceAddress i) { - // only scan IPv4 - if (!(i.getAddress() instanceof Inet4Address)) { - return; - } - // only scan Class C networks - if (i.getNetworkPrefixLength() < 24) { - return; - } - - SubnetUtils utils = new SubnetUtils(i.getAddress().getHostAddress() + "/" + i.getNetworkPrefixLength()); - for (String addressToScan : utils.getInfo().getAllAddresses()) { - try { - logger.debug("Add address to scan: {}", addressToScan); - addressesToScan.add(InetAddress.getByName(addressToScan)); - } catch (UnknownHostException e) { - logger.debug("Unknown Host", e); - } - } - } - @Override protected void checkAddress(InetAddress ip, int tcpPort, int timeout) { PJLinkDevice device = new PJLinkDevice(tcpPort, ip, null, timeout);