Skip to content

Commit 5290cfc

Browse files
authored
Merge pull request #17 from rtimush/mima-filters
Add support for mima problem filters
2 parents 6f68500 + deba943 commit 5290cfc

File tree

7 files changed

+70
-4
lines changed

7 files changed

+70
-4
lines changed

src/main/scala/com/rallyhealth/sbt/semver/SemVerPlugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ object SemVerPlugin extends AutoPlugin {
196196

197197
MiMa.miMaChecker := {
198198
val classpath = (fullClasspath in MimaKeys.mimaFindBinaryIssues).value
199-
new MimaChecker(MiMaExecutor(classpath, streams.value))
199+
new MimaChecker(MiMaExecutor(classpath, streams.value), MimaKeys.mimaBinaryIssueFilters.value)
200200
},
201201

202202
MiMa.moduleResolver := new IvyModuleResolver(scalaModuleInfo.value, ivySbt.value, streams.value),

src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package com.rallyhealth.sbt.semver.mima
22

33
import com.rallyhealth.sbt.versioning.SemVerReleaseType
4+
import com.typesafe.tools.mima.core.{Problem, ProblemFilter}
45
import sbt.File
56

6-
class MimaChecker(miMaExecutor: MiMaExecutor) {
7+
class MimaChecker(miMaExecutor: MiMaExecutor, filters: Seq[ProblemFilter]) {
8+
9+
private def applyFilter(problem: Problem): Boolean = {
10+
filters.forall(filter => filter.apply(problem))
11+
}
712

813
def compare(prev: File, curr: File): MiMaResult = {
914
require(prev != curr, s"prev=$prev cannot equal curr=$curr")
1015

11-
val problemsBackwards = miMaExecutor.backwardProblems(prev, curr)
12-
val problemsForwards = miMaExecutor.forwardProblems(prev, curr)
16+
val problemsBackwards = miMaExecutor.backwardProblems(prev, curr).filter(applyFilter)
17+
val problemsForwards = miMaExecutor.forwardProblems(prev, curr).filter(applyFilter)
1318

1419
val backwards = problemsBackwards.map(problem => MiMaProblem(Direction.Backward, problem.description("current")))
1520
val forwards = problemsForwards.map(problem => MiMaProblem(Direction.Forward, problem.description("previous")))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Scala template
2+
*.class
3+
*.log
4+
5+
# sbt specific
6+
.cache
7+
.history
8+
.lib/
9+
dist/*
10+
target/
11+
lib_managed/
12+
src_managed/
13+
project/boot/
14+
project/plugins/project/
15+
global/
16+
pending*
17+
18+
# RallyScriptedPlugin
19+
scriptedOutput-*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import com.typesafe.tools.mima.core._
2+
3+
scalaVersion in ThisBuild := "2.11.12"
4+
5+
organization in ThisBuild := "com.rallyhealth.test.scripted"
6+
7+
logLevel := sbt.Level.Info
8+
9+
enablePlugins(SemVerPlugin)
10+
11+
mimaBinaryIssueFilters += ProblemFilters.exclude[Problem]("Thing")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
val pluginVersion = System.getProperty("plugin.version")
3+
if (pluginVersion == null)
4+
throw new RuntimeException(
5+
"""|The system property 'plugin.version' is not defined.
6+
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
7+
)
8+
else addSbtPlugin("com.rallyhealth.sbt" % "sbt-git-versioning" % pluginVersion)
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Thing {
2+
3+
def foo: String = "foo"
4+
}

src/sbt-test/semver/filters/test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Set up a git repo appease GitVersioningPlugin and tag first version.
2+
$ exec git init
3+
$ exec git add .
4+
$ exec git commit -am 'Initial commit.'
5+
$ exec git tag v1.0.0
6+
7+
# Publish the first version so that SemVer will have a baseline to compare to.
8+
> publishLocal
9+
10+
# Introduce breaking change. It shouldn't care because it is filtered out.
11+
$ exec git rm src/main/scala/Thing.scala
12+
$ exec git commit -am 'Breaking change.'
13+
14+
# Reload to have the new commit reflected in the version. Should be 1.0.1-1-hash-SNAPSHOT.
15+
> reload
16+
17+
# SemVerCheck should pass here.
18+
> semVerCheck

0 commit comments

Comments
 (0)