mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Merge branch '4.4'
This commit is contained in:
commit
71f5cfe3da
28 changed files with 380 additions and 102 deletions
|
@ -33,6 +33,7 @@ dependencies {
|
|||
testFixturesApi "org.assertj:assertj-core:3.11.1"
|
||||
testFixturesApi "org.xmlunit:xmlunit-assertj:$xmlUnitVersion"
|
||||
testFixturesApi 'org.hamcrest:hamcrest-library:2.2'
|
||||
testFixturesApi 'com.google.guava:guava:28.2-jre'
|
||||
}
|
||||
|
||||
class CreateFileTask extends DefaultTask {
|
||||
|
|
|
@ -172,8 +172,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());
|
||||
|
|
53
smack-core/src/main/java/org/jivesoftware/smack/Smack.java
Normal file
53
smack-core/src/main/java/org/jivesoftware/smack/Smack.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
* 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.io.InputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Smack {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Smack.class.getName());
|
||||
|
||||
private static final String SMACK_ORG = "org.jivesoftware";
|
||||
|
||||
public static final String SMACK_PACKAGE = SMACK_ORG + ".smack";
|
||||
|
||||
/**
|
||||
* Returns the Smack version information, eg "1.3.0".
|
||||
*
|
||||
* @return the Smack version information.
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return SmackInitialization.SMACK_VERSION;
|
||||
}
|
||||
|
||||
private static final String NOTICE_RESOURCE = SMACK_PACKAGE + "/NOTICE";
|
||||
|
||||
public static InputStream getNoticeStream() {
|
||||
return ClassLoader.getSystemResourceAsStream(NOTICE_RESOURCE);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public abstract class IqBuilder<IB extends IqBuilder<IB, I>, I extends IQ>
|
|||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract I build();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
* Copyright 2019-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.
|
||||
|
@ -41,4 +41,9 @@ public final class IqData extends AbstractIqBuilder<IqData> {
|
|||
public IqData getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stanza build() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public abstract class MessageOrPresenceBuilder<MP extends MessageOrPresence<? ex
|
|||
super(stanzaId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract MP build();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
* Copyright 2019-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.
|
||||
|
@ -184,6 +184,8 @@ public abstract class StanzaBuilder<B extends StanzaBuilder<B>> implements Stanz
|
|||
return getThis();
|
||||
}
|
||||
|
||||
public abstract Stanza build();
|
||||
|
||||
public abstract B getThis();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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")
|
||||
|
|
1
smack-core/src/main/resources/org.jivesoftware.smack/NOTICE
Symbolic link
1
smack-core/src/main/resources/org.jivesoftware.smack/NOTICE
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../../../NOTICE
|
|
@ -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());
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* 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 static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SmackTest {
|
||||
|
||||
@Test
|
||||
public void getNoticeStreamTest() throws IOException {
|
||||
Set<String> expectedStrings = Sets.newHashSet(
|
||||
"Florian Schmaus"
|
||||
, "Paul Schaub"
|
||||
);
|
||||
int maxLineLength = 0;
|
||||
|
||||
try (InputStream inputStream = Smack.getNoticeStream()) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
|
||||
while (reader.ready()) {
|
||||
String line = reader.readLine();
|
||||
|
||||
int lineLength = line.length();
|
||||
maxLineLength = Math.max(maxLineLength, lineLength);
|
||||
|
||||
expectedStrings.removeIf(s -> s.equals(line));
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(expectedStrings.isEmpty());
|
||||
assertTrue(maxLineLength < 60);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue