Skip to content

Commit

Permalink
Merge pull request #17 from rtimush/mima-filters
Browse files Browse the repository at this point in the history
Add support for mima problem filters
  • Loading branch information
jeffmay authored Mar 5, 2020
2 parents 6f68500 + deba943 commit 5290cfc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 8 additions & 3 deletions src/main/scala/com/rallyhealth/sbt/semver/mima/MimaChecker.scala
Original file line number Diff line number Diff line change
@@ -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")))
Expand Down
19 changes: 19 additions & 0 deletions src/sbt-test/semver/filters/.gitignore
Original file line number Diff line number Diff line change
@@ -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-*
11 changes: 11 additions & 0 deletions src/sbt-test/semver/filters/build.sbt
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions src/sbt-test/semver/filters/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions src/sbt-test/semver/filters/src/main/scala/Thing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Thing {

def foo: String = "foo"
}
18 changes: 18 additions & 0 deletions src/sbt-test/semver/filters/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5290cfc

Please sign in to comment.