Skip to content

Commit 48e50f7

Browse files
committed
Make artifacts sorted sets
1 parent 905c3fe commit 48e50f7

File tree

7 files changed

+44
-28
lines changed

7 files changed

+44
-28
lines changed

src/main/scala/software/purpledragon/sbt/lock/DependencyUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object DependencyUtils {
8080
module.module.organization,
8181
module.module.name,
8282
module.module.revision,
83-
artifacts,
83+
artifacts.to[SortedSet],
8484
SortedSet.empty)
8585
}
8686

src/main/scala/software/purpledragon/sbt/lock/model/ChangedDependency.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616

1717
package software.purpledragon.sbt.lock.model
1818

19+
import scala.collection.SortedSet
20+
1921
final case class ChangedDependency(
2022
org: String,
2123
name: String,
2224
oldVersion: String,
2325
newVersion: String,
24-
oldArtifacts: Seq[ResolvedArtifact],
25-
newArtifacts: Seq[ResolvedArtifact],
26-
oldConfigurations: Set[String],
27-
newConfigurations: Set[String]) {
26+
oldArtifacts: SortedSet[ResolvedArtifact],
27+
newArtifacts: SortedSet[ResolvedArtifact],
28+
oldConfigurations: SortedSet[String],
29+
newConfigurations: SortedSet[String]) {
2830

2931
def versionChanged: Boolean = oldVersion != newVersion
3032
def configurationsChanged: Boolean = oldConfigurations != newConfigurations

src/main/scala/software/purpledragon/sbt/lock/model/DependencyLockFile.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ final case class DependencyLockFile(
8282
otherDep.version,
8383
ourDep.artifacts,
8484
otherDep.artifacts,
85-
ourDep.configurations.toSet,
86-
otherDep.configurations.toSet)
85+
ourDep.configurations,
86+
otherDep.configurations)
8787
} else {
8888
changes
8989
}

src/main/scala/software/purpledragon/sbt/lock/model/ResolvedArtifact.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616

1717
package software.purpledragon.sbt.lock.model
1818

19-
final case class ResolvedArtifact(name: String, hash: String)
19+
import scala.math.Ordered.orderingToOrdered
20+
21+
final case class ResolvedArtifact(name: String, hash: String) extends Ordered[ResolvedArtifact] {
22+
override def compare(that: ResolvedArtifact): Int = {
23+
(name, hash) compare (that.name, that.hash)
24+
}
25+
}

src/main/scala/software/purpledragon/sbt/lock/model/ResolvedDependency.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final case class ResolvedDependency(
2323
org: String,
2424
name: String,
2525
version: String,
26-
artifacts: Seq[ResolvedArtifact],
26+
artifacts: SortedSet[ResolvedArtifact],
2727
configurations: SortedSet[String])
2828
extends Ordered[ResolvedDependency] {
2929

src/test/scala/software/purpledragon/sbt/lock/model/DependencyLockFileSpec.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class DependencyLockFileSpec extends AnyFlatSpec with Matchers {
3434
"com.example",
3535
"package-1",
3636
"1.0.0",
37-
Seq(ResolvedArtifact("package-1.jar", "hash-1")),
37+
SortedSet(ResolvedArtifact("package-1.jar", "hash-1")),
3838
SortedSet("test-1")),
39-
ResolvedDependency("com.example", "package-2", "1.2.0", Nil, SortedSet("test-2"))
39+
ResolvedDependency("com.example", "package-2", "1.2.0", SortedSet.empty, SortedSet("test-2"))
4040
)
4141
)
4242

@@ -82,7 +82,7 @@ class DependencyLockFileSpec extends AnyFlatSpec with Matchers {
8282
"com.example",
8383
"package-3",
8484
"3.0",
85-
Seq(ResolvedArtifact("package-3.jar", "hash-3")),
85+
SortedSet(ResolvedArtifact("package-3.jar", "hash-3")),
8686
SortedSet("test-1"))
8787

