Skip to content

Commit 05c59d2

Browse files
Merge branch 'main' into JAVA-5667
2 parents f737781 + 6bd6a19 commit 05c59d2

File tree

273 files changed

+3498
-3299
lines changed

Some content is hidden

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

273 files changed

+3498
-3299
lines changed

.evergreen/.evg.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1875,15 +1875,15 @@ axes:
18751875
- id: "2.11"
18761876
display_name: "Scala 2.11"
18771877
variables:
1878-
SCALA: "2.11.12"
1878+
SCALA: "2.11"
18791879
- id: "2.12"
18801880
display_name: "Scala 2.12"
18811881
variables:
1882-
SCALA: "2.12.20"
1882+
SCALA: "2.12"
18831883
- id: "2.13"
18841884
display_name: "Scala 2.13"
18851885
variables:
1886-
SCALA: "2.13.15"
1886+
SCALA: "2.13"
18871887

18881888
# Choice of MongoDB storage engine
18891889
- id: storage-engine

.evergreen/publish.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ SYSTEM_PROPERTIES="-Dorg.gradle.internal.publish.checksums.insecure=true -Dorg.g
2727

2828
./gradlew -version
2929
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} # Scala 2.13 is published as result of this gradle execution.
30-
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.12.12
31-
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.11.12
30+
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PscalaVersion=2.12
31+
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PscalaVersion=2.11

.github/workflows/bump-version.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fi
99
FROM_VERSION=$1
1010
TO_VERSION=$2
1111

12-
sed --in-place "s/version = '${FROM_VERSION}'/version = '${TO_VERSION}'/g" build.gradle
13-
git commit -m "Version: bump ${TO_VERSION}" build.gradle
12+
sed --in-place "s/version=${FROM_VERSION}/version=${TO_VERSION}/g" gradle.properties
13+
git commit -m "Version: bump ${TO_VERSION}" gradle.properties

bom/build.gradle.kts

+133-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1-
group = "org.mongodb"
2-
description = "This Bill of Materials POM simplifies dependency management when referencing multiple" +
3-
" MongoDB Java Driver artifacts in projects using Gradle or Maven."
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+
import ProjectExtensions.configureMavenPublication
17+
import groovy.util.Node
18+
import groovy.util.NodeList
19+
20+
plugins {
21+
id("java-platform")
22+
id("project.base")
23+
id("conventions.publishing")
24+
id("conventions.spotless")
25+
}
26+
27+
base.archivesName.set("mongodb-driver-bom")
428

