Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Scala LTS and Next version updates #3328

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ package org.scalasteward.core
package object data {
val scalaLangGroupId: GroupId = GroupId("org.scala-lang")

val scalaLangModules: List[(GroupId, ArtifactId)] =
val scala2LangModules: List[(GroupId, ArtifactId)] =
List(
(scalaLangGroupId, ArtifactId("scala-compiler")),
(scalaLangGroupId, ArtifactId("scala-library")),
(scalaLangGroupId, ArtifactId("scala-reflect")),
(scalaLangGroupId, ArtifactId("scalap")),
(scalaLangGroupId, ArtifactId("scalap"))
)

val scala3LangModules: List[(GroupId, ArtifactId)] =
List(
(scalaLangGroupId, ArtifactId("scala3-compiler")),
(scalaLangGroupId, ArtifactId("scala3-library")),
(scalaLangGroupId, ArtifactId("scala3-library_sjs1"))
)

val scalaLangModules: List[(GroupId, ArtifactId)] =
scala2LangModules ++ scala3LangModules

val scalaNextMinVersion: Version = Version("3.4.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object FilterAlg {
case NotAllowedByConfig(_) => "not allowed by config"
case NoSuitableNextVersion(_) => "no suitable next version"
case VersionOrderingConflict(_) => "version ordering conflict"
case IgnoreScalaNext(_) => "not upgrading from Scala LTS to Next version"
}
}

Expand All @@ -62,9 +63,30 @@ object FilterAlg {
final case class NotAllowedByConfig(update: Update.ForArtifactId) extends RejectionReason
final case class NoSuitableNextVersion(update: Update.ForArtifactId) extends RejectionReason
final case class VersionOrderingConflict(update: Update.ForArtifactId) extends RejectionReason
final case class IgnoreScalaNext(update: Update.ForArtifactId) extends RejectionReason

def localFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
repoConfig.updates.keep(update).flatMap(globalFilter(_, repoConfig))
repoConfig.updates.keep(update).flatMap(scalaLTSFilter).flatMap(globalFilter(_, repoConfig))

def scalaLTSFilter(update: Update.ForArtifactId): FilterResult =
if (!isScala3Lang(update))
Right(update)
else {
if (update.currentVersion >= scalaNextMinVersion) {
// already on Scala Next
Right(update)
} else {
val filteredVersions = update.newerVersions.filterNot(_ >= scalaNextMinVersion)
if (filteredVersions.nonEmpty)
Right(update.copy(newerVersions = Nel.fromListUnsafe(filteredVersions)))
else Left(IgnoreScalaNext(update))
}
}

def isScala3Lang(update: Update.ForArtifactId): Boolean =
scala3LangModules.exists { case (g, a) =>
update.groupId == g && update.artifactIds.exists(_ == a)
}

private def globalFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
selectSuitableNextVersion(update, repoConfig).flatMap(checkVersionOrdering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,30 @@ class FilterAlgTest extends FunSuite {
val dependency = "org.typelevel".g % ("cats-effect", "cats-effect_2.12").a % "1.0.0"
assert(isDependencyConfigurationIgnored(dependency.copy(configurations = Some("scalafmt"))))
}

test("scalaLTSFilter: LTS, no update") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.2" %> Nel.of("3.4.0")).single
assertEquals(scalaLTSFilter(update), Left(IgnoreScalaNext(update)))
}

test("scalaLTSFilter: LTS, filter versions") {
val update =
("org.scala-lang".g % "scala3-compiler".a % "3.3.2" %> Nel.of("3.3.3", "3.4.0")).single
assertEquals(scalaLTSFilter(update), Right(update.copy(newerVersions = Nel.of("3.3.3".v))))
}

test("scalaLTSFilter: Next") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.4.0" %> Nel.of("3.4.1")).single
assertEquals(scalaLTSFilter(update), Right(update))
}

test("isScala3Lang: true") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.3" %> Nel.of("3.4.0")).single
assert(isScala3Lang(update))
}

test("isScala3Lang: false") {
val update = ("org.scala-lang".g % "scala-compiler".a % "2.13.11" %> Nel.of("2.13.12")).single
assert(!isScala3Lang(update))
}
}
Loading