Skip to content

Commit a2e952a

Browse files
authored
Merge pull request #878 from eed3si9n/wip/bump
Cross build to sbt 2.x
2 parents 0e2fefa + fd9be26 commit a2e952a

File tree

21 files changed

+191
-94
lines changed

21 files changed

+191
-94
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: ci
33
on:
44
pull_request:
55
push:
6-
branches: ['main']
7-
tags: ['[0-9]']
86

97
jobs:
108
build:
@@ -14,15 +12,15 @@ jobs:
1412
java: [8, 11, 17]
1513
runs-on: ubuntu-latest
1614
steps:
17-
- uses: actions/checkout@v2
18-
- uses: actions/setup-java@v2
15+
- uses: actions/checkout@v5
16+
- uses: actions/setup-java@v5
1917
with:
2018
distribution: temurin
2119
java-version: ${{matrix.java}}
22-
- uses: coursier/cache-action@v6
20+
cache: sbt
2321
- uses: sbt/setup-sbt@v1
2422
# note use of an old sbt version, as a smoke test
25-
- run: "sbt +test mimaReportBinaryIssues 'set sbtplugin/scriptedSbt := \"1.3.13\"' 'scripted sbt-mima-plugin/minimal'"
23+
- run: "sbt +test mimaReportBinaryIssues 'set sbtplugin/scriptedSbt := \"1.5.8\"' 'scripted sbt-mima-plugin/minimal'"
2624
testFunctional:
2725
needs: build
2826
strategy:
@@ -31,39 +29,39 @@ jobs:
3129
scala: [2.11, 2.12, 2.13, 3]
3230
runs-on: ubuntu-latest
3331
steps:
34-
- uses: actions/checkout@v2
35-
- uses: actions/setup-java@v2
32+
- uses: actions/checkout@v5
33+
- uses: actions/setup-java@v5
3634
with:
37-
distribution: temurin
35+
distribution: zulu
3836
java-version: 8
37+
cache: sbt
3938
- uses: sbt/setup-sbt@v1
40-
- uses: coursier/cache-action@v6
4139
- run: sbt "functional-tests/runMain com.typesafe.tools.mima.lib.UnitTests -${{ matrix.scala }}"
4240
testScripted:
4341
needs: build
4442
strategy:
4543
fail-fast: false
4644
matrix:
47-
scripted: [1of2, 2of2]
45+
scala: [2.12.x, 3.x]
4846
runs-on: ubuntu-latest
4947
steps:
50-
- uses: actions/checkout@v2
51-
- uses: actions/setup-java@v2
48+
- uses: actions/checkout@v5
49+
- uses: actions/setup-java@v5
5250
with:
53-
distribution: temurin
51+
distribution: zulu
5452
java-version: 8
55-
- uses: coursier/cache-action@v6
53+
cache: sbt
5654
- uses: sbt/setup-sbt@v1
57-
- run: sbt "scripted sbt-mima-plugin/*${{ matrix.scripted }}"
55+
- run: sbt "++${{ matrix.scala }} sbtplugin/scripted"
5856
testIntegration:
5957
needs: build
6058
runs-on: ubuntu-latest
6159
steps:
62-
- uses: actions/checkout@v2
63-
- uses: actions/setup-java@v2
60+
- uses: actions/checkout@v5
61+
- uses: actions/setup-java@v5
6462
with:
65-
distribution: temurin
63+
distribution: zulu
6664
java-version: 8
67-
- uses: coursier/cache-action@v6
65+
cache: sbt
6866
- uses: sbt/setup-sbt@v1
6967
- run: sbt IntegrationTest/test

build.sbt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import mimabuild._
22