529
dependencies {
630
constraints {
@@ -21,3 +45,109 @@ dependencies {
2145
api(project(":driver-scala"))
2246
}
2347
}
48+
49+
/*
50+
* Handle the multiple versions of Scala we support as defined in `gradle.properties`
51+
*/
52+
val defaultScalaVersion: String = project.findProperty("defaultScalaVersion")!!.toString()
53+
val scalaVersions: List<String>? = project.findProperty("supportedScalaVersions")?.toString()?.split(",")
54+
55+
assert(!scalaVersions.isNullOrEmpty()) {
56+
"Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property"
57+
}
58+
59+
/*
60+
* Apply the Java Platform plugin to create the BOM
61+
* Modify the generated POM to include all supported versions of Scala for driver-scala or bson-scala.
62+
*/
63+
configureMavenPublication {
64+
components.findByName("javaPlatform")?.let { from(it) }
65+
66+
pom {
67+
name.set("bom")
68+
description.set(
69+
"This Bill of Materials POM simplifies dependency management when referencing multiple MongoDB Java Driver artifacts in projects using Gradle or Maven.")
70+
71+
withXml {
72+
val pomXml: Node = asNode()
73+
74+
val dependencyManagementNode = pomXml.getNode("dependencyManagement")
75+
assert(dependencyManagementNode != null) {
76+
"<dependencyManagement> node not found in the generated BOM POM"
77+
}
78+
val dependenciesNode = dependencyManagementNode.getNode("dependencies")
79+
assert(dependenciesNode != null) { "<dependencies> node not found in the generated BOM POM" }
80+
81+
val existingScalaDeps =
82+
dependenciesNode!!
83+
.children()
84+
.map { it as Node }
85+
.filter { it.getNode("artifactId")?.text()?.contains("scala") ?: false }
86+
87+
existingScalaDeps.forEach {
88+
val groupId: String = it.getNode("groupId")!!.text()
89+
val originalArtifactId: String = it.getNode("artifactId")!!.text()
90+
val artifactVersion: String = it.getNode("version")!!.text()
91+
92+
// Add multiple versions with Scala suffixes for each Scala-related dependency.
93+
scalaVersions!!.forEach { scalaVersion ->
94+
if (scalaVersion != defaultScalaVersion) {
95+
// Replace scala version suffix
96+
val newArtifactId: String = originalArtifactId.replace(defaultScalaVersion, scalaVersion)
97+
val dependencyNode = dependenciesNode.appendNode("dependency")
98+
dependencyNode.appendNode("groupId", groupId)
99+
dependencyNode.appendNode("artifactId", newArtifactId)
100+
dependencyNode.appendNode("version", artifactVersion)
101+
}
102+
}
103+
}
104+
}
105+
}
106+
}
107+
108+
/*
109+
* Validate the BOM file.
110+
*/
111+
tasks.withType<GenerateMavenPom> {
112+
doLast {
113+
pom.withXml {
114+
val pomXml: Node = asNode()
115+
val dependenciesNode = pomXml.getNode("dependencyManagement").getNode("dependencies")
116+
assert(dependenciesNode!!.children().isNotEmpty()) {
117+
"BOM must contain more then one <dependency> element:\n$destination"
118+
}
119+
120+
dependenciesNode
121+
.children()
122+
.map { it as Node }
123+
.forEach {
124+
val groupId: String = it.getNode("groupId")!!.text()
125+
assert(groupId.startsWith("org.mongodb")) {
126+
"BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination"
127+
}
128+
129+
/*
130+
* The <scope> and <optional> tags should be omitted in BOM dependencies.
131+
* This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context.
132+
*
133+
* The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies.
134+
*/
135+
assert(it.getNode("scope") == null) {
136+
"BOM must not contain <scope> elements in dependency:\n$destination"
137+
}
138+
assert(it.getNode("optional") == null) {
139+
"BOM must not contain <optional> elements in dependency:\n$destination"
140+
}
141+
}
142+
}
143+
}
144+
}
145+
146+
/** A node lookup helper. */
147+
private fun Node?.getNode(nodeName: String): Node? {
148+
val found = this?.get(nodeName)
149+
if (found is NodeList && found.isNotEmpty()) {
150+
return found[0] as Node
151+
}
152+
return null
153+
}

bson-kotlin/build.gradle.kts

+11-117
Original file line numberDiff line numberDiff line change
@@ -13,133 +13,27 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import io.gitlab.arturbosch.detekt.Detekt
17-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
16+
import ProjectExtensions.configureJarManifest
17+
import ProjectExtensions.configureMavenPublication
1818

19-
plugins {
20-
id("org.jetbrains.kotlin.jvm")
21-
`java-library`
22-
23-
// Test based plugins
24-
id("com.diffplug.spotless")
25-
id("org.jetbrains.dokka")
26-
id("io.gitlab.arturbosch.detekt")
27-
}
28-
29-
repositories {
30-
mavenCentral()
31-
google()
32-
}
19+
plugins { id("project.kotlin") }
3320

3421
base.archivesName.set("bson-kotlin")
3522

36-
description = "Bson Kotlin Codecs"
37-
38-
ext.set("pomName", "Bson Kotlin")
39-
4023
dependencies {
41-
// Align versions of all Kotlin components
42-
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
43-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
44-
4524
api(project(path = ":bson", configuration = "default"))
46-
implementation("org.jetbrains.kotlin:kotlin-reflect")
25+
implementation(libs.kotlin.reflect)
4726

48-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
27+
// Test case checks MongoClientSettings.getDefaultCodecRegistry() support
4928
testImplementation(project(path = ":driver-core", configuration = "default"))
5029
}
5130

52-
kotlin { explicitApi() }
53-
54-
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" }
55-
56-
// ===========================
57-
// Code Quality checks
58-
// ===========================
59-
spotless {
60-
kotlinGradle {
61-
ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) }
62-
trimTrailingWhitespace()
63-
indentWithSpaces()
64-
endWithNewline()
65-
licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)")
66-
}
67-
68-
kotlin {
69-
target("**/*.kt")
70-
ktfmt().dropboxStyle().configure { it.setMaxWidth(120) }
71-
trimTrailingWhitespace()
72-
indentWithSpaces()
73-
endWithNewline()
74-
licenseHeaderFile(rootProject.file("config/mongodb.license"))
75-
}
76-
77-
format("extraneous") {
78-
target("*.xml", "*.yml", "*.md")
79-
trimTrailingWhitespace()
80-
indentWithSpaces()
81-
endWithNewline()
31+
configureMavenPublication {
32+
pom {
33+
name.set("BSON Kotlin")
34+
description.set("The BSON Codec for Kotlin")
35+
url.set("https://bsonspec.org")
8236
}
8337
}
8438

85-
tasks.named("check") { dependsOn("spotlessApply") }
86-
87-
detekt {
88-
allRules = true // fail build on any finding
89-
buildUponDefaultConfig = true // preconfigure defaults
90-
config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run,
91-
// overwriting default behavior
92-
baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt
93-
source =
94-
files(
95-
file("src/main/kotlin"),
96-
file("src/test/kotlin"),
97-
file("src/integrationTest/kotlin"),
98-
)
99-
}
100-
101-
tasks.withType<Detekt>().configureEach {
102-
reports {
103-
html.required.set(true) // observe findings in your browser with structure and code snippets
104-
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
105-
txt.required.set(false) // similar to the console output, contains issue signature to manually edit
106-
}
107-
}
108-
109-
spotbugs { showProgress.set(true) }
110-
111-
// ===========================
112-
// Test Configuration
113-
// ===========================
114-
115-
tasks.test { useJUnitPlatform() }
116-
117-
// ===========================
118-
// Dokka Configuration
119-
// ===========================
120-
val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}"
121-
122-
tasks.dokkaHtml.configure {
123-
outputDirectory.set(file(dokkaOutputDir))
124-
moduleName.set(base.archivesName.get())
125-
}
126-
127-
val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) }
128-
129-
project.parent?.tasks?.named("docs") {
130-
dependsOn(tasks.dokkaHtml)
131-
mustRunAfter(cleanDokka)
132-
}
133-
134-
tasks.javadocJar.configure {
135-
dependsOn(cleanDokka, tasks.dokkaHtml)
136-
archiveClassifier.set("javadoc")
137-
from(dokkaOutputDir)
138-
}
139-
140-
// ===========================
141-
// Sources publishing configuration
142-
// ===========================
143-
tasks.sourcesJar { from(project.sourceSets.main.map { it.kotlin }) }
144-
145-
afterEvaluate { tasks.jar { manifest { attributes["Automatic-Module-Name"] = "org.mongodb.bson.kotlin" } } }
39+
configureJarManifest { attributes["Automatic-Module-Name"] = "org.mongodb.bson.kotlin" }

0 commit comments

Comments
 (0)