Skip to content

Commit 7f3071a

Browse files
committed
Merge branch 'main' into kotlin-extensions
2 parents ff61712 + 8681337 commit 7f3071a

File tree

97 files changed

+907
-916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+907
-916
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ jobs:
7878
exit 1
7979
8080
# For non-patch releases (A.B.C where C == 0), we expect the release to
81-
# be triggered from master or the A.B.x maintenance branch. This includes
81+
# be triggered from main or the A.B.x maintenance branch. This includes
8282
# pre-releases for any non-patch releases, e.g. 5.2.0-beta1
8383
- name: "Fail if non-patch release is created from wrong release branch"
84-
if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'master' }}
84+
if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'main' }}
8585
run: |
86-
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or master, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
86+
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or main, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
8787
exit 1
8888
8989
# Set commit author information to the user that triggered the release workflow

bson-kotlinx/src/main/kotlin/org/bson/codecs/kotlinx/BsonDecoder.kt

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ import org.bson.BsonType
3737
import org.bson.BsonValue
3838
import org.bson.codecs.BsonValueCodec
3939
import org.bson.codecs.DecoderContext
40-
import org.bson.codecs.kotlinx.BsonDecoder.Companion.createBsonArrayDecoder
41-
import org.bson.codecs.kotlinx.BsonDecoder.Companion.createBsonDocumentDecoder
42-
import org.bson.codecs.kotlinx.BsonDecoder.Companion.createBsonMapDecoder
43-
import org.bson.codecs.kotlinx.BsonDecoder.Companion.createBsonPolymorphicDecoder
40+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonArrayDecoder
41+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonDecoder
42+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonDocumentDecoder
43+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonMapDecoder
44+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonPolymorphicDecoder
4445
import org.bson.internal.NumberCodecHelper
4546
import org.bson.internal.StringCodecHelper
4647
import org.bson.types.ObjectId
@@ -51,75 +52,12 @@ import org.bson.types.ObjectId
5152
* For custom serialization handlers
5253
*/
5354
@ExperimentalSerializationApi
54-
internal sealed interface BsonDecoder : Decoder, CompositeDecoder {
55-
56-
/** Factory helper for creating concrete BsonDecoder implementations */
57-
companion object {
58-
59-
@Suppress("SwallowedException")
60-
private val hasJsonDecoder: Boolean by lazy {
61-
try {
62-
Class.forName("kotlinx.serialization.json.JsonDecoder")
63-
true
64-
} catch (e: ClassNotFoundException) {
65-
false
66-
}
67-
}
68-
69-
fun createBsonDecoder(
70-
reader: AbstractBsonReader,
71-
serializersModule: SerializersModule,
72-
configuration: BsonConfiguration
73-
): BsonDecoder {
74-
return if (hasJsonDecoder) JsonBsonDecoderImpl(reader, serializersModule, configuration)
75-
else BsonDecoderImpl(reader, serializersModule, configuration)
76-
}
77-
78-
fun createBsonArrayDecoder(
79-
descriptor: SerialDescriptor,
80-
reader: AbstractBsonReader,
81-
serializersModule: SerializersModule,
82-
configuration: BsonConfiguration
83-
): BsonArrayDecoder {
84-
return if (hasJsonDecoder) JsonBsonArrayDecoder(descriptor, reader, serializersModule, configuration)
85-
else BsonArrayDecoder(descriptor, reader, serializersModule, configuration)
86-
}
87-
88-
fun createBsonDocumentDecoder(
89-
descriptor: SerialDescriptor,
90-
reader: AbstractBsonReader,
91-
serializersModule: SerializersModule,
92-
configuration: BsonConfiguration
93-
): BsonDocumentDecoder {
94-
return if (hasJsonDecoder) JsonBsonDocumentDecoder(descriptor, reader, serializersModule, configuration)
95-
else BsonDocumentDecoder(descriptor, reader, serializersModule, configuration)
96-
}
97-
98-
fun createBsonPolymorphicDecoder(
99-
descriptor: SerialDescriptor,
100-
reader: AbstractBsonReader,
101-
serializersModule: SerializersModule,
102-
configuration: BsonConfiguration
103-
): BsonPolymorphicDecoder {
104-
return if (hasJsonDecoder) JsonBsonPolymorphicDecoder(descriptor, reader, serializersModule, configuration)
105-
else BsonPolymorphicDecoder(descriptor, reader, serializersModule, configuration)
106-
}
107-
108-
fun createBsonMapDecoder(
109-
descriptor: SerialDescriptor,
110-
reader: AbstractBsonReader,
111-
serializersModule: SerializersModule,
112-
configuration: BsonConfiguration
113-
): BsonMapDecoder {
114-
return if (hasJsonDecoder) JsonBsonMapDecoder(descriptor, reader, serializersModule, configuration)
115-
else BsonMapDecoder(descriptor, reader, serializersModule, configuration)
116-
}
117-
}
55+
public sealed interface BsonDecoder : Decoder, CompositeDecoder {
11856

11957
/** @return the decoded ObjectId */
120-
fun decodeObjectId(): ObjectId
58+
public fun decodeObjectId(): ObjectId
12159
/** @return the decoded BsonValue */
122-
fun decodeBsonValue(): BsonValue
60+
public fun decodeBsonValue(): BsonValue
12361
}
12462

12563
@OptIn(ExperimentalSerializationApi::class)
@@ -325,7 +263,7 @@ internal open class BsonPolymorphicDecoder(
325263
it.reset()
326264
mark = null
327265
}
328-
return deserializer.deserialize(BsonDecoder.createBsonDecoder(reader, serializersModule, configuration))
266+
return deserializer.deserialize(createBsonDecoder(reader, serializersModule, configuration))
329267
}
330268

