From 35d7b9b0995677ccc1b754c58730cc5a4bd8f356 Mon Sep 17 00:00:00 2001 From: Nick Tan Date: Sun, 14 Jan 2024 22:24:31 -0800 Subject: [PATCH] feat: incorporate with the deprecated api cleanup per upstream https://github.com/testng-team/testng/commit/94bf0111c9f721d788db21670edb352cc5fe044f --- .../java/org/testng/remote/RemoteTestNG.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/remote/src/main/java/org/testng/remote/RemoteTestNG.java b/remote/src/main/java/org/testng/remote/RemoteTestNG.java index 306e2d1..6db9106 100644 --- a/remote/src/main/java/org/testng/remote/RemoteTestNG.java +++ b/remote/src/main/java/org/testng/remote/RemoteTestNG.java @@ -68,14 +68,17 @@ public static void main(String[] args) throws ParameterException { remoteTestNg.dontExit(ra.dontExit); boolean debug = ra.debug; - try { - Field debugField = CommandLineArgs.class.getDeclaredField("debug"); - if (debugField.getBoolean(cla)) { - debug = true; - } - } catch (NoSuchFieldException | IllegalAccessException e) { - if (isDebug()) { - e.printStackTrace(); + if (!debug) { + // use reflection below for backward compatibility of testng version < 7.10.0 + try { + Field debugField = CommandLineArgs.class.getDeclaredField("debug"); + if (debugField.getBoolean(cla)) { + debug = true; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + if (isDebug()) { + e.printStackTrace(); + } } } m_debug = debug; @@ -240,7 +243,22 @@ private static void initAndRun(IRemoteTestNG remoteTestNg, String[] args, Comman }); } remoteTestNg.configure(cla); - remoteTestNg.setHost(ra.host); + String host = ra.host; + if (host == null || host.isBlank()) { + // use reflection below for backward compatibility of testng version < 7.10.0 + try { + Field hostField = CommandLineArgs.class.getDeclaredField("host"); + Object h = hostField.get(cla); + if (h != null) { + host = (String) h; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + if (isDebug()) { + e.printStackTrace(); + } + } + } + remoteTestNg.setHost(host); remoteTestNg.setSerPort(ra.serPort); remoteTestNg.setProtocol(ra.protocol); if (isVerbose()) {