Skip to content
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

JAVA-5452 #1378

Draft
wants to merge 4 commits into
base: scala3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1916,15 +1916,15 @@ axes:
- id: "2.11"
display_name: "Scala 2.11"
variables:
SCALA: "2.11.12"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libs.versions.toml now handles the scala library versioning. So this is now just for which scala release to test against.

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
Expand Down
6 changes: 3 additions & 3 deletions .evergreen/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
jyemin marked this conversation as resolved.
Show resolved Hide resolved
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info :bson-scala:${TASK} :driver-scala:${TASK} -PscalaVersion=2.11
67 changes: 0 additions & 67 deletions bson-scala/build.gradle

This file was deleted.

65 changes: 65 additions & 0 deletions bson-scala/build.gradle.kts
vbabanin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some buildSrc extension functions to make life easier.

import config.Extensions.setAll

plugins { id("conventions.scala") }
Copy link
Member Author

@rozza rozza May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main scala configuration is done by using buildSrc conventions


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")) } } }
jyemin marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed thanks to the scala test configurations done in the scala convention.

abstract class BaseSpec extends AnyFlatSpec with Matchers {}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing to compile with Scala 2.11 - not sure how it worked with the previous plugin as its a scala error. Its possible that we are using a newer scala 2.11 version patch which highlights this error.

As Scala 2.11 has been EOL for a long time so I'm not sure its worth investigating further.

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]
Expand Down
4 changes: 4 additions & 0 deletions bson/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

plugins {
id('conventions.testArtifacts')
}

archivesBaseName = 'bson'
description = 'The BSON library'

Expand Down
7 changes: 6 additions & 1 deletion bson/src/test/unit/util/JsonPoweredTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -87,7 +88,11 @@ public static Map<Path, BsonDocument> testDocs(final Path dir) {

public static List<File> getTestFiles(final String resourcePath) throws URISyntaxException {
List<File> 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;
}

Expand Down
62 changes: 0 additions & 62 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,68 +106,6 @@ configure(javaProjects) {

}

configure(scalaProjects) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root build.gradle no longer handles the configuration of scala projects.

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'
Expand Down
48 changes: 48 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildSrc project also uses spotless for formatting. Unfortunately, at the plugin stage we can't access the version from libs.versions.toml.

}

repositories {
gradlePluginPortal()
mavenCentral()
}

dependencies {
implementation(libs.spotless.plugin)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conventions now configure the spotless and logger plugins for the projects that use them.

implementation(libs.test.logger.plugin)

// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

spotless {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spotless configuration for buildSrc files only.

kotlinGradle {
ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) }
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
target("./**/*.gradle.kts", "./**/*.kt")
licenseHeaderFile("../config/mongodb.license", "package ")
}
}

tasks.withType<GradleBuild> { dependsOn("spotlessApply") }
27 changes: 9 additions & 18 deletions settings.gradle → buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) } } }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows access from within the convention to the 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()
}
}
Loading