331269
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {

bson-kotlinx/src/main/kotlin/org/bson/codecs/kotlinx/BsonEncoder.kt

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,21 @@ import org.bson.types.ObjectId
3939
* For custom serialization handlers
4040
*/
4141
@ExperimentalSerializationApi
42-
internal sealed interface BsonEncoder : Encoder, CompositeEncoder {
43-
44-
/** Factory helper for creating concrete BsonEncoder implementations */
45-
companion object {
46-
@Suppress("SwallowedException")
47-
private val hasJsonEncoder: Boolean by lazy {
48-
try {
49-
Class.forName("kotlinx.serialization.json.JsonEncoder")
50-
true
51-
} catch (e: ClassNotFoundException) {
52-
false
53-
}
54-
}
55-
56-
fun createBsonEncoder(
57-
writer: BsonWriter,
58-
serializersModule: SerializersModule,
59-
configuration: BsonConfiguration
60-
): BsonEncoder {
61-
return if (hasJsonEncoder) JsonBsonEncoder(writer, serializersModule, configuration)
62-
else BsonEncoderImpl(writer, serializersModule, configuration)
63-
}
64-
}
42+
public sealed interface BsonEncoder : Encoder, CompositeEncoder {
6543

6644
/**
6745
* Encodes an ObjectId
6846
*
6947
* @param value the ObjectId
7048
*/
71-
fun encodeObjectId(value: ObjectId)
49+
public fun encodeObjectId(value: ObjectId)
7250

7351
/**
7452
* Encodes a BsonValue
7553
*
7654
* @param value the BsonValue
7755
*/
78-
fun encodeBsonValue(value: BsonValue)
56+
public fun encodeBsonValue(value: BsonValue)
7957
}
8058

8159
/**

bson-kotlinx/src/main/kotlin/org/bson/codecs/kotlinx/KotlinSerializerCodec.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import org.bson.codecs.Codec
3434
import org.bson.codecs.DecoderContext
3535
import org.bson.codecs.EncoderContext
3636
import org.bson.codecs.configuration.CodecConfigurationException
37+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonDecoder
38+
import org.bson.codecs.kotlinx.utils.BsonCodecUtils.createBsonEncoder
3739
import org.bson.codecs.pojo.annotations.BsonCreator
3840
import org.bson.codecs.pojo.annotations.BsonDiscriminator
3941
import org.bson.codecs.pojo.annotations.BsonExtraElements
@@ -172,13 +174,13 @@ private constructor(
172174
}
173175

174176
override fun encode(writer: BsonWriter, value: T, encoderContext: EncoderContext) {
175-
serializer.serialize(BsonEncoder.createBsonEncoder(writer, serializersModule, bsonConfiguration), value)
177+
serializer.serialize(createBsonEncoder(writer, serializersModule, bsonConfiguration), value)
176178
}
177179

178180
override fun getEncoderClass(): Class<T> = kClass.java
179181

180182
override fun decode(reader: BsonReader, decoderContext: DecoderContext): T {
181183
require(reader is AbstractBsonReader)
182-
return serializer.deserialize(BsonDecoder.createBsonDecoder(reader, serializersModule, bsonConfiguration))
184+
return serializer.deserialize(createBsonDecoder(reader, serializersModule, bsonConfiguration))
183185
}
184186
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.bson.codecs.kotlinx.utils
17+
18+
import kotlinx.serialization.ExperimentalSerializationApi
19+
import kotlinx.serialization.descriptors.SerialDescriptor
20+
import kotlinx.serialization.modules.SerializersModule
21+
import org.bson.AbstractBsonReader
22+
import org.bson.BsonWriter
23+
import org.bson.codecs.kotlinx.BsonArrayDecoder
24+
import org.bson.codecs.kotlinx.BsonConfiguration
25+
import org.bson.codecs.kotlinx.BsonDecoder
26+
import org.bson.codecs.kotlinx.BsonDecoderImpl
27+
import org.bson.codecs.kotlinx.BsonDocumentDecoder
28+
import org.bson.codecs.kotlinx.BsonEncoder
29+
import org.bson.codecs.kotlinx.BsonEncoderImpl
30+
import org.bson.codecs.kotlinx.BsonMapDecoder
31+
import org.bson.codecs.kotlinx.BsonPolymorphicDecoder
32+
import org.bson.codecs.kotlinx.JsonBsonArrayDecoder
33+
import org.bson.codecs.kotlinx.JsonBsonDecoderImpl
34+
import org.bson.codecs.kotlinx.JsonBsonDocumentDecoder
35+
import org.bson.codecs.kotlinx.JsonBsonEncoder
36+
import org.bson.codecs.kotlinx.JsonBsonMapDecoder
37+
import org.bson.codecs.kotlinx.JsonBsonPolymorphicDecoder
38+
39+
@ExperimentalSerializationApi
40+
internal object BsonCodecUtils {
41+
42+
@Suppress("SwallowedException")
43+
private val hasJsonEncoder: Boolean by lazy {
44+
try {
45+
Class.forName("kotlinx.serialization.json.JsonEncoder")
46+
true
47+
} catch (e: ClassNotFoundException) {
48+
false
49+
}
50+
}
51+
52+
@Suppress("SwallowedException")
53+
private val hasJsonDecoder: Boolean by lazy {
54+
try {
55+
Class.forName("kotlinx.serialization.json.JsonDecoder")
56+
true
57+
} catch (e: ClassNotFoundException) {
58+
false
59+
}
60+
}
61+
62+
internal fun createBsonEncoder(
63+
writer: BsonWriter,
64+
serializersModule: SerializersModule,
65+
configuration: BsonConfiguration
66+
): BsonEncoder {
67+
return if (hasJsonEncoder) JsonBsonEncoder(writer, serializersModule, configuration)
68+
else BsonEncoderImpl(writer, serializersModule, configuration)
69+
}
70+
71+
internal fun createBsonDecoder(
72+
reader: AbstractBsonReader,
73+
serializersModule: SerializersModule,
74+
configuration: BsonConfiguration
75+
): BsonDecoder {
76+
return if (hasJsonDecoder) JsonBsonDecoderImpl(reader, serializersModule, configuration)
77+
else BsonDecoderImpl(reader, serializersModule, configuration)
78+
}
79+
80+
internal fun createBsonArrayDecoder(
81+
descriptor: SerialDescriptor,
82+
reader: AbstractBsonReader,
83+
serializersModule: SerializersModule,
84+
configuration: BsonConfiguration
85+
): BsonArrayDecoder {
86+
return if (hasJsonDecoder) JsonBsonArrayDecoder(descriptor, reader, serializersModule, configuration)
87+
else BsonArrayDecoder(descriptor, reader, serializersModule, configuration)
88+
}
89+
90+
internal fun createBsonDocumentDecoder(
91+
descriptor: SerialDescriptor,
92+
reader: AbstractBsonReader,
93+
serializersModule: SerializersModule,
94+
configuration: BsonConfiguration
95+
): BsonDocumentDecoder {
96+
return if (hasJsonDecoder) JsonBsonDocumentDecoder(descriptor, reader, serializersModule, configuration)
97+
else BsonDocumentDecoder(descriptor, reader, serializersModule, configuration)
98+
}
99+
100+
internal fun createBsonPolymorphicDecoder(
101+
descriptor: SerialDescriptor,
102+
reader: AbstractBsonReader,
103+
serializersModule: SerializersModule,
104+
configuration: BsonConfiguration
105+
): BsonPolymorphicDecoder {
106+
return if (hasJsonDecoder) JsonBsonPolymorphicDecoder(descriptor, reader, serializersModule, configuration)
107+
else BsonPolymorphicDecoder(descriptor, reader, serializersModule, configuration)
108+
}
109+
110+
internal fun createBsonMapDecoder(
111+
descriptor: SerialDescriptor,
112+
reader: AbstractBsonReader,
113+
serializersModule: SerializersModule,
114+
configuration: BsonConfiguration
115+
): BsonMapDecoder {
116+
return if (hasJsonDecoder) JsonBsonMapDecoder(descriptor, reader, serializersModule, configuration)
117+
else BsonMapDecoder(descriptor, reader, serializersModule, configuration)
118+
}
119+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"name":"java.lang.Object",
4+
"queryAllDeclaredMethods":true
5+
},
6+
{
7+
"name":"sun.security.provider.NativePRNG",
8+
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"<init>","parameterTypes":["java.security.SecureRandomParameters"] }]
9+
},
10+
{
11+
"name":"sun.security.provider.SHA",
12+
"methods":[{"name":"<init>","parameterTypes":[] }]
13+
},
14+
{
15+
"name":"org.slf4j.Logger"
16+
}
17+
]

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ ext {
5858
projectReactorVersion = '2022.0.0'
5959
junitBomVersion = '5.10.2'
6060
logbackVersion = '1.3.14'
61+
graalSdkVersion = '24.0.0'
6162
gitVersion = getGitVersion()
6263
}
6364

@@ -74,7 +75,7 @@ configure(coreProjects) {
7475
apply plugin: 'idea'
7576

7677
group = 'org.mongodb'
77-
version = '5.2.0-SNAPSHOT'
78+
version = '5.3.0-SNAPSHOT'
7879

7980
repositories {
8081
mavenLocal()

config/spotbugs/exclude.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268

269269
<!-- mongocrypt -->
270270
<Match>
271-
<Class name="com.mongodb.crypt.capi.CAPI$cstring"/>
271+
<Class name="com.mongodb.internal.crypt.capi.CAPI$cstring"/>
272272
<Bug pattern="NM_CLASS_NAMING_CONVENTION"/>
273273
</Match>
274274

driver-benchmarks/src/main/com/mongodb/benchmark/framework/MongoCryptBenchmarkRunner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
*
1818
*/
1919

20-
import com.mongodb.crypt.capi.CAPI;
21-
import com.mongodb.crypt.capi.MongoCrypt;
22-
import com.mongodb.crypt.capi.MongoCryptContext;
23-
import com.mongodb.crypt.capi.MongoCryptOptions;
24-
import com.mongodb.crypt.capi.MongoCrypts;
25-
import com.mongodb.crypt.capi.MongoExplicitEncryptOptions;
26-
import com.mongodb.crypt.capi.MongoLocalKmsProviderOptions;
20+
import com.mongodb.internal.crypt.capi.CAPI;
21+
import com.mongodb.internal.crypt.capi.MongoCrypt;
22+
import com.mongodb.internal.crypt.capi.MongoCryptContext;
23+
import com.mongodb.internal.crypt.capi.MongoCryptOptions;
24+
import com.mongodb.internal.crypt.capi.MongoCrypts;
25+
import com.mongodb.internal.crypt.capi.MongoExplicitEncryptOptions;
26+
import com.mongodb.internal.crypt.capi.MongoLocalKmsProviderOptions;
2727
import org.bson.BsonBinary;
2828
import org.bson.BsonBinarySubType;
2929
import org.bson.BsonDocument;

0 commit comments

Comments
 (0)