From c17eb6a6318f2ab811027c85ff250c76d931d436 Mon Sep 17 00:00:00 2001 From: colin-lamed <9568290+colin-lamed@users.noreply.github.com> Date: Fri, 31 May 2024 13:55:22 +0100 Subject: [PATCH] BDOG-3159 Use repo name for exemptions --- README.md | 4 ++-- project/build.properties | 2 +- project/plugins.sbt | 2 +- shell.nix | 11 +++++++++++ src/main/scala/uk/gov/hmrc/bobby/Bobby.scala | 3 ++- src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala | 4 ++++ .../uk/gov/hmrc/bobby/domain/BobbyValidator.scala | 8 ++++---- 7 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 shell.nix diff --git a/README.md b/README.md index 1dbc69c..ce6d8cd 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Where: * `range` is used to target minimum and maximum versions of a dependency (both min and max may be optional), and allow "holes" for known incompatible versions. See 'Supported Version Ranges' for more details * `reason` is a short descriptive message to explain why the versions matching the range are outlawed * `from` is the date the rule will come into effect. The builds will fail after that day, and generate a warning up to it -* `exemptProjects` is the optional set of sbt project names that are exempt from the rule +* `exemptProjects` is the optional set of repository names that are exempt from the rule. ## How to setup and trigger Bobby? @@ -157,7 +157,7 @@ Otherwise, all is good and you can carry on with your day. ## Supported Version Ranges -The range that is outlawed can be configured using Ivy style syntax. +The range that is outlawed can be configured using [Maven style syntax](https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN402). | Range | Applies to | |----------------|---------------------------------------| diff --git a/project/build.properties b/project/build.properties index e8a1e24..04267b1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.7 +sbt.version=1.9.9 diff --git a/project/plugins.sbt b/project/plugins.sbt index 4aa959a..804d624 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2") resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0") diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..4fa1851 --- /dev/null +++ b/shell.nix @@ -0,0 +1,11 @@ + +with import {}; + +mkShell { + buildInputs = [ + jdk11 + ]; + shellHook = '' + export JAVA_HOME=${jdk11} + ''; +} diff --git a/src/main/scala/uk/gov/hmrc/bobby/Bobby.scala b/src/main/scala/uk/gov/hmrc/bobby/Bobby.scala index 52fa3e5..751964b 100644 --- a/src/main/scala/uk/gov/hmrc/bobby/Bobby.scala +++ b/src/main/scala/uk/gov/hmrc/bobby/Bobby.scala @@ -43,6 +43,7 @@ object Bobby { |""".stripMargin def validateDependencies( + rootName : String, projectName : String, dependencyDotFiles : Seq[DotFile], internalModuleNodes: Seq[ModuleID], @@ -57,7 +58,7 @@ object Bobby { val messages = dependencyDotFiles.flatMap { dotFile => - val messages = BobbyValidator.validate(dotFile.content, dotFile.scope, bobbyRules, internalModuleNodes, projectName) + val messages = BobbyValidator.validate(dotFile.content, dotFile.scope, bobbyRules, internalModuleNodes, rootName) val outputFileName = s"bobby-report-$projectName-${dotFile.scope}" diff --git a/src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala b/src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala index c159597..668639a 100644 --- a/src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala +++ b/src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala @@ -48,6 +48,9 @@ object SbtBobbyPlugin extends AutoPlugin { val projectName = name.value val logger = sLog.value + val pwd = {import scala.sys.process._; "pwd" !!}.trim + val rootName = pwd.split("/").last + // Retrieve config settings val bobbyConfigFile: ConfigFile = ConfigFileImpl(System.getProperty("user.home") + "/.sbt/bobby.conf", logger) @@ -92,6 +95,7 @@ object SbtBobbyPlugin extends AutoPlugin { } Bobby.validateDependencies( + rootName, projectName, dependencyDotFiles, internalModuleNodes, diff --git a/src/main/scala/uk/gov/hmrc/bobby/domain/BobbyValidator.scala b/src/main/scala/uk/gov/hmrc/bobby/domain/BobbyValidator.scala index d0fd098..db78143 100644 --- a/src/main/scala/uk/gov/hmrc/bobby/domain/BobbyValidator.scala +++ b/src/main/scala/uk/gov/hmrc/bobby/domain/BobbyValidator.scala @@ -28,7 +28,7 @@ object BobbyValidator { scope : String, bobbyRules : Seq[BobbyRule], internalModuleNodes: Seq[ModuleID], - projectName : String + rootName : String ): Seq[Message] = { val graph = DependencyGraphParser.parse(graphString) val dependencies = graph.dependencies @@ -39,7 +39,7 @@ object BobbyValidator { } dependencies.map { dependency => - val result = BobbyValidator.calc(bobbyRules, dependency.toModuleID, projectName) + val result = BobbyValidator.calc(bobbyRules, dependency.toModuleID, rootName) Message( moduleID = dependency.toModuleID, @@ -58,7 +58,7 @@ object BobbyValidator { def calc( bobbyRules : Seq[BobbyRule], dep : ModuleID, - projectName: String, + rootName : String, now : LocalDate = LocalDate.now() ): BobbyResult = { val version = @@ -75,7 +75,7 @@ object BobbyValidator { matchingRules .map { rule => - if (rule.exemptProjects.contains(projectName)) + if (rule.exemptProjects.contains(rootName)) BobbyResult.Exemption(rule): BobbyResult else if (rule.effectiveDate.isBefore(now) || rule.effectiveDate.isEqual(now)) BobbyResult.Violation(rule)