1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Add org.jivesoftware.smack.Smack with getVersion() and ensureInitialized()

This commit is contained in:
Florian Schmaus 2020-11-08 22:27:57 +01:00
parent df96c57093
commit 1f5ada4822
11 changed files with 62 additions and 19 deletions

View file

@ -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 {

View file

@ -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());

View 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");
}
}

View file

@ -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;
}

View file

@ -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")

View file

@ -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());

View file

@ -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