mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-21 22:02:06 +01:00
Add org.jivesoftware.smack.Smack with getVersion() and ensureInitialized()
This commit is contained in:
parent
df96c57093
commit
1f5ada4822
11 changed files with 62 additions and 19 deletions
|
@ -171,8 +171,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
private static final AtomicInteger connectionCounter = new AtomicInteger(0);
|
||||
|
||||
static {
|
||||
// Ensure the SmackConfiguration class is loaded by calling a method in it.
|
||||
SmackConfiguration.getVersion();
|
||||
Smack.ensureInitialized();
|
||||
}
|
||||
|
||||
protected enum SyncPointState {
|
||||
|
|
|
@ -112,9 +112,7 @@ import org.minidns.util.InetAddressUtil;
|
|||
public abstract class ConnectionConfiguration {
|
||||
|
||||
static {
|
||||
// Ensure that Smack is initialized when ConnectionConfiguration is used, or otherwise e.g.
|
||||
// SmackConfiguration.DEBUG may not be initialized yet.
|
||||
SmackConfiguration.getVersion();
|
||||
Smack.ensureInitialized();
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ConnectionConfiguration.class.getName());
|
||||
|
|
42
smack-core/src/main/java/org/jivesoftware/smack/Smack.java
Normal file
42
smack-core/src/main/java/org/jivesoftware/smack/Smack.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Smack {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Smack.class.getName());
|
||||
|
||||
/**
|
||||
* Returns the Smack version information, eg "1.3.0".
|
||||
*
|
||||
* @return the Smack version information.
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return SmackInitialization.SMACK_VERSION;
|
||||
}
|
||||
|
||||
public static void ensureInitialized() {
|
||||
if (SmackConfiguration.isSmackInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String version = getVersion();
|
||||
LOGGER.finest("Smack " + version + " has been initialized");
|
||||
}
|
||||
}
|
|
@ -105,7 +105,10 @@ public final class SmackConfiguration {
|
|||
* Returns the Smack version information, eg "1.3.0".
|
||||
*
|
||||
* @return the Smack version information.
|
||||
* @deprecated use {@link Smack#getVersion()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.6
|
||||
public static String getVersion() {
|
||||
return SmackInitialization.SMACK_VERSION;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Nonza;
|
||||
|
@ -122,7 +122,7 @@ public final class ProviderManager {
|
|||
// registered providers do not get overwritten by a following Smack
|
||||
// initialization. This guarantees that Smack is initialized before a
|
||||
// new provider is registered
|
||||
SmackConfiguration.getVersion();
|
||||
Smack.ensureInitialized();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -49,8 +49,8 @@ public class SmackConfigurationTest {
|
|||
// *every* test, those tests are currently disabled. Hopefully this will change in the future.
|
||||
@Ignore
|
||||
@Test
|
||||
public void smackconfigurationVersionShouldInitialzieSmacktTest() {
|
||||
SmackConfiguration.getVersion();
|
||||
public void smackEnsureInitializedShouldInitialzieSmacktTest() {
|
||||
Smack.ensureInitialized();
|
||||
|
||||
// Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized.
|
||||
assertTrue(SmackConfiguration.isSmackInitialized());
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.jivesoftware.smack.test.util;
|
|||
import java.security.Security;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64.Encoder;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
@ -31,7 +31,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|||
public class SmackTestSuite {
|
||||
|
||||
static {
|
||||
SmackConfiguration.getVersion();
|
||||
Smack.ensureInitialized();
|
||||
org.jivesoftware.smack.util.stringencoder.Base64.setEncoder(new Encoder() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,7 +43,7 @@ import javax.swing.JPopupMenu;
|
|||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
|
||||
/**
|
||||
|
@ -232,7 +232,7 @@ public final class EnhancedDebuggerWindow {
|
|||
versionPanel.setLayout(new BoxLayout(versionPanel, BoxLayout.X_AXIS));
|
||||
versionPanel.setMaximumSize(new Dimension(2000, 31));
|
||||
versionPanel.add(new JLabel(" Smack version: "));
|
||||
JFormattedTextField field = new JFormattedTextField(SmackConfiguration.getVersion());
|
||||
JFormattedTextField field = new JFormattedTextField(Smack.getVersion());
|
||||
field.setEditable(false);
|
||||
field.setBorder(null);
|
||||
versionPanel.add(field);
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.WeakHashMap;
|
|||
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
@ -152,7 +152,7 @@ public final class VersionManager extends Manager {
|
|||
|
||||
private static Version generateVersionFrom(String name, String version, String os) {
|
||||
if (autoAppendSmackVersion) {
|
||||
name += " (Smack " + SmackConfiguration.getVersion() + ')';
|
||||
name += " (Smack " + Smack.getVersion() + ')';
|
||||
}
|
||||
return new Version(name, version, os);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.AbstractXMPPConnection;
|
||||
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
|
@ -171,7 +172,7 @@ public class SmackIntegrationTestFramework {
|
|||
// Create a connection manager *after* we created the testRunId (in testRunResult).
|
||||
this.connectionManager = new XmppConnectionManager(this);
|
||||
|
||||
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + SmackConfiguration.getVersion());
|
||||
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion());
|
||||
if (config.debugger != Configuration.Debugger.none) {
|
||||
// JUL Debugger will not print any information until configured to print log messages of
|
||||
// level FINE
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Florian Schmaus
|
||||
* Copyright 2016-2020 Florian Schmaus
|
||||
*
|
||||
* This file is part of smack-repl.
|
||||
*
|
||||
|
@ -20,13 +20,13 @@
|
|||
*/
|
||||
package org.igniterealtime.smack.smackrepl;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Smack;
|
||||
import org.jivesoftware.smack.util.dns.javax.JavaxResolver;
|
||||
|
||||
public class SmackRepl {
|
||||
|
||||
public static void init() {
|
||||
SmackConfiguration.getVersion();
|
||||
Smack.ensureInitialized();
|
||||
// smack-repl also pulls in smack-resolver-minidns which has higher precedence the smack-resolver-javax but
|
||||
// won't work on Java SE platforms. Therefore explicitly setup JavaxResolver.
|
||||
JavaxResolver.setup();
|
||||
|
|
Loading…
Reference in a new issue