From 0ccfc653230f72118a65a2e9f233675bc8827af7 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Wed, 2 Apr 2025 16:30:20 +0100 Subject: [PATCH 1/3] Updated the bom validation to ensure it runs. JAVA-5822 --- bom/build.gradle.kts | 62 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 9402462eb7..5c9b6ffa49 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -53,7 +53,7 @@ dependencies { val defaultScalaVersion: String = project.findProperty("defaultScalaVersion")!!.toString() val scalaVersions: List? = project.findProperty("supportedScalaVersions")?.toString()?.split(",") -assert(!scalaVersions.isNullOrEmpty()) { +require(!scalaVersions.isNullOrEmpty()) { "Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property" } @@ -73,14 +73,14 @@ configureMavenPublication { val pomXml: Node = asNode() val dependencyManagementNode = pomXml.getNode("dependencyManagement") - assert(dependencyManagementNode != null) { + require(dependencyManagementNode != null) { " node not found in the generated BOM POM" } val dependenciesNode = dependencyManagementNode.getNode("dependencies") - assert(dependenciesNode != null) { " node not found in the generated BOM POM" } + require(dependenciesNode != null) { " node not found in the generated BOM POM" } val existingScalaDeps = - dependenciesNode!! + dependenciesNode .children() .map { it as Node } .filter { it.getNode("artifactId")?.text()?.contains("scala") ?: false } @@ -110,37 +110,35 @@ configureMavenPublication { * Validate the BOM file. */ tasks.withType { - doLast { - pom.withXml { - val pomXml: Node = asNode() - val dependenciesNode = pomXml.getNode("dependencyManagement").getNode("dependencies") - assert(dependenciesNode!!.children().isNotEmpty()) { - "BOM must contain more then one element:\n$destination" - } + pom.withXml { + val pomXml: Node = asNode() + val dependenciesNode = pomXml.getNode("dependencyManagement").getNode("dependencies") + require(dependenciesNode!!.children().isNotEmpty()) { + "BOM must contain more then one element:\n$destination" + } - dependenciesNode - .children() - .map { it as Node } - .forEach { - val groupId: String = it.getNode("groupId")!!.text() - assert(groupId.startsWith("org.mongodb")) { - "BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination" - } + dependenciesNode + .children() + .map { it as Node } + .forEach { + val groupId: String = it.getNode("groupId")!!.text() + require(groupId.startsWith("org.mongodb")) { + "BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination" + } - /* - * The and tags should be omitted in BOM dependencies. - * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context. - * - * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies. - */ - assert(it.getNode("scope") == null) { - "BOM must not contain elements in dependency:\n$destination" - } - assert(it.getNode("optional") == null) { - "BOM must not contain elements in dependency:\n$destination" - } + /* + * The and tags should be omitted in BOM dependencies. + * This ensures that consuming projects have the flexibility to decide whether a dependency is optional in their context. + * + * The BOM's role is to provide version information, not to dictate inclusion or exclusion of dependencies. + */ + require(it.getNode("scope") == null) { + "BOM must not contain elements in dependency:\n$destination" } - } + require(it.getNode("optional") == null) { + "BOM must not contain elements in dependency:\n$destination" + } + } } } From 5483373fb0a5f595ea95425af62879255cb620c6 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Tue, 22 Apr 2025 10:00:45 +0100 Subject: [PATCH 2/3] Update bom/build.gradle.kts Co-authored-by: Viacheslav Babanin --- bom/build.gradle.kts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 5c9b6ffa49..ed0609869e 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -56,7 +56,11 @@ val scalaVersions: List? = project.findProperty("supportedScalaVersions" require(!scalaVersions.isNullOrEmpty()) { "Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property" } - +scalaVersions?.forEach { version -> + require(version.matches(Regex("\\d\\.\\d{2}"))) { + "Scala version '$version' must be in the format X.YY" + } +} /* * Apply the Java Platform plugin to create the BOM * Modify the generated POM to include all supported versions of Scala for driver-scala or bson-scala. From 4d4f0dcc57582aacbea8f48a139e7d0a39c3bd28 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Tue, 22 Apr 2025 10:19:56 +0100 Subject: [PATCH 3/3] Spotless fix --- bom/build.gradle.kts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index ed0609869e..806c4f2095 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -56,10 +56,9 @@ val scalaVersions: List? = project.findProperty("supportedScalaVersions" require(!scalaVersions.isNullOrEmpty()) { "Scala versions must be provided as a comma-separated list in the 'supportedScalaVersions' project property" } + scalaVersions?.forEach { version -> - require(version.matches(Regex("\\d\\.\\d{2}"))) { - "Scala version '$version' must be in the format X.YY" - } + require(version.matches(Regex("\\d\\.\\d{2}"))) { "Scala version '$version' must be in the format X.YY" } } /* * Apply the Java Platform plugin to create the BOM