33
inThisBuild(Seq(
44
organization := "com.typesafe",
5-
licenses := Seq("Apache License v2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
5+
licenses := Seq(License.Apache2),
66
homepage := Some(url("http://github.com/lightbend-labs/mima")),
77
developers := List(
88
Developer("mdotta", "Mirco Dotta", "@dotta", url("https://github.com/dotta")),
@@ -14,7 +14,11 @@ inThisBuild(Seq(
1414
versionScheme := Some("early-semver"),
1515
scalaVersion := scala212,
1616
resolvers ++= (if (isStaging) List(stagingResolver) else Nil),
17-
publishTo := Some(if (isSnapshot.value) Opts.resolver.sonatypeOssSnapshots.head else Opts.resolver.sonatypeStaging),
17+
publishTo := {
18+
val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/"
19+
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
20+
else localStaging.value
21+
},
1822
))
1923

2024
def compilerOptions(scalaVersion: String): Seq[String] =
@@ -49,6 +53,7 @@ commands += Command.command("testStaging") { state =>
4953
val scala212 = "2.12.20"
5054
val scala213 = "2.13.16"
5155
val scala3 = "3.3.6"
56+
val scala3_7 = "3.7.2"
5257

5358
val root = project.in(file(".")).settings(
5459
name := "mima",
@@ -94,6 +99,13 @@ val cli = crossProject(JVMPlatform)
9499

95100
val sbtplugin = project.enablePlugins(SbtPlugin).dependsOn(core.jvm).settings(
96101
name := "sbt-mima-plugin",
102+
crossScalaVersions ++= Seq(scala3_7),
103+
(pluginCrossBuild / sbtVersion) := {
104+
scalaBinaryVersion.value match {
105+
case "2.12" => "1.5.8"
106+
case _ => "2.0.0-RC3"
107+
}
108+
},
97109
scalacOptions ++= compilerOptions(scalaVersion.value),
98110
// drop the previous value to drop running Test/compile
99111
scriptedDependencies := Def.task(()).dependsOn(publishLocal, core.jvm / publishLocal).value,

project/MimaSettings.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ object MimaSettings {
2424
// * com.typesafe.tools.mima.core.ProblemFilters
2525
// * com.typesafe.tools.mima.core.*Problem
2626
// * com.typesafe.tools.mima.core.util.log.Logging
27+
exclude[MissingClassProblem]("com.typesafe.tools.mima.plugin.MimaPlugin$EmptyMap"),
28+
exclude[MissingClassProblem]("com.typesafe.tools.mima.plugin.MimaPlugin$EmptySet"),
29+
exclude[MissingClassProblem]("com.typesafe.tools.mima.plugin.MimaPlugin$NoPreviousArtifacts$"),
30+
exclude[MissingClassProblem]("com.typesafe.tools.mima.plugin.MimaPlugin$NoPreviousClassfiles$"),
2731
),
2832
)
2933
}

project/plugins.sbt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ scalacOptions ++= Seq(
66
"-Ywarn-unused:_,-imports",
77
)
88

9-
// Useful to self-test releases
10-
val stagingResolver = "Sonatype OSS Staging" at "https://oss.sonatype.org/content/repositories/staging"
11-
def isStaging = sys.props.contains("mimabuild.staging")
12-
resolvers ++= (if (isStaging) List(stagingResolver) else Nil)
13-
149
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")
1510
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
1611
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.typesafe.tools.mima
2+
package plugin
3+
4+
import sbt.*
5+
6+
object PluginCompat {
7+
def toOldClasspath(cp: Seq[Attributed[File]]): Seq[Attributed[File]] = cp
8+
9+
// This adds `Def.uncached(...)`
10+
implicit class DefOp(singleton: Def.type) {
11+
def uncached[A1](a: A1): A1 = a
12+
}
13+
14+
// Used to differentiate unset mimaPreviousArtifacts from empty mimaPreviousArtifacts
15+
private[plugin] object NoPreviousArtifacts extends EmptySet[ModuleID]
16+
private[plugin] object NoPreviousClassfiles extends EmptyMap[ModuleID, File]
17+
18+
private[plugin] sealed class EmptySet[A] extends Set[A] {
19+
def iterator = Iterator.empty
20+
def contains(elem: A) = false
21+
def + (elem: A) = Set(elem)
22+
def - (elem: A) = this
23+
override def size = 0
24+
override def foreach[U](f: A => U) = ()
25+
override def toSet[B >: A]: Set[B] = this.asInstanceOf[Set[B]]
26+
}
27+
28+
private[plugin] sealed class EmptyMap[K, V] extends Map[K, V] {
29+
def get(key: K) = None
30+
def iterator = Iterator.empty
31+
def + [V1 >: V](kv: (K, V1)) = updated(kv._1, kv._2)
32+
def - (key: K) = this
33+
34+
override def size = 0
35+
override def contains(key: K) = false
36+
override def getOrElse[V1 >: V](key: K, default: => V1) = default
37+
override def updated[V1 >: V](key: K, value: V1) = Map(key -> value)
38+
39+
override def apply(key: K) = throw new NoSuchElementException(s"key not found: $key")
40+
}
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.typesafe.tools.mima
2+
package plugin
3+
4+
import sbt.*
5+
import xsbti.{ FileConverter, HashedVirtualFileRef }
6+
7+
object PluginCompat:
8+
inline def toOldClasspath(cp: Seq[Attributed[HashedVirtualFileRef]])(using conv: FileConverter): Seq[Attributed[File]] =
9+
cp.map(_.map(x => conv.toPath(x).toFile))
10+
11+
// Used to differentiate unset mimaPreviousArtifacts from empty mimaPreviousArtifacts
12+
private[plugin] object NoPreviousArtifacts extends EmptySet[ModuleID]
13+
private[plugin] object NoPreviousClassfiles extends EmptyMap[ModuleID, File]
14+
15+
private[plugin] sealed class EmptySet[A] extends Set[A]:
16+
def iterator = Iterator.empty
17+
def contains(elem: A) = false
18+
def excl(elem: A) = this
19+
def incl(elem: A) = Set(elem)
20+
21+
override def size = 0
22+
override def foreach[U](f: A => U) = ()
23+
override def toSet[B >: A]: Set[B] = this.asInstanceOf[Set[B]]
24+
25+
private[plugin] sealed class EmptyMap[K, V] extends Map[K, V]:
26+
def get(key: K) = None
27+
def iterator = Iterator.empty
28+
def removed(key: K) = this
29+
30+
override def size = 0
31+
override def contains(key: K) = false
32+
override def getOrElse[V1 >: V](key: K, default: => V1) = default
33+
override def updated[V1 >: V](key: K, value: V1) = Map(key -> value)
34+
35+
override def apply(key: K) = throw new NoSuchElementException(s"key not found: $key")
36+
end PluginCompat

sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaKeys.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,39 @@ object MimaKeys extends MimaKeys
1010
class MimaKeys {
1111

1212
final val mimaPreviousArtifacts = settingKey[Set[ModuleID]]("Previous released artifacts used to test binary compatibility.")
13+
14+
@transient
1315
final val mimaReportBinaryIssues = taskKey[Unit]("Logs all binary incompatibilities to the sbt console/logs.")
1416
final val mimaExcludeAnnotations = settingKey[Seq[String]]("The fully-qualified class names of annotations that exclude problems")
17+
18+
@transient
1519
final val mimaBinaryIssueFilters = taskKey[Seq[ProblemFilter]]("Filters to apply to binary issues found. Applies both to backward and forward binary compatibility checking.")
1620
final val mimaFailOnProblem = settingKey[Boolean]("if true, fail the build on binary incompatibility detection.")
1721
final val mimaFailOnNoPrevious = settingKey[Boolean]("if true, fail the build if no previous artifacts are set.")
1822
final val mimaReportSignatureProblems = settingKey[Boolean]("if true, report `IncompatibleSignatureProblem`s.")
1923

24+
@transient
2025
final val mimaDependencyResolution = taskKey[DependencyResolution]("DependencyResolution to use to fetch previous artifacts.")
26+
27+
@transient
2128
final val mimaPreviousClassfiles = taskKey[Map[ModuleID, File]]("Directories or jars containing the previous class files used to test compatibility with a given module.")
29+
30+
@transient
2231
final val mimaCurrentClassfiles = taskKey[File]("Directory or jar containing the current class files used to test compatibility.")
32+
33+
@transient
2334
final val mimaCheckDirection = settingKey[String]("Compatibility checking direction; default is \"backward\", but can also be \"forward\" or \"both\".")
35+
36+
@transient
2437
final val mimaFindBinaryIssues = taskKey[Map[ModuleID, (List[Problem], List[Problem])]]("All backward and forward binary incompatibilities between a given module and current project.")
38+
39+
@transient
2540
final val mimaBackwardIssueFilters = taskKey[Map[String, Seq[ProblemFilter]]]("Filters to apply to binary issues found grouped by version of a module checked against. These filters only apply to backward compatibility checking.")
41+
42+
@transient
2643
final val mimaForwardIssueFilters = taskKey[Map[String, Seq[ProblemFilter]]]("Filters to apply to binary issues found grouped by version of a module checked against. These filters only apply to forward compatibility checking.")
44+
45+
@transient
2746
final val mimaFiltersDirectory = settingKey[File]("Directory containing issue filters.")
2847

2948
}

sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/MimaPlugin.scala

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ package plugin
33

44
import sbt.*, Keys.*
55
import core.*
6+
import PluginCompat.*
7+
import xsbti.FileConverter
8+
import scala.annotation.nowarn
69

710
/** MiMa's sbt plugin. */
811
object MimaPlugin extends AutoPlugin {
912
override def trigger = allRequirements
1013

14+
private val NoPreviousArtifacts = PluginCompat.NoPreviousArtifacts
15+
private val NoPreviousClassfiles = PluginCompat.NoPreviousClassfiles
16+
1117
object autoImport extends MimaKeys
1218
import autoImport.*
1319

14-
override def globalSettings: Seq[Def.Setting[_]] = Seq(
20+
override def globalSettings: Seq[Def.Setting[?]] = Seq(
1521
mimaPreviousArtifacts := NoPreviousArtifacts,
1622
mimaExcludeAnnotations := Nil,
1723
mimaBinaryIssueFilters := Nil,
@@ -21,7 +27,7 @@ object MimaPlugin extends AutoPlugin {
2127
mimaCheckDirection := "backward",
2228
)
2329

24-
override def projectSettings: Seq[Def.Setting[_]] = Seq(
30+
override def projectSettings: Seq[Def.Setting[?]] = Seq(
2531
mimaReportBinaryIssues := {
2632
binaryIssuesIterator.value.foreach { case (moduleId, problems) =>
2733
SbtMima.reportModuleErrors(
@@ -43,14 +49,14 @@ object MimaPlugin extends AutoPlugin {
4349
},
4450
mimaCurrentClassfiles := (Compile / classDirectory).value,
4551
mimaFindBinaryIssues := binaryIssuesIterator.value.toMap,
46-
mimaFindBinaryIssues / fullClasspath := (Compile / fullClasspath).value,
52+
mimaFindBinaryIssues / fullClasspath := Def.uncached((Compile / fullClasspath).value),
4753
mimaBackwardIssueFilters := SbtMima.issueFiltersFromFiles(mimaFiltersDirectory.value, "\\.(?:backward[s]?|both)\\.excludes".r, streams.value),
4854
mimaForwardIssueFilters := SbtMima.issueFiltersFromFiles(mimaFiltersDirectory.value, "\\.(?:forward[s]?|both)\\.excludes".r, streams.value),
4955
mimaFiltersDirectory := (Compile / sourceDirectory).value / "mima-filters",
5056
)
5157

5258
@deprecated("Switch to enablePlugins(MimaPlugin)", "0.7.0")
53-
def mimaDefaultSettings: Seq[Setting[_]] = globalSettings ++ buildSettings ++ projectSettings
59+
def mimaDefaultSettings: Seq[Setting[?]] = globalSettings ++ buildSettings ++ projectSettings
5460

5561
trait ArtifactsToClassfiles {
5662
def toClassfiles(previousArtifacts: Set[ModuleID]): Map[ModuleID, File]
@@ -86,6 +92,9 @@ object MimaPlugin extends AutoPlugin {
8692
val excludeAnnots = mimaExcludeAnnotations.value.toList
8793
val failOnNoPrevious = mimaFailOnNoPrevious.value
8894
val projName = name.value
95+
val conv0 = fileConverter.value
96+
@nowarn
97+
implicit val conv: FileConverter = conv0
8998

9099
(prevClassfiles, checkDirection) => {
91100
if (prevClassfiles eq NoPreviousClassfiles) {
@@ -96,7 +105,15 @@ object MimaPlugin extends AutoPlugin {
96105
}
97106

98107
prevClassfiles.iterator.map { case (moduleId, prevClassfiles) =>
99-
moduleId -> SbtMima.runMima(prevClassfiles, currClassfiles, cp, checkDirection, sv, log, excludeAnnots)
108+
moduleId -> SbtMima.runMima(
109+
prevClassfiles,
110+
currClassfiles,
111+
toOldClasspath(cp),
112+
checkDirection,
113+
sv,
114+
log,
115+
excludeAnnots
116+
)
100117
}
101118
}
102119
}
@@ -111,33 +128,4 @@ object MimaPlugin extends AutoPlugin {
111128
private val binaryIssuesIterator = Def.task {
112129
binaryIssuesFinder.value.runMima(mimaPreviousClassfiles.value, mimaCheckDirection.value)
113130
}
114-
115-
// Used to differentiate unset mimaPreviousArtifacts from empty mimaPreviousArtifacts
116-
private object NoPreviousArtifacts extends EmptySet[ModuleID]
117-
private object NoPreviousClassfiles extends EmptyMap[ModuleID, File]
118-
119-
private sealed class EmptySet[A] extends Set[A] {
120-
def iterator = Iterator.empty
121-
def contains(elem: A) = false
122-
def + (elem: A) = Set(elem)
123-
def - (elem: A) = this
124-
125-
override def size = 0
126-
override def foreach[U](f: A => U) = ()
127-
override def toSet[B >: A]: Set[B] = this.asInstanceOf[Set[B]]
128-
}
129-
130-
private sealed class EmptyMap[K, V] extends Map[K, V] {
131-
def get(key: K) = None
132-
def iterator = Iterator.empty
133-
def + [V1 >: V](kv: (K, V1)) = updated(kv._1, kv._2)
134-
def - (key: K) = this
135-
136-
override def size = 0
137-
override def contains(key: K) = false
138-
override def getOrElse[V1 >: V](key: K, default: => V1) = default
139-
override def updated[V1 >: V](key: K, value: V1) = Map(key -> value)
140-
141-
override def apply(key: K) = throw new NoSuchElementException(s"key not found: $key")
142-
}
143131
}

0 commit comments

Comments
 (0)