Skip to content

Commit 944f8ae

Browse files
committed
Add smack-websocket-java11
This also lifts a bunch of logic from smack-websocket-okhttp into smack-websocket. Furthermore, the following subprojects require now Java 11: - smack-integration-test - smack-omemo-signal-integration-test - smack-repl - smack-websocket-java11 Related tracking issue: SMACK-835
1 parent cd40455 commit 944f8ae

File tree

24 files changed

+440
-161
lines changed

24 files changed

+440
-161
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
runs-on: ubuntu-20.04
1313
strategy:
1414
matrix:
15-
java: [ 1.8, 11 ]
15+
java:
16+
- 11
1617

1718
steps:
1819
- name: Checkout

build.gradle

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ plugins {
2020

2121
apply plugin: 'org.kordamp.gradle.markdown'
2222

23+
ext {
24+
java11Projects = [
25+
':smack-integration-test',
26+
':smack-omemo-signal-integration-test',
27+
':smack-repl',
28+
':smack-websocket-java11',
29+
].collect { project(it) }
30+
java8Projects = allprojects - java11Projects
31+
}
32+
33+
configure (java8Projects) {
34+
ext {
35+
javaCompatilibity = JavaVersion.VERSION_1_8
36+
}
37+
}
38+
39+
configure (java11Projects) {
40+
ext {
41+
javaCompatilibity = JavaVersion.VERSION_11
42+
}
43+
}
44+
2345
allprojects {
2446
apply plugin: 'java-library'
2547
apply plugin: 'java-test-fixtures'
@@ -136,7 +158,6 @@ allprojects {
136158
// Default to true
137159
useSonatype = true
138160
}
139-
javaCompatilibity = JavaVersion.VERSION_1_8
140161
javaMajor = javaCompatilibity.getMajorVersion()
141162
}
142163
group = 'org.igniterealtime.smack'

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ include 'smack-core',
3232
'smack-openpgp',
3333
'smack-websocket',
3434
'smack-websocket-okhttp',
35+
'smack-websocket-java11',
3536
'smack-xmlparser',
3637
'smack-xmlparser-stax',
3738
'smack-xmlparser-xpp3'

smack-core/src/main/java/org/jivesoftware/smack/c2s/XmppClientToServerTransport.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ protected XmppClientToServerTransport(ModularXmppClientToServerConnectionInterna
5454

5555
public abstract SSLSession getSslSession();
5656

57-
public abstract boolean isConnected();
58-
5957
public boolean isTransportSecured() {
6058
return getSslSession() != null;
6159
}

smack-core/src/main/java/org/jivesoftware/smack/util/rce/RemoteConnectionEndpoint.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2020 Florian Schmaus
3+
* Copyright 2020-2021 Florian Schmaus
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -32,6 +32,10 @@ public interface RemoteConnectionEndpoint {
3232

3333
String getDescription();
3434

35+
default String getRawString() {
36+
return toString();
37+
}
38+
3539
class InetSocketAddressCoupling<RCE extends RemoteConnectionEndpoint> {
3640
private final RCE connectionEndpoint;
3741
private final InetSocketAddress inetSocketAddress;

smack-integration-test/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ applicationDefaultJvmArgs = ["-enableassertions"]
99
dependencies {
1010
api project(':smack-java8-full')
1111
api project(':smack-resolver-dnsjava')
12+
implementation project(':smack-websocket-java11')
1213
implementation "com.google.guava:guava:${guavaVersion}"
1314
compile 'org.reflections:reflections:0.9.12'
1415
compile 'eu.geekplace.javapinning:java-pinning-java7:1.1.0-alpha1'

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/AbstractSmackSpecificLowLevelIntegrationTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2018-2020 Florian Schmaus
3+
* Copyright 2018-2021 Florian Schmaus
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -30,24 +30,21 @@ public abstract class AbstractSmackSpecificLowLevelIntegrationTest<C extends Abs
3030

3131
private final SmackIntegrationTestEnvironment environment;
3232

33-
protected final Class<C> connectionClass;
34-
3533
private final XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor;
3634

3735
public AbstractSmackSpecificLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment,
3836
Class<C> connectionClass) {
3937
super(environment);
4038
this.environment = environment;
41-
this.connectionClass = connectionClass;
4239

4340
connectionDescriptor = environment.connectionManager.getConnectionDescriptorFor(connectionClass);
4441
if (connectionDescriptor == null) {
4542
throw new IllegalStateException("No connection descriptor for " + connectionClass + " known");
4643
}
4744
}
4845

49-
public Class<C> getConnectionClass() {
50-
return connectionClass;
46+
public XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> getConnectionDescriptor() {
47+
return connectionDescriptor;
5148
}
5249

5350
protected C getSpecificUnconnectedConnection() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.logging.Logger;
4949

5050
import org.jivesoftware.smack.AbstractXMPPConnection;
51+
import org.jivesoftware.smack.ConnectionConfiguration;
5152
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
5253
import org.jivesoftware.smack.Smack;
5354
import org.jivesoftware.smack.SmackConfiguration;
@@ -199,8 +200,8 @@ public synchronized TestRunResult run()
199200
Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
200201
Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);
201202

202-
Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(inttestClasses.size()
203-
+ lowLevelInttestClasses.size());
203+
final int builtInTestCount = inttestClasses.size() + lowLevelInttestClasses.size();
204+
Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(builtInTestCount);
204205
classes.addAll(inttestClasses);
205206
classes.addAll(lowLevelInttestClasses);
206207

@@ -333,11 +334,11 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
333334
continue;
334335
}
335336

336-
Class<? extends AbstractXMPPConnection> specificLowLevelConnectionClass = null;
337+
XmppConnectionDescriptor<?, ?, ?> specificLowLevelConnectionDescriptor = null;
337338
final TestType testType;
338339
if (test instanceof AbstractSmackSpecificLowLevelIntegrationTest) {
339340
AbstractSmackSpecificLowLevelIntegrationTest<?> specificLowLevelTest = (AbstractSmackSpecificLowLevelIntegrationTest<?>) test;
340-
specificLowLevelConnectionClass = specificLowLevelTest.getConnectionClass();
341+
specificLowLevelConnectionDescriptor = specificLowLevelTest.getConnectionDescriptor();
341342
testType = TestType.SpecificLowLevel;
342343
} else if (test instanceof AbstractSmackLowLevelIntegrationTest) {
343344
testType = TestType.LowLevel;
@@ -366,6 +367,7 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
366367
verifyLowLevelTestMethod(method, AbstractXMPPConnection.class);
367368
break;
368369
case SpecificLowLevel:
370+
Class<? extends AbstractXMPPConnection> specificLowLevelConnectionClass = specificLowLevelConnectionDescriptor.getConnectionClass();
369371
verifyLowLevelTestMethod(method, specificLowLevelConnectionClass);
370372
break;
371373
}
@@ -543,10 +545,8 @@ private List<ConcreteTest> invokeLowLevel(LowLevelTestMethod lowLevelTestMethod,
543545
continue;
544546
}
545547

546-
Class<? extends AbstractXMPPConnection> connectionClass = connectionDescriptor.getConnectionClass();
547-
548-
ConcreteTest.Executor executor = () -> lowLevelTestMethod.invoke(test, connectionClass);
549-
ConcreteTest concreteTest = new ConcreteTest(TestType.LowLevel, lowLevelTestMethod.testMethod, executor, connectionClass.getSimpleName());
548+
ConcreteTest.Executor executor = () -> lowLevelTestMethod.invoke(test, connectionDescriptor);
549+
ConcreteTest concreteTest = new ConcreteTest(TestType.LowLevel, lowLevelTestMethod.testMethod, executor, connectionDescriptor.getNickname());
550550
resultingConcreteTests.add(concreteTest);
551551
}
552552

@@ -560,8 +560,9 @@ private static <C extends AbstractXMPPConnection> void invokeSpecificLowLevel(Lo
560560
if (testMethod.smackIntegrationTestAnnotation.onlyDefaultConnectionType()) {
561561
throw new IllegalArgumentException("SpecificLowLevelTests must not have set onlyDefaultConnectionType");
562562
}
563-
Class<C> connectionClass = test.getConnectionClass();
564-
testMethod.invoke(test, connectionClass);
563+
564+
XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor = test.getConnectionDescriptor();
565+
testMethod.invoke(test, connectionDescriptor);
565566
}
566567

567568
protected SmackIntegrationTestEnvironment prepareEnvironment() throws SmackException,
@@ -837,9 +838,8 @@ private LowLevelTestMethod(Method testMethod) {
837838
parameterListOfConnections = testMethodParametersIsListOfConnections(testMethod);
838839
}
839840

840-
// TODO: The second parameter should probably be a connection descriptor?
841841
private void invoke(AbstractSmackLowLevelIntegrationTest test,
842-
Class<? extends AbstractXMPPConnection> connectionClass)
842+
XmppConnectionDescriptor<?, ?, ?> connectionDescriptor)
843843
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
844844
InterruptedException, SmackException, IOException, XMPPException {
845845
final int connectionCount;
@@ -854,7 +854,7 @@ private void invoke(AbstractSmackLowLevelIntegrationTest test,
854854
}
855855

856856
List<? extends AbstractXMPPConnection> connections = connectionManager.constructConnectedConnections(
857-
connectionClass, connectionCount);
857+
connectionDescriptor, connectionCount);
858858

859859
if (parameterListOfConnections) {
860860
testMethod.invoke(test, connections);

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/XmppConnectionDescriptor.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2018-2020 Florian Schmaus
3+
* Copyright 2018-2021 Florian Schmaus
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.igniterealtime.smack.inttest;
1818

1919
import java.lang.reflect.Constructor;
20+
import java.lang.reflect.Field;
2021
import java.lang.reflect.InvocationTargetException;
2122
import java.lang.reflect.Method;
2223
import java.lang.reflect.Modifier;
@@ -29,7 +30,12 @@
2930
import org.jivesoftware.smack.AbstractXMPPConnection;
3031
import org.jivesoftware.smack.ConnectionConfiguration;
3132
import org.jivesoftware.smack.XMPPConnection;
33+
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;
34+
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
35+
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModuleDescriptor;
3236
import org.jivesoftware.smack.util.Consumer;
37+
import org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor;
38+
import org.jivesoftware.smack.websocket.impl.WebSocketFactory;
3339

3440
public final class XmppConnectionDescriptor<
3541
C extends AbstractXMPPConnection,
@@ -134,6 +140,32 @@ Builder<C, CC, CCB> buildWith(Class<C> connectionClass, Class<CC> connectionConf
134140
return new Builder<>(connectionClass, connectionConfigurationClass, connectionConfigurationBuilderClass);
135141
}
136142

143+
public static XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> buildWebsocketDescriptor(
144+
String nickname, Class<? extends WebSocketFactory> factoryClass)
145+
throws InstantiationException, IllegalAccessException, IllegalArgumentException,
146+
InvocationTargetException, NoSuchMethodException, SecurityException {
147+
WebSocketFactory factory;
148+
try {
149+
Field instanceField = factoryClass.getField("INSTANCE");
150+
factory = (WebSocketFactory) instanceField.get(null);
151+
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
152+
factory = factoryClass.getConstructor().newInstance();
153+
}
154+
WebSocketFactory finalFactory = factory;
155+
156+
return XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class)
157+
.withNickname("modular-websocket-java11")
158+
.applyExtraConfguration(cb -> {
159+
cb.removeAllModules();
160+
ModularXmppClientToServerConnectionModuleDescriptor webSocketModuleDescriptor =
161+
XmppWebSocketTransportModuleDescriptor.getBuilder(cb)
162+
.setWebSocketFactory(finalFactory)
163+
.build();
164+
cb.addModule(webSocketModuleDescriptor);
165+
})
166+
.build();
167+
}
168+
137169
public static final class Builder<C extends AbstractXMPPConnection, CC extends ConnectionConfiguration, CCB extends ConnectionConfiguration.Builder<?, CC>> {
138170
private final Class<C> connectionClass;
139171
private final Class<CC> connectionConfigurationClass;

0 commit comments

Comments
 (0)