Skip to content

Merging feature branch (Kotlin extensions) into main #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 2, 2024
9 changes: 6 additions & 3 deletions .evergreen/run-kotlin-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ if [ "$SAFE_FOR_MULTI_MONGOS" == "true" ]; then
export MULTI_MONGOS_URI_SYSTEM_PROPERTY="-Dorg.mongodb.test.multi.mongos.uri=${MONGODB_URI}"
fi

echo "Running Kotlin tests"

./gradlew -version
./gradlew kotlinCheck -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}

echo "Running Kotlin Unit Tests"
./gradlew :bson-kotlin:test :bson-kotlinx:test :driver-kotlin-sync:test :driver-kotlin-coroutine:test :driver-kotlin-extensions:test

echo "Running Kotlin Integration Tests"
./gradlew :driver-kotlin-sync:integrationTest :driver-kotlin-coroutine:integrationTest -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}
2 changes: 1 addition & 1 deletion .evergreen/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE[0]:-$0}")"
echo "Compiling JVM drivers"

./gradlew -version
./gradlew -PxmlReports.enabled=true --info -x test -x integrationTest -x spotlessApply clean check scalaCheck kotlinCheck jar testClasses docs
./gradlew -PxmlReports.enabled=true --info -x test -x integrationTest -x spotlessApply clean check scalaCheck jar testClasses docs
23 changes: 23 additions & 0 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,26 @@ https://github.com/mongodb/mongo-java-driver.
See the License for the specific language governing permissions and
limitations under the License.

