Skip to content
Snippets Groups Projects
Verified Commit 5a67f989 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Cleanup libquassel to also run under JDK6

parent a8f38524
No related branches found
No related tags found
No related merge requests found
Showing
with 107 additions and 21 deletions
......@@ -94,7 +94,7 @@ subprojects {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(8))
}
}
}
......@@ -35,7 +35,7 @@ internal class CoverageConverterAction(
file.delete()
}
val source = CoverageConverterPlugin::class.java.getResourceAsStream("/coverageconverter/$name")
file.writeBytes(source.readAllBytes())
file.writeBytes(source.readBytes())
return file
}
......
......@@ -4,10 +4,10 @@ hamcrestVersion=2.1
junit5Version=5.6.0
kotlinBitflagsVersion=1.1.0
sl4jVersion=1.7.30
testcontainersCiVersion=1.1.0
testcontainersCiVersion=1.2.0
GROUP=de.justjanne.libquassel
VERSION_NAME=0.3.0
VERSION_NAME=0.3.1
POM_URL=https://git.kuschku.de/justJanne/libquassel
POM_SCM_URL=https://git.kuschku.de/justJanne/libquassel
......
......@@ -10,6 +10,7 @@
package de.justjanne.libquassel.protocol.io
import de.justjanne.libquassel.protocol.util.withFlip
import java.nio.ByteBuffer
/**
......@@ -44,7 +45,7 @@ fun copyData(from: ByteBuffer, to: ByteBuffer, desiredAmount: Int) {
fun copyData(from: ByteBuffer, desiredAmount: Int): ByteBuffer {
val to = ByteBuffer.allocate(minOf(from.remaining(), desiredAmount))
copyData(from, to, desiredAmount)
return to.flip()
return to.withFlip()
}
/**
......
......@@ -10,6 +10,7 @@
package de.justjanne.libquassel.protocol.io
import de.justjanne.libquassel.protocol.util.withFlip
import java.nio.ByteBuffer
import java.util.LinkedList
......@@ -192,6 +193,6 @@ class ChainedByteBuffer(
index < buffer.bufferList.size
override fun next(): ByteBuffer =
buffer.bufferList[index++].duplicate().flip()
buffer.bufferList[index++].duplicate().withFlip()
}
}
......@@ -10,6 +10,8 @@
package de.justjanne.libquassel.protocol.io
import de.justjanne.libquassel.protocol.util.withClear
import de.justjanne.libquassel.protocol.util.withFlip
import java.nio.ByteBuffer
import java.nio.CharBuffer
import java.nio.charset.Charset
......@@ -24,7 +26,7 @@ class StringEncoder(charset: Charset) {
private fun charBuffer(length: Int): CharBuffer {
if (length < 1024) {
return charBuffer.clear()
return charBuffer.withClear()
} else {
return CharBuffer.allocate(length)
}
......@@ -83,7 +85,7 @@ class StringEncoder(charset: Charset) {
}
}
source.limit(oldlimit)
return charBuffer.flip()
return charBuffer.withFlip()
}
/**
......
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.util
import java.nio.Buffer
/**
* Utility function wrapping the [Buffer.position] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withPosition(position: Int): T {
position(position)
return this
}
/**
* Utility function wrapping the [Buffer.limit] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withLimit(limit: Int): T {
limit(limit)
return this
}
/**
* Utility function wrapping the [Buffer.mark] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withMark(): T {
mark()
return this
}
/**
* Utility function wrapping the [Buffer.reset] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withReset(): T {
reset()
return this
}
/**
* Utility function wrapping the [Buffer.clear] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withClear(): T {
clear()
return this
}
/**
* Utility function wrapping the [Buffer.flip] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withFlip(): T {
flip()
return this
}
/**
* Utility function wrapping the [Buffer.rewind] call on older JDKs where it
* always returns a plain Buffer instead of the correct type
*/
inline fun <reified T : Buffer> T.withRewind(): T {
rewind()
return this
}
......@@ -25,6 +25,7 @@ import de.justjanne.libquassel.protocol.testutil.matchers.BomMatcherString
import de.justjanne.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.justjanne.libquassel.protocol.testutil.testPrimitiveSerializerDirect
import de.justjanne.libquassel.protocol.testutil.testPrimitiveSerializerVariant
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
......@@ -50,12 +51,12 @@ class StringSerializerTest {
val bufferUtf8 = StringSerializerUtf8.serializeRaw(it)
testPrimitiveSerializerDirect(ByteBufferSerializer, bufferUtf8, matcher = ByteBufferMatcher(bufferUtf8))
testPrimitiveSerializerVariant(QtType.QByteArray, bufferUtf8, matcher = ByteBufferMatcher(bufferUtf8))
assertEquals(it, StringSerializerUtf8.deserializeRaw(bufferUtf8.rewind()))
assertEquals(it, StringSerializerUtf8.deserializeRaw(bufferUtf8.withRewind()))
val bufferUtf16 = StringSerializerUtf16.serializeRaw(it)
testPrimitiveSerializerDirect(ByteBufferSerializer, bufferUtf16, matcher = ByteBufferMatcher(bufferUtf16))
testPrimitiveSerializerVariant(QtType.QByteArray, bufferUtf16, matcher = ByteBufferMatcher(bufferUtf16))
assertThat(StringSerializerUtf16.deserializeRaw(bufferUtf16.rewind()), BomMatcherString(it))
assertThat(StringSerializerUtf16.deserializeRaw(bufferUtf16.withRewind()), BomMatcherString(it))
}
}
}
......@@ -80,7 +81,7 @@ class StringSerializerTest {
val bufferAscii = StringSerializerAscii.serializeRaw(data)
testPrimitiveSerializerDirect(ByteBufferSerializer, bufferAscii, matcher = ByteBufferMatcher(bufferAscii))
testPrimitiveSerializerVariant(QtType.QByteArray, bufferAscii, matcher = ByteBufferMatcher(bufferAscii))
assertEquals(data, StringSerializerAscii.deserializeRaw(bufferAscii.rewind()))
assertEquals(data, StringSerializerAscii.deserializeRaw(bufferAscii.withRewind()))
testUtf(data)
}
......@@ -1314,7 +1315,7 @@ class StringSerializerTest {
val bufferAscii = StringSerializerAscii.serializeRaw(data)
testPrimitiveSerializerDirect(ByteBufferSerializer, bufferAscii, matcher = ByteBufferMatcher(bufferAscii))
testPrimitiveSerializerVariant(QtType.QByteArray, bufferAscii, matcher = ByteBufferMatcher(bufferAscii))
assertEquals(data, StringSerializerAscii.deserializeRaw(bufferAscii.rewind()))
assertEquals(data, StringSerializerAscii.deserializeRaw(bufferAscii.withRewind()))
}
private fun testUtf(data: String) {
......@@ -1323,7 +1324,7 @@ class StringSerializerTest {
val bufferUtf8 = StringSerializerUtf8.serializeRaw(data)
testPrimitiveSerializerDirect(ByteBufferSerializer, bufferUtf8, matcher = ByteBufferMatcher(bufferUtf8))
testPrimitiveSerializerVariant(QtType.QByteArray, bufferUtf8, matcher = ByteBufferMatcher(bufferUtf8))
assertEquals(data, StringSerializerUtf8.deserializeRaw(bufferUtf8.rewind()))
assertEquals(data, StringSerializerUtf8.deserializeRaw(bufferUtf8.withRewind()))
// testPrimitiveSerializerDirect(StringSerializerUtf16, data, matcher = BomMatcherString(data))
// testPrimitiveSerializerVariant(StringSerializerUtf16, data, matcher = BomMatcherString(data))
......
......@@ -23,6 +23,7 @@ import de.justjanne.libquassel.protocol.io.useChainedByteBuffer
import de.justjanne.libquassel.protocol.models.HandshakeMessage
import de.justjanne.libquassel.protocol.serializers.HandshakeMessageSerializer
import de.justjanne.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import java.nio.ByteBuffer
......@@ -50,7 +51,7 @@ inline fun <reified T : HandshakeMessage> handshakeSerializerTest(
useChainedByteBuffer {
HandshakeMessageSerializer.serialize(it, value, serializeFeatureSet)
},
ByteBufferMatcher(encoded.rewind())
ByteBufferMatcher(encoded.withRewind())
)
}
}
......
......@@ -20,6 +20,7 @@ package de.justjanne.libquassel.protocol.testutil.matchers
import de.justjanne.libquassel.protocol.io.contentToString
import de.justjanne.libquassel.protocol.io.isEmpty
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
import java.nio.ByteBuffer
......@@ -40,7 +41,7 @@ class ByteBufferMatcher(buffer: ByteBuffer?) : BaseMatcher<ByteBuffer>() {
override fun describeMismatch(item: Any?, description: Description?) {
description?.appendText("was ")
description?.appendText((item as? ByteBuffer)?.rewind()?.contentToString())
description?.appendText((item as? ByteBuffer)?.withRewind()?.contentToString())
}
override fun matches(item: Any?): Boolean {
......@@ -50,6 +51,6 @@ class ByteBufferMatcher(buffer: ByteBuffer?) : BaseMatcher<ByteBuffer>() {
return true
}
return actual?.rewind()?.contentToString() == expected?.rewind()?.contentToString()
return actual?.withRewind()?.contentToString() == expected?.withRewind()?.contentToString()
}
}
......@@ -24,6 +24,7 @@ import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.models.types.QuasselType
import de.justjanne.libquassel.protocol.serializers.PrimitiveSerializer
import de.justjanne.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
......@@ -76,7 +77,7 @@ inline fun <reified T : Any?> primitiveSerializerTest(
) {
if (encoded != null) {
if (deserializeFeatureSet != null) {
val after = serializer.deserialize(encoded.rewind(), deserializeFeatureSet)
val after = serializer.deserialize(encoded.withRewind(), deserializeFeatureSet)
assertEquals(0, encoded.remaining())
if (matcher != null) {
assertThat(after, matcher(value))
......@@ -88,7 +89,7 @@ inline fun <reified T : Any?> primitiveSerializerTest(
val after = useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
assertThat(after, ByteBufferMatcher(encoded.rewind()))
assertThat(after, ByteBufferMatcher(encoded.withRewind()))
}
}
for (featureSet in featureSets) {
......
......@@ -22,6 +22,7 @@ import de.justjanne.libquassel.protocol.features.FeatureSet
import de.justjanne.libquassel.protocol.io.useChainedByteBuffer
import de.justjanne.libquassel.protocol.serializers.PrimitiveSerializer
import de.justjanne.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertEquals
......@@ -37,7 +38,7 @@ fun <T : Any?> serializerTest(
) {
if (encoded != null) {
if (deserializeFeatureSet != null) {
val after = serializer.deserialize(encoded.rewind(), deserializeFeatureSet)
val after = serializer.deserialize(encoded.withRewind(), deserializeFeatureSet)
assertEquals(0, encoded.remaining())
if (matcher != null) {
assertThat(after, matcher(value))
......@@ -49,7 +50,7 @@ fun <T : Any?> serializerTest(
val after = useChainedByteBuffer {
serializer.serialize(it, value, serializeFeatureSet)
}
assertThat(after, ByteBufferMatcher(encoded.rewind()))
assertThat(after, ByteBufferMatcher(encoded.withRewind()))
}
}
}
......@@ -23,6 +23,7 @@ import de.justjanne.libquassel.protocol.io.useChainedByteBuffer
import de.justjanne.libquassel.protocol.models.SignalProxyMessage
import de.justjanne.libquassel.protocol.serializers.SignalProxyMessageSerializer
import de.justjanne.libquassel.protocol.testutil.matchers.ByteBufferMatcher
import de.justjanne.libquassel.protocol.util.withRewind
import org.hamcrest.Matcher
import org.hamcrest.MatcherAssert.assertThat
import java.nio.ByteBuffer
......@@ -50,7 +51,7 @@ inline fun <reified T : SignalProxyMessage> signalProxySerializerTest(
useChainedByteBuffer {
SignalProxyMessageSerializer.serialize(it, value, serializeFeatureSet)
},
ByteBufferMatcher(encoded.rewind())
ByteBufferMatcher(encoded.withRewind())
)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment