Skip to content

Commit

Permalink
Merge pull request #503 from raboof/allow-calling-SbtMima-from-other-…
Browse files Browse the repository at this point in the history
…sbt-plugins
  • Loading branch information
dwijnand authored May 18, 2020
2 parents c2a9193 + 38cab26 commit ce0b075
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object MimaPlugin extends AutoPlugin {

override def projectSettings: Seq[Def.Setting[_]] = Seq(
mimaReportBinaryIssues := {
val log = new SbtLogger(streams.value)
binaryIssuesIterator.value.foreach { case (moduleId, problems) =>
SbtMima.reportModuleErrors(
moduleId,
Expand All @@ -34,7 +33,7 @@ object MimaPlugin extends AutoPlugin {
binaryIssueFilters.value,
mimaBackwardIssueFilters.value,
mimaForwardIssueFilters.value,
log,
streams.value.log,
name.value,
)
}
Expand Down Expand Up @@ -78,7 +77,6 @@ object MimaPlugin extends AutoPlugin {
val currentClassfiles = mimaCurrentClassfiles.value
val cp = (fullClasspath in mimaFindBinaryIssues).value
val sv = scalaVersion.value
val log = new SbtLogger(s)

if (previousClassfiles eq NoPreviousClassfiles) {
val msg = "mimaPreviousArtifacts not set, not analyzing binary compatibility"
Expand All @@ -88,7 +86,7 @@ object MimaPlugin extends AutoPlugin {
}

previousClassfiles.iterator.map { case (moduleId, prevClassfiles) =>
moduleId -> SbtMima.runMima(prevClassfiles, currentClassfiles, cp, mimaCheckDirection.value, sv, log)
moduleId -> SbtMima.runMima(prevClassfiles, currentClassfiles, cp, mimaCheckDirection.value, sv, s.log)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.typesafe.tools.mima
package plugin

import com.typesafe.tools.mima.core.util.log.Logging
import sbt.Keys._
import sbt.Logger

/** Wrapper on sbt logging for MiMa. */
private[plugin] final class SbtLogger(s: TaskStreams) extends Logging {
def verbose(msg: String): Unit = s.log.verbose(msg)
def debug(msg: String): Unit = s.log.debug(msg)
def warn(msg: String): Unit = s.log.warn(msg)
def error(msg: String): Unit = s.log.error(msg)
private[plugin] final class SbtLogger(log: Logger) extends Logging {
def verbose(msg: String): Unit = log.verbose(msg)
def debug(msg: String): Unit = log.debug(msg)
def warn(msg: String): Unit = log.warn(msg)
def error(msg: String): Unit = log.error(msg)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package plugin
import java.io.File

import com.typesafe.tools.mima.core._
import com.typesafe.tools.mima.core.util.log.Logging
import com.typesafe.tools.mima.lib.MiMaLib
import sbt._
import sbt.Keys.{ Classpath, TaskStreams }
Expand All @@ -21,7 +20,8 @@ import scala.util.matching._
object SbtMima {
/** Runs MiMa and returns a two lists of potential binary incompatibilities,
the first for backward compatibility checking, and the second for forward checking. */
def runMima(prev: File, curr: File, cp: Classpath, dir: String, scalaVersion: String, log: Logging): (List[Problem], List[Problem]) = {
def runMima(prev: File, curr: File, cp: Classpath, dir: String, scalaVersion: String, logger: Logger): (List[Problem], List[Problem]) = {
val log = new SbtLogger(logger)
sanityCheckScalaVersion(scalaVersion)
val mimaLib = new MiMaLib(Attributed.data(cp), log)
def checkBC = mimaLib.collectProblems(prev, curr)
Expand Down Expand Up @@ -50,11 +50,12 @@ object SbtMima {
filters: Seq[ProblemFilter],
backwardFilters: Map[String, Seq[ProblemFilter]],
forwardFilters: Map[String, Seq[ProblemFilter]],
log: Logging,
logger: Logger,
projectName: String,
): Unit = {
// filters * found is n-squared, it's fixable in principle by special-casing known
// filter types or something, not worth it most likely...
val log = new SbtLogger(logger)

def isReported(versionedFilters: Map[String, Seq[ProblemFilter]])(problem: Problem) = {
ProblemReporting.isReported(module.revision, filters, versionedFilters)(problem)
Expand Down

0 comments on commit ce0b075

Please sign in to comment.