diff --git a/.evergreen/.evg.yml b/.evergreen/.evg.yml index 886282b77c..f3f3a6c437 100644 --- a/.evergreen/.evg.yml +++ b/.evergreen/.evg.yml @@ -1916,15 +1916,15 @@ axes: - id: "2.11" display_name: "Scala 2.11" variables: - SCALA: "2.11.12" + SCALA: "2.11" - id: "2.12" display_name: "Scala 2.12" variables: - SCALA: "2.12.15" + SCALA: "2.12" - id: "2.13" display_name: "Scala 2.13" variables: - SCALA: "2.13.6" + SCALA: "2.13" # Choice of MongoDB storage engine - id: storage-engine diff --git a/.evergreen/publish.sh b/.evergreen/publish.sh index bfecc0ae86..77e3a77cba 100755 --- a/.evergreen/publish.sh +++ b/.evergreen/publish.sh @@ -26,6 +26,6 @@ fi SYSTEM_PROPERTIES="-Dorg.gradle.internal.publish.checksums.insecure=true -Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.http.socketTimeout=120000" ./gradlew -version -./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} -./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.12.12 -./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PdefaultScalaVersions=2.11.12 +./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} +./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PscalaVersion=2.12 +./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PscalaVersion=2.11 diff --git a/bson-scala/build.gradle b/bson-scala/build.gradle deleted file mode 100644 index 6606dec5a8..0000000000 --- a/bson-scala/build.gradle +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -description = "A Scala wrapper / extension to the bson library" -archivesBaseName = 'mongo-scala-bson' - -dependencies { - implementation project(path: ':bson', configuration: 'default') -} - -sourceSets { - main { - scala { - if(scalaVersion.startsWith("2.13")) { - srcDirs = ["src/main/scala", "src/main/scala-2.13+"] - } else { - srcDirs = ["src/main/scala", "src/main/scala-2.13-"] - } - } - } -} - -tasks.withType(Test) { - doFirst { - println("Running Test task using scala version: $scalaVersion") - } -} - -// =================== -// Scala checks -// =================== -tasks.register("scalaCheck") { - description = "Runs all the Scala checks" - group = "verification" - - dependsOn("clean", "compileTestScala", "check") - tasks.findByName("check").mustRunAfter("clean") -} - -ext { - pomName = 'Mongo Scala Bson Library' -} - -test { - maxParallelForks = 1 -} - -afterEvaluate { - jar.manifest.attributes['Automatic-Module-Name'] = 'org.mongodb.bson.scala' - jar.manifest.attributes['Import-Package'] = [ - '!scala.*', - '*' - ].join(',') -} diff --git a/bson-scala/build.gradle.kts b/bson-scala/build.gradle.kts new file mode 100644 index 0000000000..08480658ca --- /dev/null +++ b/bson-scala/build.gradle.kts @@ -0,0 +1,65 @@ +/* + * 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 config.Extensions.scalaVersion +import config.Extensions.setAll + +plugins { id("conventions.scala") } + +base.archivesName.set("mongo-scala-bson") + +val scalaVersion: String = project.scalaVersion() + +extra.setAll( + mapOf( + "mavenName" to "Mongo Scala Bson Library", + "mavenDescription" to "A Scala wrapper / extension to the bson library", + "automaticModuleName" to "org.mongodb.bson.scala", + "importPackage" to "!scala.*,*", + "scalaVersion" to scalaVersion, + "mavenArtifactId" to "${base.archivesName.get()}_${scalaVersion}")) + +dependencies { implementation(project(path = ":bson", configuration = "default")) } + +// ============================================ +// Scala version specific configuration +// ============================================ +when (scalaVersion) { + "2.13" -> { + dependencies { + implementation(libs.bundles.scala.v2.v13) + + testImplementation(libs.bundles.scala.test.v2.v13) + } + sourceSets { main { scala { setSrcDirs(listOf("src/main/scala", "src/main/scala-2.13")) } } } + } + "2.12" -> { + dependencies { + implementation(libs.bundles.scala.v2.v12) + + testImplementation(libs.bundles.scala.test.v2.v12) + } + sourceSets { main { scala { setSrcDirs(listOf("src/main/scala", "src/main/scala-2.12")) } } } + } + "2.11" -> { + dependencies { + implementation(libs.bundles.scala.v2.v11) + + testImplementation(libs.bundles.scala.test.v2.v11) + } + // Reuse the scala-2.12 source as its compatible. + sourceSets { main { scala { setSrcDirs(listOf("src/main/scala", "src/main/scala-2.12")) } } } + } +} diff --git a/bson-scala/src/main/scala-2.13-/org/mongodb/scala/bson/collection/immutable/Document.scala b/bson-scala/src/main/scala-2.12/org/mongodb/scala/bson/collection/immutable/Document.scala similarity index 100% rename from bson-scala/src/main/scala-2.13-/org/mongodb/scala/bson/collection/immutable/Document.scala rename to bson-scala/src/main/scala-2.12/org/mongodb/scala/bson/collection/immutable/Document.scala diff --git a/bson-scala/src/main/scala-2.13-/org/mongodb/scala/bson/collection/mutable/Document.scala b/bson-scala/src/main/scala-2.12/org/mongodb/scala/bson/collection/mutable/Document.scala similarity index 100% rename from bson-scala/src/main/scala-2.13-/org/mongodb/scala/bson/collection/mutable/Document.scala rename to bson-scala/src/main/scala-2.12/org/mongodb/scala/bson/collection/mutable/Document.scala diff --git a/bson-scala/src/main/scala-2.13+/org/mongodb/scala/bson/collection/immutable/Document.scala b/bson-scala/src/main/scala-2.13/org/mongodb/scala/bson/collection/immutable/Document.scala similarity index 100% rename from bson-scala/src/main/scala-2.13+/org/mongodb/scala/bson/collection/immutable/Document.scala rename to bson-scala/src/main/scala-2.13/org/mongodb/scala/bson/collection/immutable/Document.scala diff --git a/bson-scala/src/main/scala-2.13+/org/mongodb/scala/bson/collection/mutable/Document.scala b/bson-scala/src/main/scala-2.13/org/mongodb/scala/bson/collection/mutable/Document.scala similarity index 100% rename from bson-scala/src/main/scala-2.13+/org/mongodb/scala/bson/collection/mutable/Document.scala rename to bson-scala/src/main/scala-2.13/org/mongodb/scala/bson/collection/mutable/Document.scala diff --git a/bson-scala/src/test/scala/org/mongodb/scala/bson/BaseSpec.scala b/bson-scala/src/test/scala/org/mongodb/scala/bson/BaseSpec.scala index ad6cab0069..4ac18c5b31 100644 --- a/bson-scala/src/test/scala/org/mongodb/scala/bson/BaseSpec.scala +++ b/bson-scala/src/test/scala/org/mongodb/scala/bson/BaseSpec.scala @@ -15,10 +15,7 @@ */ package org.mongodb.scala.bson -import org.junit.runner.RunWith import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import org.scalatestplus.junit.JUnitRunner -@RunWith(classOf[JUnitRunner]) abstract class BaseSpec extends AnyFlatSpec with Matchers {} diff --git a/bson-scala/src/test/scala/org/mongodb/scala/bson/codecs/MacrosSpec.scala b/bson-scala/src/test/scala/org/mongodb/scala/bson/codecs/MacrosSpec.scala index 95d7533cc8..fd4bb3d07b 100644 --- a/bson-scala/src/test/scala/org/mongodb/scala/bson/codecs/MacrosSpec.scala +++ b/bson-scala/src/test/scala/org/mongodb/scala/bson/codecs/MacrosSpec.scala @@ -530,6 +530,7 @@ class MacrosSpec extends BaseSpec { } it should "support tagged types in case classes" in { + assume(!scala.util.Properties.versionNumberString.startsWith("2.11")) val a = 1.asInstanceOf[Int with Tag] val b = "b".asInstanceOf[String with Tag] val c = Map("c" -> 0).asInstanceOf[Map[String with Tag, Int with Tag] with Tag] diff --git a/bson/build.gradle b/bson/build.gradle index d2b2ed3ba0..15d2bec6bf 100644 --- a/bson/build.gradle +++ b/bson/build.gradle @@ -14,6 +14,10 @@ * limitations under the License. */ +plugins { + id('conventions.testArtifacts') +} + archivesBaseName = 'bson' description = 'The BSON library' diff --git a/bson/src/test/unit/util/JsonPoweredTestHelper.java b/bson/src/test/unit/util/JsonPoweredTestHelper.java index 4507e64301..2d02aa0a52 100644 --- a/bson/src/test/unit/util/JsonPoweredTestHelper.java +++ b/bson/src/test/unit/util/JsonPoweredTestHelper.java @@ -41,6 +41,7 @@ import static java.nio.file.Files.isDirectory; import static java.util.stream.Collectors.toMap; +import static org.bson.assertions.Assertions.assertNotNull; public final class JsonPoweredTestHelper { @@ -87,7 +88,11 @@ public static Map testDocs(final Path dir) { public static List getTestFiles(final String resourcePath) throws URISyntaxException { List files = new ArrayList<>(); - addFilesFromDirectory(new File(JsonPoweredTestHelper.class.getResource(resourcePath).toURI()), files); + + URL resource = JsonPoweredTestHelper.class.getResource(resourcePath); + File directory = new File(assertNotNull(resource).toExternalForm()); + addFilesFromDirectory(directory, files); + return files; } diff --git a/build.gradle b/build.gradle index aa0dd05ed3..16056ed4c7 100644 --- a/build.gradle +++ b/build.gradle @@ -106,68 +106,6 @@ configure(javaProjects) { } -configure(scalaProjects) { - apply plugin: 'scala' - apply plugin: 'idea' - apply plugin: "com.adtran.scala-multiversion-plugin" - apply plugin: "com.diffplug.spotless" - - group = 'org.mongodb.scala' - - dependencies { - implementation ('org.scala-lang:scala-library:%scala-version%') - implementation ('org.scala-lang:scala-reflect:%scala-version%') - - testImplementation(platform("org.junit:junit-bom:$junitBomVersion")) - testImplementation("org.junit.vintage:junit-vintage-engine") - - testImplementation('org.scalatest:scalatest-flatspec_%%:3.2.9') - testImplementation('org.scalatest:scalatest-shouldmatchers_%%:3.2.9') - testImplementation('org.scalatestplus:junit-4-13_%%:3.2.9.0') - testImplementation('org.scalatestplus:mockito-3-12_%%:3.2.10.0') - testImplementation('ch.qos.logback:logback-classic:1.1.3') - testImplementation('org.reflections:reflections:0.9.10') - } - - test{ - useJUnitPlatform { - includeEngines('junit-jupiter', 'junit-vintage') - } - } - - spotless { - scala { - scalafmt().configFile("$configDir/scala/scalafmt.conf") - } - } - compileScala.dependsOn('spotlessApply') - compileTestScala.dependsOn('spotlessApply') - - tasks.withType(ScalaCompile) { - scalaCompileOptions.deprecation = false - if(scalaVersion.startsWith("2.11")) { - scalaCompileOptions.additionalParameters = [ - // support static methods in interfaces - "-target:jvm-1.8" - ] - } - if(scalaVersion.startsWith("2.13")) { - scalaCompileOptions.additionalParameters = [ - "-feature", - "-unchecked", - "-language:reflectiveCalls", - "-Wconf:cat=deprecation:ws,any:e", - "-Xlint:strict-unsealed-patmat" - ] - } - - } - - tasks.withType(GenerateModuleMetadata) { - enabled = false - } -} - configure(javaMainProjects) { apply plugin: 'nebula.optional-base' apply plugin: 'java-library' diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000000..b9bcb05cbe --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,48 @@ +/* + * 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. + */ + +@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed +plugins { + `kotlin-dsl` + // When updating, update in libs.versions.toml + id("com.diffplug.spotless") version "6.25.0" +} + +repositories { + gradlePluginPortal() + mavenCentral() +} + +dependencies { + implementation(libs.spotless.plugin) + implementation(libs.test.logger.plugin) + + // https://github.com/gradle/gradle/issues/15383 + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) +} + +spotless { + kotlinGradle { + ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) } + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + target("./**/*.gradle.kts", "./**/*.kt") + licenseHeaderFile("../config/mongodb.license", "package ") + } +} + +tasks.withType { dependsOn("spotlessApply") } diff --git a/settings.gradle b/buildSrc/settings.gradle.kts similarity index 55% rename from settings.gradle rename to buildSrc/settings.gradle.kts index ab25272707..ed21f37b18 100644 --- a/settings.gradle +++ b/buildSrc/settings.gradle.kts @@ -13,22 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } } } -include ':bson' -include ':bson-record-codec' -include ':driver-benchmarks' -include ':driver-workload-executor' -include ':driver-lambda' -include ':driver-core' -include ':driver-legacy' -include ':driver-sync' -include ':driver-reactive-streams' -include ':bson-kotlin' -include ':bson-kotlinx' -include ':driver-kotlin-sync' -include ':driver-kotlin-coroutine' -include ':bson-scala' -include ':driver-scala' -include 'util:spock' -include 'util:taglets' -include ':graalvm-native-image-app' +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} diff --git a/buildSrc/src/main/kotlin/config/Extensions.kt b/buildSrc/src/main/kotlin/config/Extensions.kt new file mode 100644 index 0000000000..300f613748 --- /dev/null +++ b/buildSrc/src/main/kotlin/config/Extensions.kt @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package config + +import org.gradle.api.Project +import org.gradle.api.plugins.ExtraPropertiesExtension + +object Extensions { + + /** + * Extension function to allow easy setting of multiple items to `project.extra` + */ + fun ExtraPropertiesExtension.setAll(valueMap: Map) { + valueMap.forEach { set(it.key, it.value) } + } + + /** + * Extension function to get and validate the current scala version + */ + fun Project.scalaVersion(): String { + val supportedScalaVersions = (project.property("supportedScalaVersions") as String).split(",") + val scalaVersion: String = (project.findProperty("scalaVersion") ?: project.property("defaultScalaVersion")) as String + + if (!supportedScalaVersions.contains(scalaVersion)) { + throw UnsupportedOperationException("""Scala version: $scalaVersion is not a supported scala version. + |Supported versions: $supportedScalaVersions + """.trimMargin()) + } + + return scalaVersion + } +} diff --git a/buildSrc/src/main/kotlin/config/publishing.kt b/buildSrc/src/main/kotlin/config/publishing.kt new file mode 100644 index 0000000000..d9bf4b78d5 --- /dev/null +++ b/buildSrc/src/main/kotlin/config/publishing.kt @@ -0,0 +1,49 @@ +/* + * 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. + */ +package config + +import org.gradle.api.publish.maven.MavenPom +import org.gradle.api.publish.maven.MavenPublication + +/** + * Creates and configures the pom + * + * Also allows overrides via the `configure` parameter + */ +fun MavenPublication.createPom(configure: MavenPom.() -> Unit = {}): Unit = pom { + url.set("https://www.mongodb.com/") + scm { + url.set("https://github.com/mongodb/mongo-java-driver") + connection.set("scm:https://github.com/mongodb/mongo-java-driver.git") + developerConnection.set("scm:https://github.com/mongodb/mongo-java-driver.git") + } + + developers { + developer { + id.set("Various") + name.set("Various") + organization.set("MongoDB") + } + } + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + configure() +} diff --git a/buildSrc/src/main/kotlin/conventions/integrationTesting.gradle.kts b/buildSrc/src/main/kotlin/conventions/integrationTesting.gradle.kts new file mode 100644 index 0000000000..3b8bdc99a0 --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/integrationTesting.gradle.kts @@ -0,0 +1,57 @@ +/* + * 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. + */ +package conventions + +import org.gradle.accessors.dm.LibrariesForLibs + +plugins { + id("java-library") + id("scala") +} + +// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_additional_test_types.html +val integrationTest by sourceSets.creating { + scala.srcDir("src/integrationTest/scala") + java.srcDir("src/integrationTest/java") + resources.srcDir("src/integrationTest/resources") +} + +configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get()) +configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get()) + +val integrationTestTask = tasks.register("integrationTest") { + description = "Runs integration tests." + group = "verification" + useJUnitPlatform() + + testClassesDirs = integrationTest.output.classesDirs + classpath = configurations[integrationTest.runtimeClasspathConfigurationName] + integrationTest.output + shouldRunAfter(tasks.test) +} + +tasks.findByName("scalaCheck")?.dependsOn(integrationTestTask) +tasks.findByName("check")?.dependsOn(integrationTestTask) + +// Get Access to libs // https://github.com/gradle/gradle/issues/15383 +val libs = the() +dependencies { + "integrationTestImplementation"(project) + "integrationTestImplementation"(platform(libs.junit.bom)) + "integrationTestImplementation"(libs.bundles.junit.vintage) + "integrationTestImplementation"(platform(libs.spock.bom)) + "integrationTestImplementation"(libs.bundles.spock) +} + diff --git a/buildSrc/src/main/kotlin/conventions/publishing.gradle.kts b/buildSrc/src/main/kotlin/conventions/publishing.gradle.kts new file mode 100644 index 0000000000..3261909f7a --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/publishing.gradle.kts @@ -0,0 +1,135 @@ +/* + * 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. + */ +package conventions + +import config.createPom + +plugins { + id("java-library") + id("maven-publish") + id("signing") +} + +val signingKey: Provider = providers.gradleProperty("signingKey") +val signingPassword: Provider = providers.gradleProperty("signingPassword") +val nexusUsername: Provider = providers.gradleProperty("nexusUsername") +val nexusPassword: Provider = providers.gradleProperty("nexusPassword") + +tasks.withType().configureEach { + // Gradle warns about some signing tasks using publishing task outputs without explicit + // dependencies. Here's a quick fix. + dependsOn(tasks.withType()) + mustRunAfter(tasks.withType()) + + doLast { + logger.lifecycle("[task: ${name}] ${publication.groupId}:${publication.artifactId}:${publication.version}") + } +} + +java { + withSourcesJar() + withJavadocJar() +} + +val mavenName: String by project.extra +val mavenDescription: String by project.extra +val mavenUrl: String? by project.extra +val mavenArtifactId: String? by project.extra +val localBuildRepo: String = "${rootProject.buildDir}/repo" + +val sonatypeRepositoryReleaseUrl: Provider = provider { + if (version.toString().endsWith("SNAPSHOT")) { + "https://oss.sonatype.org/content/repositories/snapshots/" + } else { + "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + } +} + +publishing { + repositories { + maven { + url = uri(sonatypeRepositoryReleaseUrl) + if (nexusUsername.isPresent && nexusPassword.isPresent) { + credentials { + username = nexusUsername.get() + password = nexusPassword.get() + } + } + } + + // publish to local dir, for artifact tracking and testing + maven { + url = uri(localBuildRepo) + name = "LocalBuild" + } + } + + publications { + create("mavenJava") { + components.findByName("scala").let { from(it) } + components.findByName("java").let { from(it) } + } + } + + publications.withType().configureEach { + createPom { + name.set(provider { mavenName }) + description.set(provider { mavenDescription }) + } + + if (signingKey.isPresent && signingPassword.isPresent) { + signing.sign(this) + } + + afterEvaluate { + mavenArtifactId?.let { artifactId = it } + mavenUrl?.let { pom.url.set(it) } + } + } +} + +tasks.named("clean") { + delete.add(localBuildRepo) +} + +tasks.withType { + afterEvaluate { + manifest { + attributes( + mapOf( + "-exportcontents" to "*;-noimport:=true", + "Build-Version" to project.findProperty("gitVersion"), + "Bundle-Version" to project.version, + "Bundle-Name" to project.findProperty("archivesBaseName"), + "Bundle-SymbolicName" to "${group}.${project.findProperty("archivesBaseName")}", + "Automatic-Module-Name" to project.extra.get("automaticModuleName"), + "Import-Package" to project.extra.get("importPackage") + ) + ) + } + } +} + +signing { + if (signingKey.isPresent && signingPassword.isPresent) { + logger.debug("[${project.displayName}] Signing is enabled") + useInMemoryPgpKeys(signingKey.get(), signingPassword.get()) + } +} + +// workaround for https://github.com/gradle/gradle/issues/16543 +inline fun TaskContainer.provider(taskName: String): Provider = + providers.provider { taskName }.flatMap { named(it) } diff --git a/buildSrc/src/main/kotlin/conventions/scala.gradle.kts b/buildSrc/src/main/kotlin/conventions/scala.gradle.kts new file mode 100644 index 0000000000..fa9b6eea31 --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/scala.gradle.kts @@ -0,0 +1,96 @@ +/* + * 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. + */ + +package conventions + +import org.gradle.accessors.dm.LibrariesForLibs + +plugins { + id("scala") + id("conventions.publishing") + id("conventions.spotless") + id("conventions.testing") +} + +group = "org.mongodb.scala" + +tasks { + compileScala { dependsOn("spotlessApply") } + compileTestScala { dependsOn("spotlessApply") } +} + +val scalaVersion: String by lazy { extra.get("scalaVersion") as String? ?: "unknown" } + +tasks.withType { enabled = false } + +afterEvaluate { + tasks.withType { + scalaCompileOptions.isDeprecation = false + val compileOptions = mutableListOf("-target:jvm-1.8") + compileOptions.addAll(when (scalaVersion) { + "2.13" -> listOf( + "-feature", + "-unchecked", + "-language:reflectiveCalls", + "-Wconf:cat=deprecation:ws,any:e", + "-Xlint:strict-unsealed-patmat" + ) + "2.11" -> listOf("-Xexperimental") + else -> emptyList() + }) + scalaCompileOptions.additionalParameters = compileOptions + } +} + + +// =================== +// Scala checks +// =================== +tasks.register("scalaCheck") { + description = "Runs all the Scala checks" + group = "verification" + + dependsOn("clean", "compileTestScala", "check") + tasks.findByName("check")?.mustRunAfter("clean") +} + +// =================== +// Scala testing +// =================== +tasks.withType { + doFirst { println("Running Test task using scala version: $scalaVersion") } + useJUnitPlatform { includeEngines("scalatest") } +} + +// =================== +// Scala docs +// =================== + +tasks.withType { + group = "documentation" + + afterEvaluate { + destinationDir = file("${rootProject.buildDir.path}/docs/${project.base.archivesName.get()}") + } +} + +rootProject.tasks.named("docs") { + dependsOn(tasks.findByName("scaladoc")) +} + +tasks.named("clean") { + delete.add("${rootProject.buildDir.path}/docs") +} diff --git a/buildSrc/src/main/kotlin/conventions/spotless.gradle.kts b/buildSrc/src/main/kotlin/conventions/spotless.gradle.kts new file mode 100644 index 0000000000..35751db48c --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/spotless.gradle.kts @@ -0,0 +1,59 @@ +/* + * 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. + */ + +package conventions + +import com.diffplug.gradle.spotless.SpotlessApply +import com.diffplug.gradle.spotless.SpotlessCheck + +plugins { id("com.diffplug.spotless") } + +spotless { + scala { scalafmt().configFile(rootProject.file("config/scala/scalafmt.conf")) } + + 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")) + } + + format("extraneous") { + target("*.xml", "*.yml", "*.md") + trimTrailingWhitespace() + indentWithSpaces() + endWithNewline() + } +} + +tasks { + withType().configureEach { + notCompatibleWithConfigurationCache("https://github.com/diffplug/spotless/issues/644") + } + withType().configureEach { + notCompatibleWithConfigurationCache("https://github.com/diffplug/spotless/issues/644") + } +} diff --git a/buildSrc/src/main/kotlin/conventions/testArtifacts.gradle.kts b/buildSrc/src/main/kotlin/conventions/testArtifacts.gradle.kts new file mode 100644 index 0000000000..44a32e7633 --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/testArtifacts.gradle.kts @@ -0,0 +1,40 @@ +/* + * 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. + */ +package conventions + +plugins { + id("java-library") +} + + +/** + * Create a test artifact configuration so that test resources can be consumed by other projects. + * + * TODO: Migrate to using https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures + */ +val testArtifacts by configurations.creating +val testJar by tasks.registering(Jar::class) { + archiveBaseName.set("${project.name}-test") + from(sourceSets.test.get().output) +} + +tasks.test { + mustRunAfter(testJar) +} + +artifacts { + add("testArtifacts", testJar) +} diff --git a/buildSrc/src/main/kotlin/conventions/testing.gradle.kts b/buildSrc/src/main/kotlin/conventions/testing.gradle.kts new file mode 100644 index 0000000000..a84bb1a68e --- /dev/null +++ b/buildSrc/src/main/kotlin/conventions/testing.gradle.kts @@ -0,0 +1,62 @@ +/* + * 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. + */ +package conventions + +import com.adarshr.gradle.testlogger.theme.ThemeType +import gradle.kotlin.dsl.accessors._2cd6d09f8559ded4a6d8fc3a737c7cc9.testImplementation +import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.tasks.testing.logging.TestExceptionFormat + +plugins { + id("com.adarshr.test-logger") +} + +// Get Access to libs // https://github.com/gradle/gradle/issues/15383 +val libs = the() +dependencies { + testImplementation(platform(libs.junit.bom)) + testImplementation(libs.bundles.junit) +} + +tasks.withType { + maxHeapSize = "4g" + maxParallelForks = 1 + + testLogging { + exceptionFormat = TestExceptionFormat.FULL + events("passed", "skipped", "failed") + } +} + +testlogger { + theme = ThemeType.STANDARD + showExceptions = true + showStackTraces = true + showFullStackTraces = false + showCauses = true + slowThreshold = 2000 + showSummary = true + showSimpleNames = false + showPassed = true + showSkipped = true + showFailed = true + showOnlySlow = false + showStandardStreams = false + showPassedStandardStreams = true + showSkippedStandardStreams = true + showFailedStandardStreams = true + logLevel = LogLevel.LIFECYCLE +} diff --git a/driver-core/build.gradle b/driver-core/build.gradle index 40a63c15d4..7166158520 100644 --- a/driver-core/build.gradle +++ b/driver-core/build.gradle @@ -17,6 +17,7 @@ plugins { id 'com.github.gmazzo.buildconfig' version '3.0.3' + id('conventions.testArtifacts') } archivesBaseName = 'mongodb-driver-core' diff --git a/driver-reactive-streams/build.gradle b/driver-reactive-streams/build.gradle index 5a08997e6e..c6a49ac5a4 100644 --- a/driver-reactive-streams/build.gradle +++ b/driver-reactive-streams/build.gradle @@ -14,6 +14,10 @@ * limitations under the License. */ +plugins { + id('conventions.testArtifacts') +} + description = "A Reactive Streams implementation of the MongoDB Java driver" archivesBaseName = 'mongodb-driver-reactivestreams' diff --git a/driver-scala/build.gradle b/driver-scala/build.gradle deleted file mode 100644 index f9852968f0..0000000000 --- a/driver-scala/build.gradle +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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. - */ - -description = "A Scala wrapper of the MongoDB Reactive Streams Java driver" -archivesBaseName = 'mongo-scala-driver' - - -dependencies { - implementation project(path: ':bson-scala', configuration: 'default') - implementation project(path: ':driver-reactive-streams', configuration: 'default') - - testImplementation project(':driver-sync') - testImplementation project(':bson').sourceSets.test.output - testImplementation project(':driver-sync').sourceSets.test.output - testImplementation project(':driver-core').sourceSets.test.output - testImplementation project(':driver-reactive-streams').sourceSets.test.output - testRuntimeOnly project(path: ':driver-core', configuration: 'consumableTestRuntimeOnly') -} - -sourceSets { - integrationTest { - scala.srcDir file('src/integration/scala') - scala { - compileClasspath += main.output - runtimeClasspath += main.output - } - } -} - -test { - maxParallelForks = 1 -} - -tasks.withType(Test) { - doFirst { - println("Running Test task using scala version: $scalaVersion") - } -} - -tasks.withType(ScalaCompile) { - if(scalaVersion.startsWith("2.11")) { - // Better support SAM style closures in scala 2.11 - scalaCompileOptions.additionalParameters.addAll([ - // Better support SAM style closures in scala 2.11 - "-Xexperimental" - ]) - } -} - -task integrationTest(type: Test) { - delete 'build/test-integration' - testClassesDirs = sourceSets.integrationTest.output.classesDirs - classpath = sourceSets.integrationTest.runtimeClasspath - mustRunAfter test -} - -check.dependsOn integrationTest - -// =================== -// Scala checks -// =================== -tasks.register("scalaCheck") { - description = "Runs all the Scala checks" - group = "verification" - - dependsOn("clean", "compileTestScala", "compileIntegrationTestScala", "check") - tasks.findByName("check").mustRunAfter("clean") -} - - -task aggregatedScalaDoc(type: ScalaDoc) { - description('Unified Scaladoc for bson-scala and driver-scala') - group('documentation') - ext.fromProjects = [ - project(':bson-scala'), - project(':driver-scala') - ] - destinationDir = file("${rootProject.buildDir.path}/docs/${project.archivesBaseName}") - classpath = project.sourceSets.main.compileClasspath - source = fromProjects.collect { it.sourceSets.main.allSource } - - scalaDocOptions.additionalParameters = ["-doc-root-content", "${project.rootDir}/driver-scala/rootdoc.txt" as String] -} -project.parent.tasks.named("docs"){ it.dependsOn(aggregatedScalaDoc) } - -configurations { - integrationTestImplementation { - extendsFrom testImplementation - canBeResolved = true - } -} - -idea { - module { - testSourceDirs += sourceSets.integrationTest.scala.srcDirs - testResourceDirs += sourceSets.integrationTest.resources.srcDirs - scopes.TEST.plus += [ configurations.integrationTestImplementation ] - } -} - - -ext { - pomName = 'Mongo Scala Driver' -} - -afterEvaluate { - jar.manifest.attributes['Automatic-Module-Name'] = 'org.mongodb.driver.scala' - jar.manifest.attributes['Import-Package'] = [ - '!scala.*', - '*' - ].join(',') -} diff --git a/driver-scala/build.gradle.kts b/driver-scala/build.gradle.kts new file mode 100644 index 0000000000..747829c871 --- /dev/null +++ b/driver-scala/build.gradle.kts @@ -0,0 +1,84 @@ +/* + * 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 config.Extensions.scalaVersion +import config.Extensions.setAll + +plugins { + id("conventions.scala") + id("conventions.integrationTesting") +} + +val scalaVersion: String = project.scalaVersion() + +base.archivesName.set("mongo-scala-driver") + +extra.setAll( + mapOf( + "mavenName" to "Mongo Scala Driver", + "mavenDescription" to "A Scala wrapper of the MongoDB Reactive Streams Java driver", + "automaticModuleName" to "org.mongodb.driver.scala", + "importPackage" to "!scala.*,*", + "scalaVersion" to scalaVersion, + "mavenArtifactId" to "${base.archivesName.get()}_${scalaVersion}")) + +dependencies { + implementation(project(path = ":bson-scala", configuration = "default")) + implementation(project(path = ":driver-reactive-streams", configuration = "default")) + + "integrationTestImplementation"(project(path = ":driver-sync")) + "integrationTestImplementation"(project(path = ":driver-reactive-streams")) + "integrationTestImplementation"(project(path = ":bson", configuration = "testArtifacts")) + "integrationTestImplementation"(project(path = ":driver-core", configuration = "testArtifacts")) + "integrationTestImplementation"(project(path = ":driver-sync", configuration = "testArtifacts")) + "integrationTestImplementation"(project(path = ":driver-reactive-streams", configuration = "testArtifacts")) +} + +// =================== +// Scala docs +// =================== + +tasks.withType().forEach { + // Include bson-scala source for main scaladoc + project(":bson-scala").tasks.withType().forEach { bsonScala -> it.source += bsonScala.source } + it.scalaDocOptions.additionalParameters = listOf("-doc-root-content", "${project.rootDir}/driver-scala/rootdoc.txt") +} + +// ============================================ +// Scala version specific configuration +// ============================================ +when (scalaVersion) { + "2.13" -> { + dependencies { + implementation(libs.bundles.scala.v2.v13) + + testImplementation(libs.bundles.scala.test.v2.v13) + } + } + "2.12" -> { + dependencies { + implementation(libs.bundles.scala.v2.v12) + + testImplementation(libs.bundles.scala.test.v2.v12) + } + } + "2.11" -> { + dependencies { + implementation(libs.bundles.scala.v2.v11) + + testImplementation(libs.bundles.scala.test.v2.v11) + } + } +} diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/BaseSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/BaseSpec.scala similarity index 87% rename from driver-scala/src/integration/scala/org/mongodb/scala/BaseSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/BaseSpec.scala index 98ce89a88f..7f400d4f48 100644 --- a/driver-scala/src/integration/scala/org/mongodb/scala/BaseSpec.scala +++ b/driver-scala/src/integrationTest/scala/org/mongodb/scala/BaseSpec.scala @@ -15,10 +15,6 @@ */ package org.mongodb.scala -import org.junit.runner.RunWith import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import org.scalatestplus.junit.JUnitRunner - -@RunWith(classOf[JUnitRunner]) abstract class BaseSpec extends AnyFlatSpec with Matchers {} diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/ClientSideEncryptionBypassAutoEncryptionSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/ClientSideEncryptionBypassAutoEncryptionSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/ClientSideEncryptionBypassAutoEncryptionSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/ClientSideEncryptionBypassAutoEncryptionSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/ClientSideEncryptionTest.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/ClientSideEncryptionTest.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/ClientSideEncryptionTest.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/ClientSideEncryptionTest.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/FuturesSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/FuturesSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/FuturesSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/FuturesSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/MongoCollectionCaseClassSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/MongoCollectionCaseClassSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/MongoCollectionCaseClassSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/MongoCollectionCaseClassSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/RequiresMongoDBISpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/RequiresMongoDBISpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/RequiresMongoDBISpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/RequiresMongoDBISpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/RetryableReadsTest.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/RetryableReadsTest.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/RetryableReadsTest.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/RetryableReadsTest.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/TestMongoClientHelper.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/TestMongoClientHelper.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/TestMongoClientHelper.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/TestMongoClientHelper.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationChangeStreamExampleSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationChangeStreamExampleSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationChangeStreamExampleSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationChangeStreamExampleSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationExampleSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationExampleSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationExampleSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationExampleSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationTransactionsExampleSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationTransactionsExampleSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/documentation/DocumentationTransactionsExampleSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/documentation/DocumentationTransactionsExampleSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/gridfs/GridFSObservableSpec.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/gridfs/GridFSObservableSpec.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/gridfs/GridFSObservableSpec.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/gridfs/GridFSObservableSpec.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncAggregateIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncAggregateIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncAggregateIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncAggregateIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncChangeStreamIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncChangeStreamIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncChangeStreamIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncChangeStreamIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncClientSession.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncClientSession.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncClientSession.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncClientSession.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncDistinctIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncDistinctIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncDistinctIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncDistinctIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncFindIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncFindIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncFindIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncFindIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListCollectionsIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListCollectionsIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListCollectionsIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListCollectionsIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListDatabasesIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListDatabasesIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListDatabasesIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListDatabasesIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListIndexesIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListIndexesIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListIndexesIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListIndexesIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListSearchIndexesIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListSearchIndexesIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncListSearchIndexesIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncListSearchIndexesIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMapReduceIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMapReduceIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMapReduceIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMapReduceIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoClient.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoClient.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoClient.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoClient.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoCollection.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoCollection.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoCollection.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoCollection.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoCursor.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoCursor.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoCursor.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoCursor.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoDatabase.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoDatabase.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoDatabase.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoDatabase.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoIterable.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoIterable.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/SyncMongoIterable.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/SyncMongoIterable.scala diff --git a/driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/package.scala b/driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/package.scala similarity index 100% rename from driver-scala/src/integration/scala/org/mongodb/scala/syncadapter/package.scala rename to driver-scala/src/integrationTest/scala/org/mongodb/scala/syncadapter/package.scala diff --git a/driver-scala/src/integration/scala/tour/ClientSideEncryptionAutoEncryptionSettingsTour.scala b/driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionAutoEncryptionSettingsTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/ClientSideEncryptionAutoEncryptionSettingsTour.scala rename to driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionAutoEncryptionSettingsTour.scala diff --git a/driver-scala/src/integration/scala/tour/ClientSideEncryptionExplicitEncryptionAndDecryptionTour.scala b/driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionExplicitEncryptionAndDecryptionTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/ClientSideEncryptionExplicitEncryptionAndDecryptionTour.scala rename to driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionExplicitEncryptionAndDecryptionTour.scala diff --git a/driver-scala/src/integration/scala/tour/ClientSideEncryptionExplicitEncryptionOnlyTour.scala b/driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionExplicitEncryptionOnlyTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/ClientSideEncryptionExplicitEncryptionOnlyTour.scala rename to driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionExplicitEncryptionOnlyTour.scala diff --git a/driver-scala/src/integration/scala/tour/ClientSideEncryptionSimpleTour.scala b/driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionSimpleTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/ClientSideEncryptionSimpleTour.scala rename to driver-scala/src/integrationTest/scala/tour/ClientSideEncryptionSimpleTour.scala diff --git a/driver-scala/src/integration/scala/tour/GridFSTour.scala b/driver-scala/src/integrationTest/scala/tour/GridFSTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/GridFSTour.scala rename to driver-scala/src/integrationTest/scala/tour/GridFSTour.scala diff --git a/driver-scala/src/integration/scala/tour/Helpers.scala b/driver-scala/src/integrationTest/scala/tour/Helpers.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/Helpers.scala rename to driver-scala/src/integrationTest/scala/tour/Helpers.scala diff --git a/driver-scala/src/integration/scala/tour/QuickTour.scala b/driver-scala/src/integrationTest/scala/tour/QuickTour.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/QuickTour.scala rename to driver-scala/src/integrationTest/scala/tour/QuickTour.scala diff --git a/driver-scala/src/integration/scala/tour/QuickTourCaseClass.scala b/driver-scala/src/integrationTest/scala/tour/QuickTourCaseClass.scala similarity index 100% rename from driver-scala/src/integration/scala/tour/QuickTourCaseClass.scala rename to driver-scala/src/integrationTest/scala/tour/QuickTourCaseClass.scala diff --git a/driver-scala/src/test/scala/org/mongodb/scala/BaseSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/BaseSpec.scala index 98ce89a88f..9d59b8f55e 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/BaseSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/BaseSpec.scala @@ -15,10 +15,7 @@ */ package org.mongodb.scala -import org.junit.runner.RunWith import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import org.scalatestplus.junit.JUnitRunner -@RunWith(classOf[JUnitRunner]) abstract class BaseSpec extends AnyFlatSpec with Matchers {} diff --git a/driver-sync/build.gradle b/driver-sync/build.gradle index eb10ef62eb..6401313067 100644 --- a/driver-sync/build.gradle +++ b/driver-sync/build.gradle @@ -14,6 +14,10 @@ * limitations under the License. */ +plugins { + id('conventions.testArtifacts') +} + archivesBaseName = 'mongodb-driver-sync' description = 'The MongoDB Synchronous Driver' ext { diff --git a/gradle.properties b/gradle.properties index e31c63fbd6..eaf30d7bb5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,8 +16,8 @@ org.gradle.daemon=true org.gradle.jvmargs=-Duser.country=US -Duser.language=en -scalaVersions=2.11.12,2.12.15,2.13.6 -defaultScalaVersions=2.13.6 +supportedScalaVersions=2.13,2.12,2.11 +defaultScalaVersion=2.13 runOnceTasks=clean,release org.gradle.java.installations.auto-download=false org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17,JDK21,JDK21_GRAALVM diff --git a/gradle/deploy.gradle b/gradle/deploy.gradle index c34f7bf9b7..cde0ecc020 100644 --- a/gradle/deploy.gradle +++ b/gradle/deploy.gradle @@ -19,28 +19,12 @@ def deployedProjects = subprojects - utilProjects configure(deployedProjects) { - def isScala = project.name.contains('scala') - def hasAllScalaVersions = project.hasProperty('allScalaVersions') - def isInvalidScalaProject = false // isScala && !hasAllScalaVersions // TODO JAVA-3564 - task publishSnapshots { group = 'publishing' description = 'Publishes snapshots to Sonatype' if ( version.endsWith('-SNAPSHOT')) { - if (isInvalidScalaProject) { - doFirst { - def cause = """ - | Not publishing all Scala versions: - | ================================= - | - | You must set the -PallScalaVersions flag when publishing - |""".stripMargin() - throw new GradleException(cause) - } - } else { - dependsOn tasks.withType(PublishToMavenRepository) - } + dependsOn tasks.withType(PublishToMavenRepository) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000000..c18c2c9405 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,89 @@ +# 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. + +[versions] +scala-v2-v13 = "2.13.14" +scala-v2-v12 = "2.12.19" +scala-v2-v11 = "2.11.12" +scala-test = "3.2.18" +scala-test-plus = "3.2.18.0" +reflections = "0.9.10" +logback = "1.3.14" + +junit-bom = "5.8.2" +spock-bom = "2.1-groovy-3.0" +hamcrest = "1.3" + +spotless-plugin = "6.14.0" +test-logger-plugin = "4.0.0" + +[libraries] +scala-library-v2-v13 = { module = "org.scala-lang:scala-library", version.ref = "scala-v2-v13" } +scala-reflect-v2-v13 = { module = "org.scala-lang:scala-reflect", version.ref = "scala-v2-v13" } +scala-test-flatspec-v2-v13 = { module = "org.scalatest:scalatest-flatspec_2.13", version.ref = "scala-test" } +scala-test-shouldmatchers-v2-v13 = { module = "org.scalatest:scalatest-shouldmatchers_2.13", version.ref = "scala-test" } +scala-test-mockito-v2-v13 = { module = "org.scalatestplus:mockito-4-11_2.13", version.ref = "scala-test-plus" } +scala-test-junit-runner-v2-v13 = { module = "org.scalatestplus:junit-5-10_2.13", version.ref = "scala-test-plus" } + +scala-library-v2-v12 = { module = "org.scala-lang:scala-library", version.ref = "scala-v2-v12" } +scala-reflect-v2-v12 = { module = "org.scala-lang:scala-reflect", version.ref = "scala-v2-v12" } +scala-test-flatspec-v2-v12 = { module = "org.scalatest:scalatest-flatspec_2.12", version.ref = "scala-test" } +scala-test-shouldmatchers-v2-v12 = { module = "org.scalatest:scalatest-shouldmatchers_2.12", version.ref = "scala-test" } +scala-test-mockito-v2-v12 = { module = "org.scalatestplus:mockito-4-11_2.12", version.ref = "scala-test-plus" } +scala-test-junit-runner-v2-v12 = { module = "org.scalatestplus:junit-5-10_2.12", version.ref = "scala-test-plus" } + +scala-library-v2-v11 = { module = "org.scala-lang:scala-library", version.ref = "scala-v2-v11" } +scala-reflect-v2-v11 = { module = "org.scala-lang:scala-reflect", version.ref = "scala-v2-v11" } +scala-test-flatspec-v2-v11 = { module = "org.scalatest:scalatest-flatspec_2.11", version.ref = "scala-test" } +scala-test-shouldmatchers-v2-v11 = { module = "org.scalatest:scalatest-shouldmatchers_2.11", version.ref = "scala-test" } +scala-test-mockito-v2-v11 = { module = "org.scalatestplus:mockito-4-11_2.11", version.ref = "scala-test-plus" } +scala-test-junit-runner-v2-v11 = { module = "org.scalatestplus:junit-5-10_2.11", version.ref = "scala-test-plus" } + +reflections-library = {module = "org.reflections:reflections", version.ref = "reflections" } + +junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit-bom" } +junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter" } +junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params" } +junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine" } +junit-vintage-engine = { group = "org.junit.vintage", name = "junit-vintage-engine" } + +spock-bom = { group = "org.spockframework", name = "spock-bom", version.ref = "spock-bom" } +spock-core = { group = "org.spockframework", name = "spock-core" } +spock-junit4 = { group = "org.spockframework", name = "spock-junit4" } + +hamcrest-all = { module = "org.hamcrest:hamcrest-all", version.ref = "hamcrest" } +logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } + +## Plugins defined in buildSrc get added as an impementation +spotless-plugin = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless-plugin"} +test-logger-plugin = { group = "com.adarshr", name = "gradle-test-logger-plugin", version.ref = "test-logger-plugin"} + +[bundles] +scala-v2-v13 = ["scala-library-v2-v13", "scala-reflect-v2-v13"] +scala-v2-v12 = ["scala-library-v2-v12", "scala-reflect-v2-v12"] +scala-v2-v11 = ["scala-library-v2-v11", "scala-reflect-v2-v11"] + +scala-test-v2-v13 = ["scala-test-flatspec-v2-v13", "scala-test-shouldmatchers-v2-v13", "scala-test-mockito-v2-v13", + "scala-test-junit-runner-v2-v13", "reflections-library"] +scala-test-v2-v12 = ["scala-test-flatspec-v2-v12", "scala-test-shouldmatchers-v2-v12", "scala-test-mockito-v2-v12", + "scala-test-junit-runner-v2-v12", "reflections-library"] +scala-test-v2-v11 = ["scala-test-flatspec-v2-v11", "scala-test-shouldmatchers-v2-v11", "scala-test-mockito-v2-v11", + "scala-test-junit-runner-v2-v11", "reflections-library"] + +junit = ["junit-jupiter-params", "junit-jupiter-engine", "junit-jupiter", "logback-classic", "hamcrest-all"] +junit-vintage = ["junit-vintage-engine", "junit-jupiter-params", "junit-jupiter-engine", "junit-jupiter", "logback-classic", "hamcrest-all"] +spock = ["spock-core", "spock-junit4"] + + + diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 498184db98..b95c4e0331 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -116,43 +116,6 @@ configure(javaProjects) { project -> } } -configure(scalaProjects) { project -> - apply plugin: 'maven-publish' - apply plugin: 'signing' - - task sourcesJar(type: Jar) { - from project.sourceSets.main.allScala - classifier = 'sources' - } - - task scaladocJar(type: Jar) { - from scaladoc - classifier = 'javadoc' - } - - publishing { - publications { - mavenJava(MavenPublication) { - artifactId = project.archivesBaseName.contains('bson') ? 'mongo-scala-bson' : 'mongo-scala-driver' - from project.components.java - artifact sourcesJar - artifact scaladocJar - } - } - - repositories configureMavenRepositories(project) - } - - afterEvaluate { - publishing.publications.mavenJava.pom configurePom(project) - signing { - useInMemoryPgpKeys(findProperty("signingKey"), findProperty("signingPassword")) - sign publishing.publications.mavenJava - } - } -} - - configure(projectsWithManifest) { project -> apply plugin: 'biz.aQute.bnd.builder' afterEvaluate { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c023..7454180f2a 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102e09..3994438e22 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c81..1b6c787337 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000000..ab0c112d27 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + + +include(":bson") +include(":bson-record-codec") +include(":driver-benchmarks") +include(":driver-workload-executor") +include(":driver-lambda") +include(":driver-core") +include(":driver-legacy") +include(":driver-sync") +include(":driver-reactive-streams") +include(":bson-kotlin") +include(":bson-kotlinx") +include(":driver-kotlin-sync") +include(":driver-kotlin-coroutine") +include(":bson-scala") +include(":driver-scala") +include("util:spock") +include("util:taglets") +include(":graalvm-native-image-app")