Skip to content

Commit 8a8d2fe

Browse files
committed
Actually compiles...
1 parent e63ace3 commit 8a8d2fe

File tree

17 files changed

+230
-152
lines changed

17 files changed

+230
-152
lines changed

modules/benchmark/src/main/scala/org/scalasteward/benchmark/UpdatesConfigBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UpdatesConfigBenchmark {
3333
val newerVersions = Nel
3434
.of("2.0.0", "2.1.0", "2.1.1", "2.2.0", "3.0.0", "3.1.0", "3.2.1", "3.3.3", "4.0", "5.0")
3535
.map(Version.apply)
36-
val update = Update.ForArtifactId(dependency, newerVersions)
36+
val update = ArtifactUpdateCandidates(ArtifactForUpdate(dependency), newerVersions)
3737

3838
UpdatesConfig().keep(update)
3939
UpdatesConfig(allow = Some(List(UpdatePattern(groupId, None, None)))).keep(update)

modules/core/src/main/scala/org/scalasteward/core/data/Update.scala

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,44 @@ import org.scalasteward.core.repoconfig.PullRequestGroup
2323
import org.scalasteward.core.util
2424
import org.scalasteward.core.util.Nel
2525

26+
case class ArtifactForUpdate(
27+
crossDependency: CrossDependency,
28+
newerGroupId: Option[GroupId] = None,
29+
newerArtifactId: Option[String] = None
30+
) {
31+
def groupId: GroupId = crossDependency.head.groupId
32+
33+
def dependencies: Nel[Dependency] = crossDependency.dependencies
34+
35+
def artifactId: ArtifactId = crossDependency.head.artifactId
36+
37+
def artifactIds: Nel[ArtifactId] = dependencies.map(_.artifactId)
38+
//
39+
// override def mainArtifactId: String =
40+
// artifactId.name
41+
//
42+
def currentVersion: Version = crossDependency.head.version
43+
}
44+
45+
trait ArtifactUpdateVersions {
46+
val artifactForUpdate: ArtifactForUpdate
47+
48+
val refersToUpdateVersions: Nel[Version]
49+
50+
def show: String
51+
}
2652

2753
case class ArtifactUpdateCandidates(
28-
crossDependency: CrossDependency,
29-
newerVersions: Nel[Version],
30-
newerGroupId: Option[GroupId] = None,
31-
newerArtifactId: Option[String] = None
32-
) {
33-
def groupId: GroupId =
34-
crossDependency.head.groupId
35-
36-
def dependencies: Nel[Dependency] =
37-
crossDependency.dependencies
38-
39-
def artifactIds: Nel[ArtifactId] =
40-
dependencies.map(_.artifactId)
41-
//
42-
// override def mainArtifactId: String =
43-
// artifactId.name
44-
//
45-
def show: String =
46-
s"$groupId:${crossDependency.showArtifactNames} : ${Version.show((currentVersion +: newerVersions.toList)*)}"
47-
48-
def currentVersion: Version =
49-
crossDependency.head.version
50-
51-
def artifactId: ArtifactId =
52-
crossDependency.head.artifactId
54+
artifactForUpdate: ArtifactForUpdate,
55+
newerVersions: Nel[Version]
56+
) extends ArtifactUpdateVersions {
57+
override val refersToUpdateVersions: Nel[Version] = newerVersions
58+
59+
def asSpecificUpdate(nextVersion: Version): Update.ForArtifactId =
60+
Update.ForArtifactId(artifactForUpdate, nextVersion)
61+
62+
override def show: String =
63+
s"${artifactForUpdate.groupId}:${artifactForUpdate.crossDependency.showArtifactNames} : ${Version.show((artifactForUpdate.currentVersion +: refersToUpdateVersions.toList)*)}"
5364
}
5465

5566
sealed trait Update {
@@ -97,44 +108,42 @@ object Update {
97108
s"$groupId:$showArtifacts : ${Version.show(currentVersion, nextVersion)}"
98109

99110
def withVersionData(nextVersion: Version): Update.Single = this match {
100-
case s @ ForArtifactId(_, _, _, _) =>
111+
case s: ForArtifactId =>
101112
s.copy(nextVersion = nextVersion)
102113
case ForGroupId(forArtifactIds) =>
103114
ForGroupId(forArtifactIds.map(_.copy(nextVersion = nextVersion)))
104115
}
105116
}
106117

107118
final case class ForArtifactId(
108-
crossDependency: CrossDependency,
109-
nextVersion: Version,
110-
newerGroupId: Option[GroupId] = None,
111-
newerArtifactId: Option[String] = None
112-
) extends Single {
113-
override def forArtifactIds: Nel[ForArtifactId] =
114-
Nel.one(this)
119+
artifactForUpdate: ArtifactForUpdate,
120+
nextVersion: Version
121+
) extends Single
122+
with ArtifactUpdateVersions {
123+
override val refersToUpdateVersions: Nel[Version] = Nel.one(nextVersion)
115124

116-
override def crossDependencies: Nel[CrossDependency] =
117-
Nel.one(crossDependency)
125+
val crossDependency: CrossDependency = artifactForUpdate.crossDependency
118126

119-
override def dependencies: Nel[Dependency] =
120-
crossDependency.dependencies
127+
val headDependency: Dependency = crossDependency.head
121128

122-
override def groupId: GroupId =
123-
crossDependency.head.groupId
129+
override def forArtifactIds: Nel[ForArtifactId] = Nel.one(this)
124130

125-
override def artifactIds: Nel[ArtifactId] =
126-
dependencies.map(_.artifactId)
131+
override def crossDependencies: Nel[CrossDependency] = Nel.one(crossDependency)
132+
133+
override def dependencies: Nel[Dependency] = crossDependency.dependencies
134+
135+
override def groupId: GroupId = headDependency.groupId
127136

128-
override def mainArtifactId: String =
129-
artifactId.name
137+
override def artifactIds: Nel[ArtifactId] = dependencies.map(_.artifactId)
138+
139+
override def mainArtifactId: String = artifactId.name
130140

131141
override def showArtifacts: String = crossDependency.showArtifactNames
132142

133-
override def currentVersion: Version =
134-
crossDependency.head.version
143+
override def currentVersion: Version = headDependency.version
144+
145+
def artifactId: ArtifactId = headDependency.artifactId
135146

136-
def artifactId: ArtifactId =
137-
crossDependency.head.artifactId
138147
}
139148

140149
final case class ForGroupId(
@@ -167,7 +176,8 @@ object Update {
167176
.getOrElse(artifactIds.head.name)
168177
}
169178

170-
override def showArtifacts: String = crossDependencies.map(_.showArtifactNames).mkString_("{", ", ", "}")
179+
override def showArtifacts: String =
180+
crossDependencies.map(_.showArtifactNames).mkString_("{", ", ", "}")
171181

172182
override def currentVersion: Version =
173183
dependencies.head.version
@@ -190,8 +200,12 @@ object Update {
190200
val groups0 =
191201
updates.groupByNel(s => (s.groupId, s.artifactId.name, s.currentVersion, s.nextVersion))
192202
val groups1 = groups0.values.map { group =>
193-
val dependencies = group.flatMap(_.crossDependency.dependencies).distinct.sorted
194-
group.head.copy(crossDependency = CrossDependency(dependencies))
203+
val dependencies =
204+
group.flatMap(_.artifactForUpdate.crossDependency.dependencies).distinct.sorted
205+
val update: Update.ForArtifactId = group.head
206+
update.copy(artifactForUpdate =
207+
update.artifactForUpdate.copy(crossDependency = CrossDependency(dependencies))
208+
)
195209
}
196210
groups1.toList.distinct.sortBy(u => u: Update.Single)
197211
}
@@ -230,20 +244,29 @@ object Update {
230244

231245
implicit private val forArtifactIdEncoder: Encoder[ForArtifactId] =
232246
Encoder.forProduct1("ForArtifactId")(identity[ForArtifactId]) {
233-
Encoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
234-
s => (s.crossDependency, s.nextVersion, s.newerGroupId, s.newerArtifactId)
247+
Encoder.forProduct4("crossDependency", "newerVersions", "newerGroupId", "newerArtifactId") {
248+
s =>
249+
(
250+
s.crossDependency,
251+
Seq(s.nextVersion),
252+
s.artifactForUpdate.newerGroupId,
253+
s.artifactForUpdate.newerArtifactId
254+
)
235255
}
236256
}
237257

238258
private val unwrappedForArtifactIdDecoder: Decoder[ForArtifactId] =
239-
Decoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
259+
Decoder.forProduct4("crossDependency", "newerVersions", "newerGroupId", "newerArtifactId") {
240260
(
241261
crossDependency: CrossDependency,
242-
nextVersion: Version,
262+
newerVersions: List[Version],
243263
newerGroupId: Option[GroupId],
244264
newerArtifactId: Option[String]
245265
) =>
246-
ForArtifactId(crossDependency, nextVersion, newerGroupId, newerArtifactId)
266+
ForArtifactId(
267+
ArtifactForUpdate(crossDependency, newerGroupId, newerArtifactId),
268+
newerVersions.head
269+
)
247270
}
248271

249272
private val forArtifactIdDecoderV2 =

modules/core/src/main/scala/org/scalasteward/core/edit/update/Selector.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ object Selector {
204204
update: Update.Single,
205205
modulePositions: List[ModulePosition]
206206
): List[Substring.Replacement] =
207-
update.forArtifactIds.toList.flatMap { forArtifactId =>
208-
val newerGroupId = forArtifactId.newerGroupId
209-
val newerArtifactId = forArtifactId.newerArtifactId
207+
update.forArtifactIds.toList.map(_.artifactForUpdate).flatMap { artifactForUpdate =>
208+
val newerGroupId = artifactForUpdate.newerGroupId
209+
val newerArtifactId = artifactForUpdate.newerArtifactId
210210
if (newerGroupId.isEmpty && newerArtifactId.isEmpty) List.empty
211211
else {
212-
val currentGroupId = forArtifactId.groupId
213-
val currentArtifactId = forArtifactId.artifactIds.head
212+
val currentGroupId = artifactForUpdate.groupId
213+
val currentArtifactId = artifactForUpdate.artifactIds.head
214214
modulePositions
215215
.filter { p =>
216216
p.groupId.value === currentGroupId.value &&

modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ object NewPullRequestData {
363363

364364
val artifactMigrationsLabel = Option.when {
365365
update.asSingleUpdates
366-
.flatMap(_.forArtifactIds.toList)
366+
.flatMap(_.forArtifactIds.toList.map(_.artifactForUpdate))
367367
.exists(u => u.newerGroupId.nonEmpty || u.newerArtifactId.nonEmpty)
368368
}("artifact-migrations")
369369
val scalafixLabel = edits.collectFirst { case _: ScalafixEdit => "scalafix-migrations" }

modules/core/src/main/scala/org/scalasteward/core/repoconfig/PullRequestUpdateFilter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ final case class PullRequestUpdateFilter private (
4747

4848
private def isMatchedVersion(versionType: SemVer.Change, update: Update.ForArtifactId): Boolean =
4949
(SemVer.parse(update.currentVersion.value), SemVer.parse(update.nextVersion.value)).tupled
50-
.flatMap { case (current, next) => SemVer.getChangeEarly(current, next) }.exists(_.render === versionType.render)
50+
.flatMap { case (current, next) => SemVer.getChangeEarly(current, next) }
51+
.exists(_.render === versionType.render)
5152

5253
}
5354

modules/core/src/main/scala/org/scalasteward/core/repoconfig/RetractedArtifact.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ final case class RetractedArtifact(
2525
doc: String,
2626
artifacts: List[UpdatePattern] = List.empty
2727
) {
28-
def isRetracted(updateSingle: Update.Single): Boolean = // NextVersion, because the PR already raised?
28+
def isRetracted(updateSingle: Update.Single): Boolean =
2929
updateSingle.forArtifactIds.exists { updateForArtifactId =>
3030
UpdatePattern
31-
.findMatch(artifacts, updateForArtifactId.transformVersionData(_.asNewerVersions), include = true)
31+
.findMatch(artifacts, updateForArtifactId, include = true)
3232
.filteredVersions
3333
.nonEmpty
3434
}

modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatePattern.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ package org.scalasteward.core.repoconfig
1919
import cats.syntax.all.*
2020
import io.circe.Codec
2121
import io.circe.generic.semiauto.*
22-
import org.scalasteward.core.data.{ArtifactUpdateCandidates, GroupId, Version}
22+
import org.scalasteward.core.data.{
23+
ArtifactUpdateCandidates,
24+
ArtifactUpdateVersions,
25+
GroupId,
26+
Version
27+
}
2328

2429
final case class UpdatePattern(
2530
groupId: GroupId,
@@ -37,12 +42,14 @@ object UpdatePattern {
3742

3843
def findMatch(
3944
patterns: List[UpdatePattern],
40-
update: ArtifactUpdateCandidates,
45+
update: ArtifactUpdateVersions,
4146
include: Boolean
4247
): MatchResult = {
43-
val byGroupId = patterns.filter(_.groupId === update.groupId)
44-
val byArtifactId = byGroupId.filter(_.artifactId.forall(_ === update.artifactId.name))
45-
val filteredVersions = update.newerVersions.filter(newVersion =>
48+
val artifactForUpdate = update.artifactForUpdate
49+
val byGroupId = patterns.filter(_.groupId === artifactForUpdate.groupId)
50+
val byArtifactId =
51+
byGroupId.filter(_.artifactId.forall(_ === artifactForUpdate.artifactId.name))
52+
val filteredVersions = update.refersToUpdateVersions.filter(newVersion =>
4653
byArtifactId.exists(_.version.forall(_.matches(newVersion.value))) === include
4754
)
4855
MatchResult(byArtifactId, filteredVersions)

modules/core/src/main/scala/org/scalasteward/core/repoconfig/UpdatesConfig.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ import io.circe.{Codec, Decoder}
2525
import org.scalasteward.core.buildtool.{gradle, maven, mill, sbt}
2626
import org.scalasteward.core.data.{ArtifactUpdateCandidates, GroupId}
2727
import org.scalasteward.core.scalafmt
28-
import org.scalasteward.core.update.FilterAlg.{FilterResult, IgnoredByConfig, NotAllowedByConfig, VersionPinnedByConfig}
29-
import org.scalasteward.core.util.{Nel, combineOptions, intellijThisImportIsUsed}
28+
import org.scalasteward.core.update.FilterAlg.{
29+
FilterResult,
30+
IgnoredByConfig,
31+
NotAllowedByConfig,
32+
VersionPinnedByConfig
33+
}
34+
import org.scalasteward.core.util.{combineOptions, intellijThisImportIsUsed, Nel}
3035

3136
final case class UpdatesConfig(
3237
private val pin: Option[List[UpdatePattern]] = None,

modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ final class FilterAlg[F[_]](implicit
3333
update: ArtifactUpdateCandidates
3434
): F[Option[Update.ForArtifactId]] =
3535
localFilter(update, config) match {
36-
case Right(update) => F.pure(update.transformVersionData(_.toNextVersion).some)
37-
case Left(reason) =>
36+
case Right(update) => F.pure(update.some)
37+
case Left(reason) =>
3838
logger.info(s"Ignore ${reason.update.show} (reason: ${reason.show})").as(None)
3939
}
4040

@@ -44,7 +44,7 @@ object FilterAlg {
4444
type FilterResult = Either[RejectionReason, ArtifactUpdateCandidates]
4545

4646
sealed trait RejectionReason {
47-
def update: ArtifactUpdateCandidates
47+
def update: ArtifactUpdateVersions
4848
def show: String =
4949
this match {
5050
case IgnoredByConfig(_) => "ignored by config"
@@ -60,20 +60,23 @@ object FilterAlg {
6060
final case class VersionPinnedByConfig(update: ArtifactUpdateCandidates) extends RejectionReason
6161
final case class NotAllowedByConfig(update: ArtifactUpdateCandidates) extends RejectionReason
6262
final case class NoSuitableNextVersion(update: ArtifactUpdateCandidates) extends RejectionReason
63-
final case class VersionOrderingConflict(update: ArtifactUpdateCandidates) extends RejectionReason
63+
final case class VersionOrderingConflict(update: Update.ForArtifactId) extends RejectionReason
6464
final case class IgnoreScalaNext(update: ArtifactUpdateCandidates) extends RejectionReason
6565

66-
def localFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): FilterResult =
66+
def localFilter(
67+
update: ArtifactUpdateCandidates,
68+
repoConfig: RepoConfig
69+
): Either[RejectionReason, Update.ForArtifactId] =
6770
repoConfig.updatesOrDefault
6871
.keep(update)
6972
.flatMap(scalaLTSFilter)
7073
.flatMap(globalFilter(_, repoConfig))
7174

7275
def scalaLTSFilter(update: ArtifactUpdateCandidates): FilterResult =
73-
if (!isScala3Lang(update))
76+
if (!isScala3Lang(update.artifactForUpdate))
7477
Right(update)
7578
else {
76-
if (update.currentVersion >= scalaNextMinVersion) {
79+
if (update.artifactForUpdate.currentVersion >= scalaNextMinVersion) {
7780
// already on Scala Next
7881
Right(update)
7982
} else {
@@ -85,12 +88,15 @@ object FilterAlg {
8588
}
8689
}
8790

88-
def isScala3Lang(update: ArtifactUpdateCandidates): Boolean =
91+
def isScala3Lang(artifactForUpdate: ArtifactForUpdate): Boolean =
8992
scala3LangModules.exists { case (g, a) =>
90-
update.groupId == g && update.artifactIds.exists(_.name == a.name)
93+
artifactForUpdate.groupId == g && artifactForUpdate.artifactId.name == a.name
9194
}
9295

93-
private def globalFilter(update: ArtifactUpdateCandidates, repoConfig: RepoConfig): FilterResult =
96+
private def globalFilter(
97+
update: ArtifactUpdateCandidates,
98+
repoConfig: RepoConfig
99+
): Either[RejectionReason, Update.ForArtifactId] =
94100
selectSuitableNextVersion(update, repoConfig).flatMap(checkVersionOrdering)
95101

96102
def isDependencyConfigurationIgnored(dependency: Dependency): Boolean =
@@ -106,20 +112,23 @@ object FilterAlg {
106112
private def selectSuitableNextVersion(
107113
update: ArtifactUpdateCandidates,
108114
repoConfig: RepoConfig
109-
): FilterResult = {
115+
): Either[RejectionReason, Update.ForArtifactId] = {
110116
val newerVersions = update.newerVersions.toList
111117
val allowPreReleases = repoConfig.updatesOrDefault.preRelease(update).isRight
112-
val maybeNext = update.currentVersion.selectNext(newerVersions, allowPreReleases)
118+
val maybeNext =
119+
update.artifactForUpdate.currentVersion.selectNext(newerVersions, allowPreReleases)
113120

114121
maybeNext match {
115-
case Some(next) => Right(update.copy(newerVersions = Nel.of(next))) // TODO but we _could_ go singular at this point
122+
case Some(next) => Right(update.asSpecificUpdate(nextVersion = next))
116123
case None => Left(NoSuitableNextVersion(update))
117124
}
118125
}
119126

120-
private def checkVersionOrdering(update: ArtifactUpdateCandidates): FilterResult = {
127+
private def checkVersionOrdering(
128+
update: Update.ForArtifactId
129+
): Either[RejectionReason, Update.ForArtifactId] = {
121130
val current = coursier.core.Version(update.currentVersion.value)
122-
val next = coursier.core.Version(update.versionData.toNextVersion.nextVersion.value) // TODO is this the right change?
131+
val next = coursier.core.Version(update.nextVersion.value)
123132
if (current > next) Left(VersionOrderingConflict(update)) else Right(update)
124133
}
125134
}

0 commit comments

Comments
 (0)