Skip to content

Commit

Permalink
Merge pull request #713 from dwijnand/honour-owners
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Aug 3, 2022
2 parents 295754c + f413193 commit f353ee3
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inThisBuild(Seq(
scalaVersion := scala212,
scalacOptions ++= Seq("-feature", "-Xsource:3", "-Xlint", "-Wconf:cat=deprecation&msg=Stream|JavaConverters:s"),
resolvers ++= (if (isStaging) List(stagingResolver) else Nil),
publishTo := Some(if (isSnapshot.value) Opts.resolver.sonatypeSnapshots else Opts.resolver.sonatypeStaging),
publishTo := Some(if (isSnapshot.value) Opts.resolver.sonatypeOssSnapshots.head else Opts.resolver.sonatypeStaging),
))

// Useful to self-test releases
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/scala/com/typesafe/tools/mima/core/ClassInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private[mima] sealed abstract class ClassInfo(val owner: PackageInfo) extends In
final def isScopedPrivate: Boolean = afterLoading(_scopedPrivate)
final def annotations: List[AnnotInfo] = afterLoading(_annotations)
final def implClass: ClassInfo = { owner.setImplClasses; _implClass } // returns NoClass if this is not a trait
final def moduleClass: ClassInfo = { owner.setModules; if (_moduleClass == NoClass) this else _moduleClass }
final def module: ClassInfo = { owner.setModules; if (_module == NoClass) this else _module }
final def moduleClass: ClassInfo = { owner.setModules; if (_moduleClass == NoClass || _moduleClass == null) this else _moduleClass }
final def module: ClassInfo = { owner.setModules; if (_module == NoClass || _module == null) this else _module }

final def isTrait: Boolean = implClass ne NoClass // trait with some concrete methods or fields
final def isModuleClass: Boolean = bytecodeName.endsWith("$") // super scuffed
Expand All @@ -95,6 +95,18 @@ private[mima] sealed abstract class ClassInfo(val owner: PackageInfo) extends In
final def description: String = s"$declarationPrefix $formattedFullName"
final def classString: String = s"$accessModifier $description".trim

def outerChain: Iterator[ClassInfo] = Iterator.iterate(this)(_.outer).takeWhile(_ != NoClass)

lazy val outer: ClassInfo = {
val idx = bytecodeName.stripSuffix("$").lastIndexOf('$')
if (idx != -1) {
val outerName = bytecodeName.substring(0, idx)
owner.classes.getOrElse(outerName,
owner.classes.getOrElse(s"$outerName$$",
NoClass))
} else NoClass
}

lazy val superClasses: Set[ClassInfo] = {
if (this == ClassInfo.ObjectClass) Set.empty
else superClass.superClasses + superClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ object Analyzer {
// if it is missing a trait implementation class, then no error should be reported
// since there should be already errors, i.e., missing methods...
if !oldclazz.isImplClass
if !excludeAnnots.exists(oldclazz.annotations.contains)
if !excludeAnnots.exists { annot =>
oldclazz.outerChain.exists { cls =>
cls.annotations.contains(annot) ||
cls.module.annotations.contains(annot) ||
cls.moduleClass.annotations.contains(annot)
}
}
problem <- newpkg.classes.get(oldclazz.bytecodeName) match {
case Some(newclazz) => analyze(oldclazz, newclazz, log, excludeAnnots)
case None => List(MissingClassProblem(oldclazz))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package com.typesafe.tools.mima.lib
import scala.reflect.io.Path
import scala.util.{ Failure, Success, Try }

import munit.GenericTest

object UnitTests {
def main(args: Array[String]): Unit = TestCli.argsToTests(args.toList, runTestCase).unsafeRunTest()
def munitTests(): List[GenericTest[Unit]] = TestCli.argsToTests(Nil, runTestCase).munitTests
def main(args: Array[String]): Unit = TestCli.argsToTests(args.toList, runTestCase).unsafeRunTest()
def munitTests(): List[munit.Test] = TestCli.argsToTests(Nil, runTestCase).munitTests

def runTestCase(testCase: TestCase): Try[Unit] = for {
() <- runTestCaseIf(testCase, Backwards)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object App {
def main(args: Array[String]): Unit = ()
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The change is breaking, but the problem is suppressed by the annotation
# This is here to not make the app run test fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mima
package pkg2

import mima.annotation.exclude

@exclude object O {
def foo = 1
class OC { def foo = 1; class OCC { def foo = 1 }; object OCO { def foo = 1 } }
object OO { def foo = 1; class OOC { def foo = 1 }; object OOO { def foo = 1 } }
}
@exclude class C {
def foo = 1
class CC { def foo = 1; class CCC { def foo = 1 }; object CCO { def foo = 1 } }
object CO { def foo = 1; class COC { def foo = 1 }; object COO { def foo = 1 } }
}

object PrefixO {
@exclude object O {
def foo = 1
class OC { def foo = 1; class OCC { def foo = 1 }; object OCO { def foo = 1 } }
object OO { def foo = 1; class OOC { def foo = 1 }; object OOO { def foo = 1 } }
}
@exclude class C {
def foo = 1
class CC { def foo = 1; class CCC { def foo = 1 }; object CCO { def foo = 1 } }
object CO { def foo = 1; class COC { def foo = 1 }; object COO { def foo = 1 } }
}
}
class PrefixC {
@exclude object O {
def foo = 1
class OC { def foo = 1; class OCC { def foo = 1 }; object OCO { def foo = 1 } }
object OO { def foo = 1; class OOC { def foo = 1 }; object OOO { def foo = 1 } }
}
@exclude class C {
def foo = 1
class CC { def foo = 1; class CCC { def foo = 1 }; object CCO { def foo = 1 } }
object CO { def foo = 1; class COC { def foo = 1 }; object COO { def foo = 1 } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mima.annotation

import scala.annotation.StaticAnnotation

class exclude extends StaticAnnotation
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mima
package pkg2

import mima.annotation.exclude

@exclude object O {
class OC { class OCC; object OCO }
object OO { class OOC; object OOO }
}
@exclude class C {
class CC { class CCC; object CCO }
object CO { class COC; object COO }
}

object PrefixO {
@exclude object O {
class OC { class OCC; object OCO }
object OO { class OOC; object OOO }
}
@exclude class C {
class CC { class CCC; object CCO }
object CO { class COC; object COO }
}
}
class PrefixC {
@exclude object O {
class OC { class OCC; object OCO }
object OO { class OOC; object OOO }
}
@exclude class C {
class CC { class CCC; object CCO }
object CO { class COC; object COO }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mima.annotation

import scala.annotation.StaticAnnotation

class exclude extends StaticAnnotation

0 comments on commit f353ee3

Please sign in to comment.