1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Merge pull request #581 from guusdk/sint_custom_debugger

sint: Allow use of custom SmackDebugger
This commit is contained in:
Florian Schmaus 2024-04-02 12:57:43 +00:00 committed by GitHub
commit 50a04d8556
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 31 deletions

View file

@ -36,6 +36,7 @@ import javax.net.ssl.SSLContext;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.debugger.ConsoleDebugger; import org.jivesoftware.smack.debugger.ConsoleDebugger;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
import org.jivesoftware.smack.util.CollectionUtil; import org.jivesoftware.smack.util.CollectionUtil;
import org.jivesoftware.smack.util.Function; import org.jivesoftware.smack.util.Function;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
@ -61,12 +62,6 @@ public final class Configuration {
serviceAdministration, serviceAdministration,
} }
public enum Debugger {
none,
console,
enhanced,
}
public enum DnsResolver { public enum DnsResolver {
minidns, minidns,
javax, javax,
@ -101,7 +96,7 @@ public final class Configuration {
public final String accountThreePassword; public final String accountThreePassword;
public final Debugger debugger; public final SmackDebuggerFactory debuggerFactory;
public final Set<String> enabledTests; public final Set<String> enabledTests;
@ -148,7 +143,7 @@ public final class Configuration {
} else { } else {
replyTimeout = 47000; replyTimeout = 47000;
} }
debugger = builder.debugger; debuggerFactory = builder.debuggerFactory;
if (StringUtils.isNotEmpty(builder.adminAccountUsername, builder.adminAccountPassword)) { if (StringUtils.isNotEmpty(builder.adminAccountUsername, builder.adminAccountPassword)) {
accountRegistration = AccountRegistration.serviceAdministration; accountRegistration = AccountRegistration.serviceAdministration;
} }
@ -193,16 +188,8 @@ public final class Configuration {
b.setSecurityMode(securityMode); b.setSecurityMode(securityMode);
b.setXmppDomain(service); b.setXmppDomain(service);
switch (debugger) { if (debuggerFactory != null) {
case enhanced: b.setDebuggerFactory(debuggerFactory);
b.setDebuggerFactory(EnhancedDebugger.Factory.INSTANCE);
break;
case console:
b.setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE);
break;
case none:
// Nothing to do :).
break;
} }
}; };
@ -246,7 +233,7 @@ public final class Configuration {
public String accountThreePassword; public String accountThreePassword;
private Debugger debugger = Debugger.none; private SmackDebuggerFactory debuggerFactory;
private Set<String> enabledTests; private Set<String> enabledTests;
@ -352,18 +339,23 @@ public final class Configuration {
case "false": // For backwards compatibility settings with previous boolean setting. case "false": // For backwards compatibility settings with previous boolean setting.
LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"none\" instead"); LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"none\" instead");
case "none": case "none":
debugger = Debugger.none; debuggerFactory = null;
break; break;
case "true": // For backwards compatibility settings with previous boolean setting. case "true": // For backwards compatibility settings with previous boolean setting.
LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"console\" instead"); LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"console\" instead");
case "console": case "console":
debugger = Debugger.console; debuggerFactory = ConsoleDebugger.Factory.INSTANCE;
break; break;
case "enhanced": case "enhanced":
debugger = Debugger.enhanced; debuggerFactory = EnhancedDebugger.Factory.INSTANCE;
break; break;
default: default:
throw new IllegalArgumentException("Unrecognized debugger string: " + debuggerString); try {
final Class<? extends SmackDebuggerFactory> 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; return this;
} }

View file

@ -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.javax.JavaxResolver;
import org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver; import org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver;
import org.jivesoftware.smackx.debugger.EnhancedDebugger;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow; import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
import org.jivesoftware.smackx.iqregister.AccountManager; import org.jivesoftware.smackx.iqregister.AccountManager;
@ -138,12 +139,8 @@ public class SmackIntegrationTestFramework {
exitStatus = 0; exitStatus = 0;
} }
switch (config.debugger) { if (config.debuggerFactory instanceof EnhancedDebugger) {
case enhanced:
EnhancedDebuggerWindow.getInstance().waitUntilClosed(); EnhancedDebuggerWindow.getInstance().waitUntilClosed();
break;
default:
break;
} }
System.exit(exitStatus); System.exit(exitStatus);
@ -175,7 +172,7 @@ public class SmackIntegrationTestFramework {
this.connectionManager = new XmppConnectionManager(this); this.connectionManager = new XmppConnectionManager(this);
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion()); 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 // JUL Debugger will not print any information until configured to print log messages of
// level FINE // level FINE
// TODO configure JUL for log? // TODO configure JUL for log?

View file

@ -125,7 +125,7 @@
* </tr> * </tr>
* <tr> * <tr>
* <td>debugger</td> * <td>debugger</td>
* <td>console for console debugger, enhanced for the enhanced debugger</td> * <td>console for console debugger, enhanced for the enhanced debugger, or the name of a class that implements SmackDebuggerFactory for a custom debugger</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>enabledTests</td> * <td>enabledTests</td>
@ -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 * 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. * connection, hopefully enough to diagnose what went wrong.
* </p> * </p>
* <p>
* 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.
* </p>
* <p>
* Example:
* </p>
*
* <pre>{@code
* $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.debugger="org.example.MyDebugger$Factory"
* }</pre>
* <h3>Debugging in the IDE</h3> * <h3>Debugging in the IDE</h3>
* <p> * <p>
* If the output isn't enough, you may need to debug and inspect running code within the IDE. Depending on the IDE, in * 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 @@
* </p> * </p>
* *
* <pre>{@code * <pre>{@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
* }</pre> * }</pre>
*/ */
package org.igniterealtime.smack.inttest; package org.igniterealtime.smack.inttest;