8) The following files (originally from https://github.com/Litote/kmongo):

Filters.kt
Properties.kt
KPropertyPath.kt
FiltersTest.kt
KPropertiesTest.kt

Copyright 2008-present MongoDB, Inc.
Copyright (C) 2016/2022 Litote

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

7 changes: 0 additions & 7 deletions bson-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ spotbugs { showProgress.set(true) }
// ===========================
// Test Configuration
// ===========================
tasks.create("kotlinCheck") {
description = "Runs all the kotlin checks"
group = "verification"

dependsOn("clean", "check")
tasks.findByName("check")?.mustRunAfter("clean")
}

tasks.test { useJUnitPlatform() }

Expand Down
7 changes: 0 additions & 7 deletions bson-kotlinx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ spotbugs { showProgress.set(true) }
// ===========================
// Test Configuration
// ===========================
tasks.create("kotlinCheck") {
description = "Runs all the kotlin checks"
group = "verification"

dependsOn("clean", "check")
tasks.findByName("check")?.mustRunAfter("clean")
}

tasks.test { useJUnitPlatform() }

Expand Down
24 changes: 24 additions & 0 deletions config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@
<Method name="~.*validateAnnotations.*"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
</Match>
<Match>
<!-- MongoDB status: "False Positive", SpotBugs rank: 17 -->
<Class name="com.mongodb.kotlin.client.model.PropertiesKt$path$1"/>
<Method name="~.*invoke.*"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
</Match>
<Match>
<!-- MongoDB status: "False Positive", SpotBugs rank: 17 -->
<Class name="com.mongodb.kotlin.client.model.Projections"/>
<Method name="~include|exclude"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
</Match>
<Match>
<!-- MongoDB status: "False Positive", SpotBugs rank: 17 -->
<Class name="com.mongodb.kotlin.client.model.Indexes"/>
<Method name="~ascending|descending|geo2dsphere"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
</Match>
<Match>
<!-- MongoDB status: "False Positive", SpotBugs rank: 17 -->
<Class name="com.mongodb.kotlin.client.model.Sorts"/>
<Method name="~ascending|descending"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
</Match>

<!-- Spotbugs reports false positives for suspendable operations with default params
see: https://github.com/Kotlin/kotlinx.coroutines/issues/3099
Expand Down
2 changes: 1 addition & 1 deletion driver-core/src/main/com/mongodb/ServerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ServerAddress(@Nullable final String host, final int port) {
if (hostToUse.startsWith("[")) {
int idx = host.indexOf("]");
if (idx == -1) {
throw new IllegalArgumentException("an IPV6 address must be encosed with '[' and ']'"
throw new IllegalArgumentException("an IPV6 address must be enclosed with '[' and ']'"
+ " according to RFC 2732.");
}

Expand Down
22 changes: 22 additions & 0 deletions driver-core/src/main/com/mongodb/client/model/UnwindOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.mongodb.lang.Nullable;

import java.util.Objects;

/**
* The options for an unwind aggregation pipeline stage
*
Expand Down Expand Up @@ -79,4 +81,24 @@ public String toString() {
+ ", includeArrayIndex='" + includeArrayIndex + '\''
+ '}';
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

UnwindOptions that = (UnwindOptions) o;
return Objects.equals(preserveNullAndEmptyArrays, that.preserveNullAndEmptyArrays) && Objects.equals(includeArrayIndex, that.includeArrayIndex);
}

@Override
public int hashCode() {
int result = Objects.hashCode(preserveNullAndEmptyArrays);
result = 31 * result + Objects.hashCode(includeArrayIndex);
return result;
}
}
9 changes: 0 additions & 9 deletions driver-kotlin-coroutine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@ val integrationTest =
classpath = sourceSets["integrationTest"].runtimeClasspath
}

tasks.create("kotlinCheck") {
description = "Runs all the kotlin checks"
group = "verification"

dependsOn("clean", "check", integrationTest)
tasks.findByName("check")?.mustRunAfter("clean")
tasks.findByName("integrationTest")?.mustRunAfter("check")
}

tasks.test { useJUnitPlatform() }

// ===========================
Expand Down
168 changes: 168 additions & 0 deletions driver-kotlin-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.jvm")
`java-library`

// Test based plugins
id("com.diffplug.spotless")
id("org.jetbrains.dokka")
id("io.gitlab.arturbosch.detekt")
}

repositories {
mavenCentral()
google()
}

base.archivesName.set("mongodb-driver-kotlin-extensions")

description = "The MongoDB Kotlin Driver Extensions"

ext.set("pomName", "MongoDB Kotlin Driver Extensions")

java { registerFeature("kotlinDrivers") { usingSourceSet(sourceSets["main"]) } }

dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

api(project(path = ":driver-core", configuration = "default"))

// Some extensions require higher API like MongoCollection which are defined in the sync &
// coroutine Kotlin driver
"kotlinDriversImplementation"(project(path = ":driver-kotlin-sync", configuration = "default"))
"kotlinDriversImplementation"(project(path = ":driver-kotlin-coroutine", configuration = "default"))

testImplementation("org.jetbrains.kotlin:kotlin-reflect")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("io.github.classgraph:classgraph:4.8.154")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
}

kotlin { explicitApi() }

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs =
listOf(
// Adds OnlyInputTypes support
"-Xallow-kotlin-package",
)
}
}

// ===========================
// Code Quality checks
// ===========================
val customLicenseHeader = "/^(?s)(?!.*@custom-license-header).*/"

spotless {
kotlinGradle {
ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) }
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)")
}

kotlin {
target("**/*.kt")
ktfmt().dropboxStyle().configure { it.setMaxWidth(120) }
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()

licenseHeaderFile(rootProject.file("config/mongodb.license"))
.named("standard")
.onlyIfContentMatches(customLicenseHeader)
}

format("extraneous") {
target("*.xml", "*.yml", "*.md")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}

tasks.named("check") { dependsOn("spotlessApply") }

detekt {
allRules = true // fail build on any finding
buildUponDefaultConfig = true // preconfigure defaults
config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run,
// overwriting default behavior
baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt
source = files(file("src/main/kotlin"), file("src/test/kotlin"))
}

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true) // observe findings in your browser with structure and code snippets
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
txt.required.set(false) // similar to the console output, contains issue signature to manually edit
}
}

spotbugs { showProgress.set(true) }

tasks.spotbugsMain {
// we need the xml report to find out the "rank" (see config/spotbugs/exclude.xml)
reports.getByName("xml") { required.set(true) }
}

// ===========================
// Test Configuration
// ===========================

tasks.test { useJUnitPlatform() }

// ===========================
// Dokka Configuration
// ===========================
val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}"

tasks.dokkaHtml.configure {
outputDirectory.set(file(dokkaOutputDir))
moduleName.set(base.archivesName.get())
}

val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) }

project.parent?.tasks?.named("docs") {
dependsOn(tasks.dokkaHtml)
mustRunAfter(cleanDokka)
}

tasks.javadocJar.configure {
dependsOn(cleanDokka, tasks.dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaOutputDir)
}

// ===========================
// Sources publishing configuration
// ===========================
tasks.sourcesJar { from(project.sourceSets.main.map { it.kotlin }) }

afterEvaluate { tasks.jar { manifest { attributes["Automatic-Module-Name"] = "org.mongodb.driver.kotlin.core" } } }
Loading