From c7dcab75742eb3f5b18e109f3c4cedb7976caa1b Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Thu, 27 Sep 2018 14:09:45 +0200 Subject: [PATCH 1/2] Allow multiple exclude files per version to be loaded from a directory So, instead of creating a single mima-filters/10.1.5.backwards.excludes file to which everyone appends, you can now create a directory with the same name containing multiple exclude files per change like that: mima-filters/10.1.5.backwards.excludes/pr1234.excludes mima-filters/10.1.5.backwards.excludes/pr5678.excludes etc. This will prevent the common merge conflicts when everyone tries to append to the same file when in fact the ordering of entries is not interesting. --- .../typesafe/tools/mima/plugin/SbtMima.scala | 66 ++++++++++++------- .../build.sbt | 1 + .../project/plugins.sbt | 1 + .../a.excludes | 1 + .../b.excludes | 1 + .../c.excludes | 1 + .../src/main/scala/v1/A.scala | 6 ++ .../src/main/scala/v2/A.scala | 3 + .../test | 13 ++++ 9 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/build.sbt create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/project/plugins.sbt create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v1/A.scala create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v2/A.scala create mode 100644 sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/test diff --git a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala index 07bf2d4d..353cfb6a 100644 --- a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala +++ b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala @@ -1,6 +1,8 @@ package com.typesafe.tools.mima package plugin +import java.io.File + import com.typesafe.tools.mima.core._ import com.typesafe.tools.mima.core.util.log.Logging import sbt.Keys.TaskStreams @@ -119,32 +121,48 @@ object SbtMima { val ExclusionPattern = """ProblemFilters\.exclude\[([^\]]+)\]\("([^"]+)"\)""".r def findFiles(): Seq[(File, String)] = directory.listFiles().flatMap(f => fileExtension.findFirstIn(f.getName).map((f, _))) - def parseFile(file: File, extension: String): Either[Seq[Throwable], (String, Seq[ProblemFilter])] = { - val version = file.getName.dropRight(extension.size) - - def parseLine(text: String, line: Int): Try[ProblemFilter] = - Try { - text match { - case ExclusionPattern(className, target) => ProblemFilters.exclude(className, target) - case x => throw new RuntimeException(s"Couldn't parse '$x'") - } - }.transform(Success(_), ex => Failure(new ParsingException(file, line, ex))) - - val lines = try { - Source.fromFile(file).getLines().toVector - } catch { - case NonFatal(t) => throw new RuntimeException(s"Couldn't load '$file'", t) + def parseFile(fileOrDir: File, extension: String): Either[Seq[Throwable], (String, Seq[ProblemFilter])] = { + val version = fileOrDir.getName.dropRight(extension.size) + + def parseOneFile(file: File): Either[Seq[Throwable],Seq[ProblemFilter]] = { + def parseLine(text: String, line: Int): Try[ProblemFilter] = + Try { + text match { + case ExclusionPattern(className, target) => ProblemFilters.exclude(className, target) + case x => throw new RuntimeException(s"Couldn't parse '$x'") + } + }.transform(Success(_), ex => Failure(new ParsingException(file, line, ex))) + + val lines = try { + Source.fromFile(file).getLines().toVector + } catch { + case NonFatal(t) => throw new RuntimeException(s"Couldn't load '$file'", t) + } + + val (excludes, failures) = + lines + .zipWithIndex + .filterNot { case (str, line) => str.trim.isEmpty || str.trim.startsWith("#") } + .map((parseLine _).tupled) + .partition(_.isSuccess) + + if (failures.isEmpty) Right(excludes.map(_.get)) + else Left(failures.map(_.failed.get)) } - val (excludes, failures) = - lines - .zipWithIndex - .filterNot { case (str, line) => str.trim.isEmpty || str.trim.startsWith("#") } - .map((parseLine _).tupled) - .partition(_.isSuccess) - - if (failures.isEmpty) Right(version -> excludes.map(_.get)) - else Left(failures.map(_.failed.get)) + if (fileOrDir.isDirectory) { + val allResults = + fileOrDir.listFiles().filter(_.getName.endsWith(".excludes")) + .toSeq + .map(parseOneFile) + val (mappings, failures) = allResults.partition(_.isRight) + if (failures.nonEmpty) Left(failures.flatMap(_.left.get)) + else { + val allMappings = mappings.flatMap(_.right.get) + Right(version -> allMappings) + } + } else + parseOneFile(fileOrDir).right.map(version -> _) } require(directory.exists(), s"Mima filter directory did not exist: ${directory.getAbsolutePath}") diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/build.sbt b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/build.sbt new file mode 100644 index 00000000..2ab8eda7 --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/build.sbt @@ -0,0 +1 @@ +mimaPreviousArtifacts := Set(organization.value %% name.value % "0.0.1-SNAPSHOT") diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/project/plugins.sbt b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/project/plugins.sbt new file mode 100644 index 00000000..3a6fa8ab --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % System.getProperty("plugin.version")) diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes new file mode 100644 index 00000000..a3c631a3 --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes @@ -0,0 +1 @@ +ProblemFilters.exclude[MissingMethodProblem]("A.foz") \ No newline at end of file diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes new file mode 100644 index 00000000..64798497 --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes @@ -0,0 +1 @@ +ProblemFilters.exclude[MissingMethodProblem]("A.baz") \ No newline at end of file diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes new file mode 100644 index 00000000..fb4e6445 --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes @@ -0,0 +1 @@ +ProblemFilters.exclude[MissingMethodProblem]("A.bar") \ No newline at end of file diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v1/A.scala b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v1/A.scala new file mode 100644 index 00000000..1e2762d9 --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v1/A.scala @@ -0,0 +1,6 @@ +class A { + def foo = 1 + def bar = foo + def baz = foo + def foz = foo +} diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v2/A.scala b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v2/A.scala new file mode 100644 index 00000000..816b5a4e --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/scala/v2/A.scala @@ -0,0 +1,3 @@ +class A { + def foo = 1 +} diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/test b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/test new file mode 100644 index 00000000..0af9db4d --- /dev/null +++ b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/test @@ -0,0 +1,13 @@ +> set scalaSource in Compile := baseDirectory.value /"src" /"main" /"scala" /"v1" +> set version := s"0.0.1-SNAPSHOT" +> publishLocal + +> set scalaSource in Compile := baseDirectory.value /"src" /"main" /"scala" /"v2" +> set version := s"0.0.2-SNAPSHOT" + +# filters are read from file, so mima check should pass +> mimaReportBinaryIssues + +# remove all filters so mima check fails +> set mimaBackwardIssueFilters := Map.empty +-> mimaReportBinaryIssues From 983a511e23bbc671afb1d2103c7ab60f7278083e Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Thu, 4 Oct 2018 12:16:41 +0200 Subject: [PATCH 2/2] Take all files from exclusion directories --- .../src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala | 2 +- .../0.0.1-SNAPSHOT.backwards.excludes/{a.excludes => pr1234} | 0 .../0.0.1-SNAPSHOT.backwards.excludes/{b.excludes => pr5678} | 0 .../0.0.1-SNAPSHOT.backwards.excludes/{c.excludes => pr9012} | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/{a.excludes => pr1234} (100%) rename sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/{b.excludes => pr5678} (100%) rename sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/{c.excludes => pr9012} (100%) diff --git a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala index 353cfb6a..b466733a 100644 --- a/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala +++ b/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala @@ -152,7 +152,7 @@ object SbtMima { if (fileOrDir.isDirectory) { val allResults = - fileOrDir.listFiles().filter(_.getName.endsWith(".excludes")) + fileOrDir.listFiles() .toSeq .map(parseOneFile) val (mappings, failures) = allResults.partition(_.isRight) diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr1234 similarity index 100% rename from sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/a.excludes rename to sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr1234 diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr5678 similarity index 100% rename from sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/b.excludes rename to sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr5678 diff --git a/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes b/sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr9012 similarity index 100% rename from sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/c.excludes rename to sbtplugin/src/sbt-test/sbt-mima-plugin/backward-filters-from-dir-per-version/src/main/mima-filters/0.0.1-SNAPSHOT.backwards.excludes/pr9012