8888
val left = TestLockFile
@@ -105,7 +105,7 @@ class DependencyLockFileSpec extends AnyFlatSpec with Matchers {
105105
"com.example",
106106
"package-1",
107107
"2.0.0",
108-
Seq(ResolvedArtifact("package-1.jar", "hash-1a")),
108+
SortedSet(ResolvedArtifact("package-1.jar", "hash-1a")),
109109
SortedSet("test-1", "test-2"))
110110
)
111111

@@ -120,10 +120,10 @@ class DependencyLockFileSpec extends AnyFlatSpec with Matchers {
120120
"package-1",
121121
"1.0.0",
122122
"2.0.0",
123-
Seq(ResolvedArtifact("package-1.jar", "hash-1")),
124-
Seq(ResolvedArtifact("package-1.jar", "hash-1a")),
125-
Set("test-1"),
126-
Set("test-1", "test-2")
123+
SortedSet(ResolvedArtifact("package-1.jar", "hash-1")),
124+
SortedSet(ResolvedArtifact("package-1.jar", "hash-1a")),
125+
SortedSet("test-1"),
126+
SortedSet("test-1", "test-2")
127127
))
128128
)
129129
}

src/test/scala/software/purpledragon/sbt/lock/model/LockFileStatusSpec.scala

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
165165
.withDependencyChanges(
166166
Nil,
167167
Nil,
168-
Seq(testChangedDependency(newVersion = "1.0", newConfigurations = Set("compile"))))
168+
Seq(testChangedDependency(newVersion = "1.0", newConfigurations = SortedSet("compile"))))
169169
.toLongReport shouldBe expected
170170
}
171171

@@ -176,7 +176,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
176176
| com.example:artifact:[1.0]->[2.0] (compile,test)->(compile)""".stripMargin
177177

178178
LockFileMatches
179-
.withDependencyChanges(Nil, Nil, Seq(testChangedDependency(newConfigurations = Set("compile"))))
179+
.withDependencyChanges(Nil, Nil, Seq(testChangedDependency(newConfigurations = SortedSet("compile"))))
180180
.toLongReport shouldBe expected
181181
}
182182

@@ -206,14 +206,14 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
206206
testChangedDependency(
207207
org = "org.example",
208208
name = "version",
209-
oldConfigurations = Set("compile"),
210-
newConfigurations = Set("compile")),
209+
oldConfigurations = SortedSet("compile"),
210+
newConfigurations = SortedSet("compile")),
211211
testChangedDependency(
212212
org = "org.example",
213213
name = "configs",
214214
newVersion = "1.0",
215-
newConfigurations = Set("compile")),
216-
testChangedDependency(org = "org.example", name = "both", oldConfigurations = Set("compile"))
215+
newConfigurations = SortedSet("compile")),
216+
testChangedDependency(org = "org.example", name = "both", oldConfigurations = SortedSet("compile"))
217217
)
218218
)
219219
.toLongReport
@@ -226,17 +226,25 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
226226
name: String = "artifact",
227227
version: String = "1.0",
228228
configs: SortedSet[String] = SortedSet("compile", "test")): ResolvedDependency = {
229-
ResolvedDependency(org, name, version, Nil, configs)
229+
ResolvedDependency(org, name, version, SortedSet.empty, configs)
230230
}
231231

232232
private def testChangedDependency(
233233
org: String = "com.example",
234234
name: String = "artifact",
235235
oldVersion: String = "1.0",
236236
newVersion: String = "2.0",
237-
oldConfigurations: Set[String] = Set("compile", "test"),
238-
newConfigurations: Set[String] = Set("compile", "test")): ChangedDependency = {
239-
240-
ChangedDependency(org, name, oldVersion, newVersion, Nil, Nil, oldConfigurations, newConfigurations)
237+
oldConfigurations: SortedSet[String] = SortedSet("compile", "test"),
238+
newConfigurations: SortedSet[String] = SortedSet("compile", "test")): ChangedDependency = {
239+
240+
ChangedDependency(
241+
org,
242+
name,
243+
oldVersion,
244+
newVersion,
245+
SortedSet.empty,
246+
SortedSet.empty,
247+
oldConfigurations,
248+
newConfigurations)
241249
}
242250
}

0 commit comments

Comments
 (0)