From 92c45e0d29eef8d52897e698a8c00f78c4c68b62 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Thu, 21 Mar 2024 16:18:14 +0100 Subject: [PATCH] sint: Allow use of custom SmackDebugger Refactors the Smack Integration Test configuration to allow for a classname for a SmackDebugger(Factory) to be provided. --- .../smack/inttest/Configuration.java | 38 ++++++++----------- .../SmackIntegrationTestFramework.java | 9 ++--- .../smack/inttest/package-info.java | 16 +++++++- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java index 0df16141c..3ab8f9e15 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java @@ -36,6 +36,7 @@ import javax.net.ssl.SSLContext; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.jivesoftware.smack.debugger.ConsoleDebugger; +import org.jivesoftware.smack.debugger.SmackDebuggerFactory; import org.jivesoftware.smack.util.CollectionUtil; import org.jivesoftware.smack.util.Function; import org.jivesoftware.smack.util.Objects; @@ -61,12 +62,6 @@ public final class Configuration { serviceAdministration, } - public enum Debugger { - none, - console, - enhanced, - } - public enum DnsResolver { minidns, javax, @@ -101,7 +96,7 @@ public final class Configuration { public final String accountThreePassword; - public final Debugger debugger; + public final SmackDebuggerFactory debuggerFactory; public final Set enabledTests; @@ -148,7 +143,7 @@ public final class Configuration { } else { replyTimeout = 47000; } - debugger = builder.debugger; + debuggerFactory = builder.debuggerFactory; if (StringUtils.isNotEmpty(builder.adminAccountUsername, builder.adminAccountPassword)) { accountRegistration = AccountRegistration.serviceAdministration; } @@ -193,16 +188,8 @@ public final class Configuration { b.setSecurityMode(securityMode); b.setXmppDomain(service); - switch (debugger) { - case enhanced: - b.setDebuggerFactory(EnhancedDebugger.Factory.INSTANCE); - break; - case console: - b.setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE); - break; - case none: - // Nothing to do :). - break; + if (debuggerFactory != null) { + b.setDebuggerFactory(debuggerFactory); } }; @@ -246,7 +233,7 @@ public final class Configuration { public String accountThreePassword; - private Debugger debugger = Debugger.none; + private SmackDebuggerFactory debuggerFactory; private Set enabledTests; @@ -352,18 +339,23 @@ public final class Configuration { case "false": // For backwards compatibility settings with previous boolean setting. LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"none\" instead"); case "none": - debugger = Debugger.none; + debuggerFactory = null; break; case "true": // For backwards compatibility settings with previous boolean setting. LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"console\" instead"); case "console": - debugger = Debugger.console; + debuggerFactory = ConsoleDebugger.Factory.INSTANCE; break; case "enhanced": - debugger = Debugger.enhanced; + debuggerFactory = EnhancedDebugger.Factory.INSTANCE; break; default: - throw new IllegalArgumentException("Unrecognized debugger string: " + debuggerString); + try { + final Class aClass = Class.forName(debuggerString).asSubclass(SmackDebuggerFactory.class); + debuggerFactory = aClass.getConstructor().newInstance(); + } catch (Exception e) { + throw new IllegalArgumentException("Unable to construct debugger from value: " + debuggerString, e); + } } return this; } diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index 8be908fb0..aedd55221 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -64,6 +64,7 @@ import org.jivesoftware.smack.util.dns.dnsjava.DNSJavaResolver; import org.jivesoftware.smack.util.dns.javax.JavaxResolver; import org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver; +import org.jivesoftware.smackx.debugger.EnhancedDebugger; import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow; import org.jivesoftware.smackx.iqregister.AccountManager; @@ -138,12 +139,8 @@ public class SmackIntegrationTestFramework { exitStatus = 0; } - switch (config.debugger) { - case enhanced: + if (config.debuggerFactory instanceof EnhancedDebugger) { EnhancedDebuggerWindow.getInstance().waitUntilClosed(); - break; - default: - break; } System.exit(exitStatus); @@ -175,7 +172,7 @@ public class SmackIntegrationTestFramework { this.connectionManager = new XmppConnectionManager(this); LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion()); - if (config.debugger != Configuration.Debugger.none) { + if (config.debuggerFactory != null) { // JUL Debugger will not print any information until configured to print log messages of // level FINE // TODO configure JUL for log? diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java index 2caf8d792..46bea2cd0 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java @@ -125,7 +125,7 @@ * * * debugger - * ‘console’ for console debugger, ‘enhanced’ for the enhanced debugger + * ‘console’ for console debugger, ‘enhanced’ for the enhanced debugger, or the name of a class that implements SmackDebuggerFactory for a custom debugger * * * enabledTests @@ -284,6 +284,18 @@ * Debug Window launching when your tests launch, and you'll get a stanza-by-stanza account of what happened on each * connection, hopefully enough to diagnose what went wrong. *

+ *

+ * Lastly, you can provide a custom debugger, by providing the fully qualified name of a class that implements + * {@link org.jivesoftware.smack.debugger.SmackDebuggerFactory}. The provided factory must declare a public constructor + * that takes no arguments. + *

+ *

+ * Example: + *

+ * + *
{@code
+ * $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.debugger="org.example.MyDebugger$Factory"
+ * }
*

Debugging in the IDE

*

* If the output isn't enough, you may need to debug and inspect running code within the IDE. Depending on the IDE, in @@ -302,7 +314,7 @@ *

* *
{@code
- * $ gradle integrationTest -Dsinttest.service=my.xmppserivce.org -Dsinttest.testPackages=org.mypackage,org.otherpackage
+ * $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.testPackages=org.mypackage,org.otherpackage
  * }
*/ package org.igniterealtime.smack.inttest;