From b892fc2a04d21144340bc7418632d430c3ac354a Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Mon, 25 Jan 2021 22:23:39 +0200 Subject: [PATCH] exclude windows fetchers/pingers (that rely on JNA) from non-windows builds --- .idea/ipscan.iml | 2 +- build.gradle | 6 ++++-- src/net/azib/ipscan/config/ComponentRegistry.java | 6 +++--- src/net/azib/ipscan/core/net/PingerRegistry.java | 5 +++-- test/net/azib/ipscan/core/net/PingerRegistryTest.java | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.idea/ipscan.iml b/.idea/ipscan.iml index 53deaf4d..860c6281 100644 --- a/.idea/ipscan.iml +++ b/.idea/ipscan.iml @@ -1,5 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index e1831097..c37d53d1 100644 --- a/build.gradle +++ b/build.gradle @@ -117,7 +117,10 @@ def packageTask(String platform, def moreLibs = [], Closure doMore) { 'com/sun/jna/*/*.a', 'com/sun/jna/*/*.so', 'com/sun/jna/*/*.jnilib', - "com/sun/jna/win32-${platform == 'win32' ? 'x86-64' : platform == 'win64' ? 'x86' : '*'}/*.dll" + "com/sun/jna/win32-${platform == 'win32' ? 'x86-64' : platform == 'win64' ? 'x86' : '*'}/*.dll", + // Win-specific stuff + !platform.startsWith('win') ? 'net/azib/ipscan/core/net/Win*' : '', + !platform.startsWith('win') ? 'net/azib/ipscan/fetchers/Win*' : '' ) with jar @@ -139,7 +142,6 @@ def minimizeTask(String platform, Closure doMore) { libraryjars System.getProperty('java.home') + "/jmods/java.logging.jmod" libraryjars System.getProperty('java.home') + "/jmods/java.net.http.jmod" libraryjars System.getProperty('java.home') + "/jmods/java.prefs.jmod" - libraryjars 'lib/jna.jar' dontobfuscate dontoptimize dontnote '**' diff --git a/src/net/azib/ipscan/config/ComponentRegistry.java b/src/net/azib/ipscan/config/ComponentRegistry.java index ca1eb7d1..fda0e225 100644 --- a/src/net/azib/ipscan/config/ComponentRegistry.java +++ b/src/net/azib/ipscan/config/ComponentRegistry.java @@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.Shell; * @author Anton Keks */ public class ComponentRegistry { - public void register(Injector i) { + public void register(Injector i) throws Exception { Display display = Display.getDefault(); i.register(Display.class, display); Shell shell = new Shell(); @@ -43,13 +43,13 @@ public class ComponentRegistry { i.register(TXTExporter.class, CSVExporter.class, XMLExporter.class, IPListExporter.class); i.register(IPFetcher.class, PingFetcher.class, PingTTLFetcher.class, HostnameFetcher.class, PortsFetcher.class); - i.register(MACFetcher.class, Platform.WINDOWS ? new WinMACFetcher() : new UnixMACFetcher()); + i.register(MACFetcher.class, (MACFetcher) Class.forName(MACFetcher.class.getPackage().getName() + (Platform.WINDOWS ? ".WinMACFetcher" : ".UnixMACFetcher")).newInstance()); i.register(CommentFetcher.class, FilteredPortsFetcher.class, WebDetectFetcher.class, HTTPSenderFetcher.class, NetBIOSInfoFetcher.class, PacketLossFetcher.class, HTTPProxyFetcher.class, MACVendorFetcher.class); i.register(FeederRegistry.class, i.require(FeederGUIRegistry.class)); } - public Injector init() { + public Injector init() throws Exception { Injector i = new Injector(); new ConfigModule().register(i); new ComponentRegistry().register(i); diff --git a/src/net/azib/ipscan/core/net/PingerRegistry.java b/src/net/azib/ipscan/core/net/PingerRegistry.java index 68b73504..901e4d8f 100644 --- a/src/net/azib/ipscan/core/net/PingerRegistry.java +++ b/src/net/azib/ipscan/core/net/PingerRegistry.java @@ -33,12 +33,13 @@ public class PingerRegistry { /** All available Pinger implementations */ Map> pingers; - public PingerRegistry(ScannerConfig scannerConfig) { + @SuppressWarnings("unchecked") + public PingerRegistry(ScannerConfig scannerConfig) throws ClassNotFoundException { this.scannerConfig = scannerConfig; pingers = new LinkedHashMap<>(); if (Platform.WINDOWS) - pingers.put("pinger.windows", WindowsPinger.class); + pingers.put("pinger.windows", (Class) Class.forName(getClass().getPackage().getName() + ".WindowsPinger")); if (Platform.LINUX && Platform.ARCH_64) pingers.put("pinger.icmp", ICMPSharedPinger.class); pingers.put("pinger.udp", UDPPinger.class); diff --git a/test/net/azib/ipscan/core/net/PingerRegistryTest.java b/test/net/azib/ipscan/core/net/PingerRegistryTest.java index 510c3cab..93fdaafc 100644 --- a/test/net/azib/ipscan/core/net/PingerRegistryTest.java +++ b/test/net/azib/ipscan/core/net/PingerRegistryTest.java @@ -20,7 +20,7 @@ public class PingerRegistryTest { } @Test - public void getRegisteredNames() { + public void getRegisteredNames() throws ClassNotFoundException { String[] names = new PingerRegistry(null).getRegisteredNames(); assertNotNull(names); for (String name : names) { @@ -54,7 +54,7 @@ public class PingerRegistryTest { } @Test - public void checkSelectedPinger() { + public void checkSelectedPinger() throws ClassNotFoundException { ScannerConfig config = Config.getConfig().forScanner(); PingerRegistry registry = new PingerRegistry(config);