Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Created October 9, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richdougherty/76f3d05ffabd80fcb04f6bf0776adc33 to your computer and use it in GitHub Desktop.
Save richdougherty/76f3d05ffabd80fcb04f6bf0776adc33 to your computer and use it in GitHub Desktop.
Example of custom ProblemFilter
mimaBinaryIssueFilters ++= {
def excludeSymbols[P <: ProblemRef](
name: String,
symbolFilter: String => Boolean)(
implicit problemTag: ClassTag[P]): ProblemFilter = {
{ problem: Problem =>
// Check the problem type
if (problemTag.runtimeClass.isAssignableFrom(problem.getClass)) {
// Check the problem name
problem.matchName.fold(false) { name: String =>
val split: Seq[String] = name.split('.')
val splitName = split.take(split.length - 1).mkString(".")
val splitSymbol = split(split.length - 1)
name == splitName && symbolFilter(splitSymbol)
}
} else false
}
}
val contentTypeConstants = Set("CACHE_MANIFEST", "JSON", "FORM", "BINARY")
val httpProtocolContants = Set("HTTP_1_0", "HTTP_1_1", "CHUNKED")
val controllerHelperConstants: Set[String] = contentTypeConstants ++ httpProtocolContants
val controllerHelperClasses: Seq[String] = Seq("play.api.mvc.ControllerHelpers", "controllers.ExternalAssets", "controllers.Default", "controllers.AssetsBuilder", "controllers.AbstractController")
val controllerHelperFilters: Seq[ProblemFilter] = controllerHelperClasses.map { className: String =>
excludeSymbols(className, controllerHelperConstants)
}
controllerHelperFilters ++ Seq(
excludeSymbols[DirectMissingMethodProblem]("play.api.http.ContentTypes", contentTypeConstants),
excludeSymbols[DirectMissingMethodProblem]("play.api.http.HttpProtocol", httpProtocolContants),
// Changing return and parameter types from DefaultApplicationLifecycle (implementation) to ApplicationLifecycle (trait)
ProblemFilters.exclude[IncompatibleResultTypeProblem]("play.api.BuiltInComponents.applicationLifecycle"),
ProblemFilters.exclude[IncompatibleResultTypeProblem
@mkurz
Copy link

mkurz commented Oct 14, 2019

The excludeSymbols method is not correct: It returns true when it should return false and vice versa. Correct would be:

      def excludeSymbols[P <: ProblemRef](
          name: String,
          symbolFilter: String => Boolean)(
          implicit problemTag: ClassTag[P]): ProblemFilter = {
        { problem: Problem =>
          // Check the problem type
          if (problemTag.runtimeClass.isAssignableFrom(problem.getClass)) {
            // Check the problem name
            problem.matchName.fold(false) { fullName: String =>
              val split: Seq[String] = fullName.split('.')
              val splitName = split.take(split.length - 1).mkString(".")
              val splitSymbol = split(split.length - 1)
              name != splitName || !symbolFilter(splitSymbol)
            }
          } else true
        }
      }

These is also how the ProblemFilters.exclude[...]("...") method works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment