@@ -23,33 +23,44 @@ import org.scalasteward.core.repoconfig.PullRequestGroup
2323import org .scalasteward .core .util
2424import org .scalasteward .core .util .Nel
2525
26-
27- case class ArtifactUpdateCandidates (
26+ case class ArtifactForUpdate (
2827 crossDependency : CrossDependency ,
29- newerVersions : Nel [Version ],
3028 newerGroupId : Option [GroupId ] = None ,
3129 newerArtifactId : Option [String ] = None
3230) {
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
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+ }
52+
53+ case class ArtifactUpdateCandidates (
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
5566sealed trait Update {
@@ -97,44 +108,41 @@ 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 with ArtifactUpdateVersions {
122+ override val refersToUpdateVersions : Nel [Version ] = Nel .one(nextVersion)
115123
116- override def crossDependencies : Nel [CrossDependency ] =
117- Nel .one(crossDependency)
124+ val crossDependency : CrossDependency = artifactForUpdate.crossDependency
118125
119- override def dependencies : Nel [Dependency ] =
120- crossDependency.dependencies
126+ val headDependency : Dependency = crossDependency.head
121127
122- override def groupId : GroupId =
123- crossDependency.head.groupId
128+ override def forArtifactIds : Nel [ForArtifactId ] = Nel .one(this )
124129
125- override def artifactIds : Nel [ArtifactId ] =
126- dependencies.map(_.artifactId)
130+ override def crossDependencies : Nel [CrossDependency ] = Nel .one(crossDependency)
131+
132+ override def dependencies : Nel [Dependency ] = crossDependency.dependencies
133+
134+ override def groupId : GroupId = headDependency.groupId
127135
128- override def mainArtifactId : String =
129- artifactId.name
136+ override def artifactIds : Nel [ArtifactId ] = dependencies.map(_.artifactId)
137+
138+ override def mainArtifactId : String = artifactId.name
130139
131140 override def showArtifacts : String = crossDependency.showArtifactNames
132141
133- override def currentVersion : Version =
134- crossDependency.head.version
142+ override def currentVersion : Version = headDependency.version
143+
144+ def artifactId : ArtifactId = headDependency.artifactId
135145
136- def artifactId : ArtifactId =
137- crossDependency.head.artifactId
138146 }
139147
140148 final case class ForGroupId (
@@ -190,8 +198,9 @@ object Update {
190198 val groups0 =
191199 updates.groupByNel(s => (s.groupId, s.artifactId.name, s.currentVersion, s.nextVersion))
192200 val groups1 = groups0.values.map { group =>
193- val dependencies = group.flatMap(_.crossDependency.dependencies).distinct.sorted
194- group.head.copy(crossDependency = CrossDependency (dependencies))
201+ val dependencies = group.flatMap(_.artifactForUpdate.crossDependency.dependencies).distinct.sorted
202+ val update : Update .ForArtifactId = group.head
203+ update.copy(artifactForUpdate = update.artifactForUpdate.copy(crossDependency = CrossDependency (dependencies)))
195204 }
196205 groups1.toList.distinct.sortBy(u => u : Update .Single )
197206 }
@@ -228,23 +237,23 @@ object Update {
228237
229238 // ForArtifactId
230239
231- implicit private val forArtifactIdEncoder : Encoder [ForArtifactId ] =
232- Encoder .forProduct1(" ForArtifactId" )(identity[ForArtifactId ]) {
233- Encoder .forProduct4(" crossDependency" , " nextVersion" , " newerGroupId" , " newerArtifactId" ) {
234- s => (s.crossDependency, s.nextVersion, s.newerGroupId, s.newerArtifactId)
235- }
236- }
237-
238- private val unwrappedForArtifactIdDecoder : Decoder [ForArtifactId ] =
239- Decoder .forProduct4(" crossDependency" , " nextVersion" , " newerGroupId" , " newerArtifactId" ) {
240- (
241- crossDependency : CrossDependency ,
242- nextVersion : Version ,
243- newerGroupId : Option [GroupId ],
244- newerArtifactId : Option [String ]
245- ) =>
246- ForArtifactId (crossDependency, nextVersion, newerGroupId, newerArtifactId)
247- }
240+ implicit private val forArtifactIdEncoder : Encoder [ForArtifactId ] = ???
241+ // Encoder.forProduct1("ForArtifactId")(identity[ForArtifactId]) {
242+ // Encoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
243+ // s => (s.crossDependency, s.nextVersion, s.newerGroupId, s.newerArtifactId)
244+ // }
245+ // }
246+
247+ private val unwrappedForArtifactIdDecoder : Decoder [ForArtifactId ] = ???
248+ // Decoder.forProduct4("crossDependency", "nextVersion", "newerGroupId", "newerArtifactId") {
249+ // (
250+ // crossDependency: CrossDependency,
251+ // nextVersion: Version,
252+ // newerGroupId: Option[GroupId],
253+ // newerArtifactId: Option[String]
254+ // ) =>
255+ // ForArtifactId(crossDependency, nextVersion, newerGroupId, newerArtifactId)
256+ // }
248257
249258 private val forArtifactIdDecoderV2 =
250259 Decoder .forProduct1(" ForArtifactId" )(identity[ForArtifactId ])(unwrappedForArtifactIdDecoder)
0 commit comments