From deba943cb5bde9beef4d40878d58fb5ade2fcd52 Mon Sep 17 00:00:00 2001 From: Roman Timushev Date: Thu, 12 Dec 2019 18:47:12 +0100 Subject: [PATCH] Add support for mima problem filters --- .../rallyhealth/sbt/semver/SemVerPlugin.scala | 2 +- .../sbt/semver/mima/MimaChecker.scala | 11 ++++++++--- src/sbt-test/semver/filters/.gitignore | 19 +++++++++++++++++++ src/sbt-test/semver/filters/build.sbt | 11 +++++++++++ .../semver/filters/project/plugins.sbt | 9 +++++++++ .../semver/filters/src/main/scala/Thing.scala | 4 ++++ src/sbt-test/semver/filters/test | 18 ++++++++++++++++++ 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/sbt-test/semver/filters/.gitignore create mode 100644 src/sbt-test/semver/filters/build.sbt create mode 100644 src/sbt-test/semver/filters/project/plugins.sbt create mode 100644 src/sbt-test/semver/filters/src/main/scala/Thing.scala create mode 100644 src/sbt-test/semver/filters/test diff --git a/src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala b/src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala index 10d8a55..ae245ea 100644 --- a/src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala +++ b/src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala @@ -196,7 +196,7 @@ object SemVerPlugin extends AutoPlugin { MiMa.miMaChecker := { val classpath = (fullClasspath in MimaKeys.mimaFindBinaryIssues).value - new MimaChecker(MiMaExecutor(classpath, streams.value)) + new MimaChecker(MiMaExecutor(classpath, streams.value), MimaKeys.mimaBinaryIssueFilters.value) }, MiMa.moduleResolver := new IvyModuleResolver(scalaModuleInfo.value, ivySbt.value, streams.value), diff --git a/src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala b/src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala index aee5d23..5e6322e 100644 --- a/src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala +++ b/src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala @@ -1,15 +1,20 @@ package com.rallyhealth.sbt.semver.mima import com.rallyhealth.sbt.versioning.SemVerReleaseType +import com.typesafe.tools.mima.core.{Problem, ProblemFilter} import sbt.File -class MimaChecker(miMaExecutor: MiMaExecutor) { +class MimaChecker(miMaExecutor: MiMaExecutor, filters: Seq[ProblemFilter]) { + + private def applyFilter(problem: Problem): Boolean = { + filters.forall(filter => filter.apply(problem)) + } def compare(prev: File, curr: File): MiMaResult = { require(prev != curr, s"prev=$prev cannot equal curr=$curr") - val problemsBackwards = miMaExecutor.backwardProblems(prev, curr) - val problemsForwards = miMaExecutor.forwardProblems(prev, curr) + val problemsBackwards = miMaExecutor.backwardProblems(prev, curr).filter(applyFilter) + val problemsForwards = miMaExecutor.forwardProblems(prev, curr).filter(applyFilter) val backwards = problemsBackwards.map(problem => MiMaProblem(Direction.Backward, problem.description("current"))) val forwards = problemsForwards.map(problem => MiMaProblem(Direction.Forward, problem.description("previous"))) diff --git a/src/sbt-test/semver/filters/.gitignore b/src/sbt-test/semver/filters/.gitignore new file mode 100644 index 0000000..8484a46 --- /dev/null +++ b/src/sbt-test/semver/filters/.gitignore @@ -0,0 +1,19 @@ +### Scala template +*.class +*.log + +# sbt specific +.cache +.history +.lib/ +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ +global/ +pending* + +# RallyScriptedPlugin +scriptedOutput-* diff --git a/src/sbt-test/semver/filters/build.sbt b/src/sbt-test/semver/filters/build.sbt new file mode 100644 index 0000000..5ca7c34 --- /dev/null +++ b/src/sbt-test/semver/filters/build.sbt @@ -0,0 +1,11 @@ +import com.typesafe.tools.mima.core._ + +scalaVersion in ThisBuild := "2.11.12" + +organization in ThisBuild := "com.rallyhealth.test.scripted" + +logLevel := sbt.Level.Info + +enablePlugins(SemVerPlugin) + +mimaBinaryIssueFilters += ProblemFilters.exclude[Problem]("Thing") diff --git a/src/sbt-test/semver/filters/project/plugins.sbt b/src/sbt-test/semver/filters/project/plugins.sbt new file mode 100644 index 0000000..31095cf --- /dev/null +++ b/src/sbt-test/semver/filters/project/plugins.sbt @@ -0,0 +1,9 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin + ) + else addSbtPlugin("com.rallyhealth.sbt" % "sbt-git-versioning" % pluginVersion) +} diff --git a/src/sbt-test/semver/filters/src/main/scala/Thing.scala b/src/sbt-test/semver/filters/src/main/scala/Thing.scala new file mode 100644 index 0000000..b992730 --- /dev/null +++ b/src/sbt-test/semver/filters/src/main/scala/Thing.scala @@ -0,0 +1,4 @@ +class Thing { + + def foo: String = "foo" +} diff --git a/src/sbt-test/semver/filters/test b/src/sbt-test/semver/filters/test new file mode 100644 index 0000000..68344e0 --- /dev/null +++ b/src/sbt-test/semver/filters/test @@ -0,0 +1,18 @@ +# Set up a git repo appease GitVersioningPlugin and tag first version. +$ exec git init +$ exec git add . +$ exec git commit -am 'Initial commit.' +$ exec git tag v1.0.0 + +# Publish the first version so that SemVer will have a baseline to compare to. +> publishLocal + +# Introduce breaking change. It shouldn't care because it is filtered out. +$ exec git rm src/main/scala/Thing.scala +$ exec git commit -am 'Breaking change.' + +# Reload to have the new commit reflected in the version. Should be 1.0.1-1-hash-SNAPSHOT. +> reload + +# SemVerCheck should pass here. +> semVerCheck