Skip to content

Commit

Permalink
BDOG-3159 Use repo name for exemptions
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-lamed committed May 31, 2024
1 parent 06d82b0 commit c17eb6a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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 |
|----------------|---------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.9
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 11 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

with import <nixpkgs> {};

mkShell {
buildInputs = [
jdk11
];
shellHook = ''
export JAVA_HOME=${jdk11}
'';
}
3 changes: 2 additions & 1 deletion src/main/scala/uk/gov/hmrc/bobby/Bobby.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object Bobby {
|""".stripMargin

def validateDependencies(
rootName : String,
projectName : String,
dependencyDotFiles : Seq[DotFile],
internalModuleNodes: Seq[ModuleID],
Expand All @@ -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}"

Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/uk/gov/hmrc/bobby/SbtBobbyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -92,6 +95,7 @@ object SbtBobbyPlugin extends AutoPlugin {
}

Bobby.validateDependencies(
rootName,
projectName,
dependencyDotFiles,
internalModuleNodes,
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/uk/gov/hmrc/bobby/domain/BobbyValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -58,7 +58,7 @@ object BobbyValidator {
def calc(
bobbyRules : Seq[BobbyRule],
dep : ModuleID,
projectName: String,
rootName : String,
now : LocalDate = LocalDate.now()
): BobbyResult = {
val version =
Expand All @@ -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)
Expand Down

0 comments on commit c17eb6a

Please sign in to comment.