This commit is contained in:
Adrien Piquerez 2024-09-17 16:54:34 +02:00
parent 3dcc6cfcd1
commit 6da4790671
3 changed files with 24 additions and 15 deletions

View File

@ -13,6 +13,7 @@ sealed abstract class VirtualAxis {
}
object VirtualAxis {
/**
* WeakAxis allows a row to depend on another row with Zero value.
* For example, Scala version can be Zero for Java project, and it's ok.
@ -22,7 +23,6 @@ object VirtualAxis {
/** StrongAxis requires a row to depend on another row with the same selected value. */
abstract class StrongAxis extends VirtualAxis
def isMatch(lhs: Seq[VirtualAxis], rhs: Seq[VirtualAxis]): Boolean =
lhs.forall(isStronglyCompatible(_, rhs)) && rhs.forall(isStronglyCompatible(_, lhs))
@ -41,8 +41,8 @@ object VirtualAxis {
def isSecondaryCompatible(v: VirtualAxis, stack: Seq[VirtualAxis]): Boolean =
v match {
case v: ScalaVersionAxis =>
val thatSVOpt = (stack collect {
case x: ScalaVersionAxis => x
val thatSVOpt = (stack collect { case x: ScalaVersionAxis =>
x
}).headOption
thatSVOpt match {
case Some(ScalaVersionAxis(sv, _)) =>
@ -54,7 +54,10 @@ object VirtualAxis {
isStronglyCompatible(v, stack)
}
private[sbt] def isScala2Scala3Sandwich(sbv1: Option[(Long, Long)], sbv2: Option[(Long, Long)]): Boolean = {
private[sbt] def isScala2Scala3Sandwich(
sbv1: Option[(Long, Long)],
sbv2: Option[(Long, Long)]
): Boolean = {
def str(x: Option[(Long, Long)]): String =
x match {
case Some((a, b)) => s"$a.$b"
@ -97,7 +100,8 @@ object VirtualAxis {
}
}
case class PlatformAxis(value: String, idSuffix: String, directorySuffix: String) extends StrongAxis {
case class PlatformAxis(value: String, idSuffix: String, directorySuffix: String)
extends StrongAxis {
override val suffixOrder: Int = 80
}

View File

@ -6,8 +6,8 @@ import java.util.concurrent.atomic.AtomicBoolean
import scala.language.experimental.macros
trait ProjectMatrixKeys {
val virtualAxes = settingKey[Seq[VirtualAxis]]("Virtual axes for the project")
val projectMatrixBaseDirectory = settingKey[File]("Base directory of the current project matrix")
val virtualAxes = settingKey[Seq[VirtualAxis]]("Virtual axes for the project")
val projectMatrixBaseDirectory = settingKey[File]("Base directory of the current project matrix")
}
object ProjectMatrixKeys extends ProjectMatrixKeys
@ -19,12 +19,12 @@ object ProjectMatrixPlugin extends AutoPlugin {
def projectMatrix: ProjectMatrix = macro ProjectMatrix.projectMatrixMacroImpl
implicit def matrixClasspathDependency[T](
m: T
m: T
)(implicit ev: T => ProjectMatrixReference): ProjectMatrix.MatrixClasspathDependency =
ProjectMatrix.MatrixClasspathDependency(m, None)
implicit def matrixReferenceSyntax[T](
m: T
m: T
)(implicit ev: T => ProjectMatrixReference): ProjectMatrix.ProjectMatrixReferenceSyntax =
new ProjectMatrix.ProjectMatrixReferenceSyntax(m)
}

View File

@ -10,14 +10,19 @@ object ReflectionUtil {
val clazz = classLoader.loadClass(className)
val t = implicitly[ClassTag[A]].runtimeClass
Option(clazz.getField("MODULE$").get(null)) match {
case None => throw new ClassNotFoundException(s"Unable to find $className using classloader: $classLoader")
case Some(c) if !t.isInstance(c) => throw new ClassCastException(s"${clazz.getName} is not a subtype of $t")
case Some(c: A) => c
case None =>
throw new ClassNotFoundException(
s"Unable to find $className using classloader: $classLoader"
)
case Some(c) if !t.isInstance(c) =>
throw new ClassCastException(s"${clazz.getName} is not a subtype of $t")
case Some(c: A) => c
}
}
.recover {
case i: InvocationTargetException if i.getTargetException != null => throw i.getTargetException
}
.recover {
case i: InvocationTargetException if i.getTargetException != null =>
throw i.getTargetException
}
def objectExists(classLoader: ClassLoader, className: String): Boolean =
try {