diff --git a/core/src/main/scala/com/typesafe/tools/mima/core/Filters.scala b/core/src/main/scala/com/typesafe/tools/mima/core/Filters.scala index 7f2007ef..769a2e8d 100644 --- a/core/src/main/scala/com/typesafe/tools/mima/core/Filters.scala +++ b/core/src/main/scala/com/typesafe/tools/mima/core/Filters.scala @@ -1,12 +1,14 @@ package com.typesafe.tools.mima.core import scala.reflect.ClassTag +import sbt.io.GlobFilter object ProblemFilters { private case class ExcludeByName[P <: ProblemRef: ClassTag](name: String) extends ProblemFilter { + private[this] val glob = GlobFilter(name) override def apply(problem: Problem): Boolean = { !(implicitly[ClassTag[P]].runtimeClass.isAssignableFrom(problem.getClass) && - Some(name) == problem.matchName) + glob.accept(problem.matchName.getOrElse(""))) } override def toString(): String = """ExcludeByName[%s]("%s")""".format(implicitly[ClassTag[P]].runtimeClass.getSimpleName, name) @@ -27,13 +29,4 @@ object ProblemFilters { val problemClass: Class[_ <: ProblemRef] = Class.forName("com.typesafe.tools.mima.core." + problemName).asInstanceOf[Class[_ <: ProblemRef]] exclude(name)(ClassTag(problemClass)) } - - private case class ExcludeByPackage(excludedPackageName: String) extends ProblemFilter { - def apply(problem: Problem): Boolean = { - // careful to avoid excluding "com.foobar" with an exclusion "com.foo" - !problem.matchName.getOrElse("").startsWith(excludedPackageName + ".") - } - } - - def excludePackage(packageName: String): ProblemFilter = new ExcludeByPackage(packageName) } diff --git a/core/src/test/scala/com/typesafe/tools/mima/core/ProblemFiltersSpec.scala b/core/src/test/scala/com/typesafe/tools/mima/core/ProblemFiltersSpec.scala new file mode 100644 index 00000000..aff43fbd --- /dev/null +++ b/core/src/test/scala/com/typesafe/tools/mima/core/ProblemFiltersSpec.scala @@ -0,0 +1,34 @@ +package com.typesafe.tools.mima.core + +import org.scalatest._ +import org.scalatest.prop.TableDrivenPropertyChecks + +class ProblemFiltersSpec extends WordSpec with TableDrivenPropertyChecks with Matchers { + import ProblemFiltersSpec._ + + val filters = Table( + ("filter", "problem", "realProblem"), + (ProblemFilters.exclude[Problem]("impl.Http"), problem("impl.Http"), false), + (ProblemFilters.exclude[Problem]("impl.Http"), problem("impl.Http2"), true), + (ProblemFilters.exclude[Problem]("impl.*"), problem("impl.Http"), false), + (ProblemFilters.exclude[Problem]("impl.*"), problem("impl2.Http"), true), + (ProblemFilters.exclude[Problem]("a$Impl*"), problem("a$Impl$B"), false), + (ProblemFilters.exclude[Problem]("a$Impl*"), problem("a2$Impl$B"), true) + ) + + "problem filters" should { + "filter problems" in { + forAll (filters) { (filter, problem, realProblem) => + filter(problem) shouldBe realProblem + } + } + } + +} + +object ProblemFiltersSpec { + def problem(name: String) = new TemplateProblem(NoClass) { + override def description: (String) => String = ??? + override def matchName: Some[String] = Some(name) + } +} diff --git a/project/Build.scala b/project/Build.scala index 126d7c38..eb2b5fa0 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -77,6 +77,8 @@ object Dependencies { import BuildSettings._ val typesafeConfig = "com.typesafe" % "config" % "1.0.0" + val sbtIo = "org.scala-sbt" %% "io" % "1.0.0-M11" + val scalatest = "org.scalatest" %% "scalatest" % "3.0.1" % Test } @@ -104,7 +106,11 @@ object MimaBuild { buildInfoObject := "BuildInfo" ) ) - settings(libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value, + settings(libraryDependencies ++= Seq( + "org.scala-lang" % "scala-compiler" % scalaVersion.value, + sbtIo, + scalatest + ), name := buildName + "-core") settings(sonatypePublishSettings:_*) ) diff --git a/reporter/functional-tests/src/main/scala/com/typesafe/tools/mima/lib/CollectProblemsTest.scala b/reporter/functional-tests/src/main/scala/com/typesafe/tools/mima/lib/CollectProblemsTest.scala index ad7b547c..b54ee6b6 100644 --- a/reporter/functional-tests/src/main/scala/com/typesafe/tools/mima/lib/CollectProblemsTest.scala +++ b/reporter/functional-tests/src/main/scala/com/typesafe/tools/mima/lib/CollectProblemsTest.scala @@ -26,7 +26,7 @@ class CollectProblemsTest { val allProblems = mima.collectProblems(oldJarPath, newJarPath) val problems = (if(filterPath ne null) { - val fallback = ConfigFactory.parseString("filter { problems = []\npackages=[] }") + val fallback = ConfigFactory.parseString("filter { problems = [] }") val config = ConfigFactory.parseFile(new File(filterPath)).withFallback(fallback).resolve() val filters = ProblemFiltersConfig.parseProblemFilters(config) allProblems.filter(p => filters.forall(_.apply(p))) diff --git a/reporter/src/main/scala/com/typesafe/tools/mima/cli/ProblemFiltersConfig.scala b/reporter/src/main/scala/com/typesafe/tools/mima/cli/ProblemFiltersConfig.scala index a8aca4af..02c0d203 100644 --- a/reporter/src/main/scala/com/typesafe/tools/mima/cli/ProblemFiltersConfig.scala +++ b/reporter/src/main/scala/com/typesafe/tools/mima/cli/ProblemFiltersConfig.scala @@ -7,7 +7,6 @@ import scala.collection.JavaConverters._ object ProblemFiltersConfig { private val filterProblemsPath = "filter.problems" - private val filterPackagesPath = "filter.packages" private val problemNameKey = "problemName" private val matchNameKey = "matchName" @@ -20,16 +19,11 @@ object ProblemFiltersConfig { */ def parseProblemFilters(config: Config): Seq[ProblemFilter] = { val filters = config.getConfigList(filterProblemsPath).asScala.toSeq - val individualFilter = for (problemConfig <- filters) yield { + for (problemConfig <- filters) yield { val problemClassName = problemConfig.getString(problemNameKey) val matchName = problemConfig.getString(matchNameKey) ProblemFilters.exclude(problemClassName, matchName) } - val packages = config.getStringList(filterPackagesPath).asScala.toSeq - val packageFilter = for (pack <- packages) yield { - ProblemFilters.excludePackage(pack) - } - individualFilter ++ packageFilter } /**