Skip to content

Commit

Permalink
Add smack-websocket-java11
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Flowdalic committed Feb 14, 2021
1 parent cd40455 commit 944f8ae
Show file tree
Hide file tree
Showing 24 changed files with 440 additions and 161 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
java: [ 1.8, 11 ]
java:
- 11

steps:
- name: Checkout
Expand Down
23 changes: 22 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ plugins {

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

ext {
java11Projects = [
':smack-integration-test',
':smack-omemo-signal-integration-test',
':smack-repl',
':smack-websocket-java11',
].collect { project(it) }
java8Projects = allprojects - java11Projects
}

configure (java8Projects) {
ext {
javaCompatilibity = JavaVersion.VERSION_1_8
}
}

configure (java11Projects) {
ext {
javaCompatilibity = JavaVersion.VERSION_11
}
}

allprojects {
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
Expand Down Expand Up @@ -136,7 +158,6 @@ allprojects {
// Default to true
useSonatype = true
}
javaCompatilibity = JavaVersion.VERSION_1_8
javaMajor = javaCompatilibity.getMajorVersion()
}
group = 'org.igniterealtime.smack'
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ include 'smack-core',
'smack-openpgp',
'smack-websocket',
'smack-websocket-okhttp',
'smack-websocket-java11',
'smack-xmlparser',
'smack-xmlparser-stax',
'smack-xmlparser-xpp3'
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ protected XmppClientToServerTransport(ModularXmppClientToServerConnectionInterna

public abstract SSLSession getSslSession();

public abstract boolean isConnected();

public boolean isTransportSecured() {
return getSslSession() != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2020 Florian Schmaus
* Copyright 2020-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,10 @@ public interface RemoteConnectionEndpoint {

String getDescription();

default String getRawString() {
return toString();
}

class InetSocketAddressCoupling<RCE extends RemoteConnectionEndpoint> {
private final RCE connectionEndpoint;
private final InetSocketAddress inetSocketAddress;
Expand Down
1 change: 1 addition & 0 deletions smack-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ applicationDefaultJvmArgs = ["-enableassertions"]
dependencies {
api project(':smack-java8-full')
api project(':smack-resolver-dnsjava')
implementation project(':smack-websocket-java11')
implementation "com.google.guava:guava:${guavaVersion}"
compile 'org.reflections:reflections:0.9.12'
compile 'eu.geekplace.javapinning:java-pinning-java7:1.1.0-alpha1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2020 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,24 +30,21 @@ public abstract class AbstractSmackSpecificLowLevelIntegrationTest<C extends Abs

private final SmackIntegrationTestEnvironment environment;

protected final Class<C> connectionClass;

private final XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor;

public AbstractSmackSpecificLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment,
Class<C> connectionClass) {
super(environment);
this.environment = environment;
this.connectionClass = connectionClass;

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

public Class<C> getConnectionClass() {
return connectionClass;
public XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> getConnectionDescriptor() {
return connectionDescriptor;
}

protected C getSpecificUnconnectedConnection() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.logging.Logger;

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.Smack;
import org.jivesoftware.smack.SmackConfiguration;
Expand Down Expand Up @@ -199,8 +200,8 @@ public synchronized TestRunResult run()
Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);

Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(inttestClasses.size()
+ lowLevelInttestClasses.size());
final int builtInTestCount = inttestClasses.size() + lowLevelInttestClasses.size();
Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(builtInTestCount);
classes.addAll(inttestClasses);
classes.addAll(lowLevelInttestClasses);

Expand Down Expand Up @@ -333,11 +334,11 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
continue;
}

Class<? extends AbstractXMPPConnection> specificLowLevelConnectionClass = null;
XmppConnectionDescriptor<?, ?, ?> specificLowLevelConnectionDescriptor = null;
final TestType testType;
if (test instanceof AbstractSmackSpecificLowLevelIntegrationTest) {
AbstractSmackSpecificLowLevelIntegrationTest<?> specificLowLevelTest = (AbstractSmackSpecificLowLevelIntegrationTest<?>) test;
specificLowLevelConnectionClass = specificLowLevelTest.getConnectionClass();
specificLowLevelConnectionDescriptor = specificLowLevelTest.getConnectionDescriptor();
testType = TestType.SpecificLowLevel;
} else if (test instanceof AbstractSmackLowLevelIntegrationTest) {
testType = TestType.LowLevel;
Expand Down Expand Up @@ -366,6 +367,7 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
verifyLowLevelTestMethod(method, AbstractXMPPConnection.class);
break;
case SpecificLowLevel:
Class<? extends AbstractXMPPConnection> specificLowLevelConnectionClass = specificLowLevelConnectionDescriptor.getConnectionClass();
verifyLowLevelTestMethod(method, specificLowLevelConnectionClass);
break;
}
Expand Down Expand Up @@ -543,10 +545,8 @@ private List<ConcreteTest> invokeLowLevel(LowLevelTestMethod lowLevelTestMethod,
continue;
}

Class<? extends AbstractXMPPConnection> connectionClass = connectionDescriptor.getConnectionClass();

ConcreteTest.Executor executor = () -> lowLevelTestMethod.invoke(test, connectionClass);
ConcreteTest concreteTest = new ConcreteTest(TestType.LowLevel, lowLevelTestMethod.testMethod, executor, connectionClass.getSimpleName());
ConcreteTest.Executor executor = () -> lowLevelTestMethod.invoke(test, connectionDescriptor);
ConcreteTest concreteTest = new ConcreteTest(TestType.LowLevel, lowLevelTestMethod.testMethod, executor, connectionDescriptor.getNickname());
resultingConcreteTests.add(concreteTest);
}

Expand All @@ -560,8 +560,9 @@ private static <C extends AbstractXMPPConnection> void invokeSpecificLowLevel(Lo
if (testMethod.smackIntegrationTestAnnotation.onlyDefaultConnectionType()) {
throw new IllegalArgumentException("SpecificLowLevelTests must not have set onlyDefaultConnectionType");
}
Class<C> connectionClass = test.getConnectionClass();
testMethod.invoke(test, connectionClass);

XmppConnectionDescriptor<C, ? extends ConnectionConfiguration, ? extends ConnectionConfiguration.Builder<?, ?>> connectionDescriptor = test.getConnectionDescriptor();
testMethod.invoke(test, connectionDescriptor);
}

protected SmackIntegrationTestEnvironment prepareEnvironment() throws SmackException,
Expand Down Expand Up @@ -837,9 +838,8 @@ private LowLevelTestMethod(Method testMethod) {
parameterListOfConnections = testMethodParametersIsListOfConnections(testMethod);
}

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

List<? extends AbstractXMPPConnection> connections = connectionManager.constructConnectedConnections(
connectionClass, connectionCount);
connectionDescriptor, connectionCount);

if (parameterListOfConnections) {
testMethod.invoke(test, connections);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2018-2020 Florian Schmaus
* Copyright 2018-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.igniterealtime.smack.inttest;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand All @@ -29,7 +30,12 @@
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection;
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModuleDescriptor;
import org.jivesoftware.smack.util.Consumer;
import org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor;
import org.jivesoftware.smack.websocket.impl.WebSocketFactory;

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

public static XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> buildWebsocketDescriptor(
String nickname, Class<? extends WebSocketFactory> factoryClass)
throws InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
WebSocketFactory factory;
try {
Field instanceField = factoryClass.getField("INSTANCE");
factory = (WebSocketFactory) instanceField.get(null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
factory = factoryClass.getConstructor().newInstance();
}
WebSocketFactory finalFactory = factory;

return XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class)
.withNickname("modular-websocket-java11")
.applyExtraConfguration(cb -> {
cb.removeAllModules();
ModularXmppClientToServerConnectionModuleDescriptor webSocketModuleDescriptor =
XmppWebSocketTransportModuleDescriptor.getBuilder(cb)
.setWebSocketFactory(finalFactory)
.build();
cb.addModule(webSocketModuleDescriptor);
})
.build();
}

public static final class Builder<C extends AbstractXMPPConnection, CC extends ConnectionConfiguration, CCB extends ConnectionConfiguration.Builder<?, CC>> {
private final Class<C> connectionClass;
private final Class<CC> connectionConfigurationClass;
Expand Down
Loading

0 comments on commit 944f8ae

Please sign in to comment.