Skip to content

Commit b8090b8

Browse files
committed
Improve output of long dependency report
1 parent a320a1e commit b8090b8

File tree

4 files changed

+43
-53
lines changed

4 files changed

+43
-53
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ libraryDependencies ++= Seq(
1818
).map(_ % circeVersion)
1919

2020
libraryDependencies ++= Seq(
21-
"org.scalatest" %% "scalatest" % "3.1.0" % Test
21+
"software.purpledragon" %% "text-utils" % "1.2.0",
22+
"org.scalatest" %% "scalatest" % "3.1.0" % Test
2223
)
2324

2425
organizationName := "Michael Stringer"

src/main/resources/messages.properties

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,4 @@ lock.status.full.dependencies.removed.multiple=\ \ {0} dependencies removed:\n{1
4242

4343
lock.status.full.dependencies.changed.none=
4444
lock.status.full.dependencies.changed.singular=\ \ 1 dependency changed:\n{1}
45-
lock.status.full.dependencies.changed.multiple=\ \ {0} dependencies changed:\n{1}
46-
47-
#com.example:artifact:1.0 (compile,test)
48-
lock.status.full.dependency=\ \ \ \ {0}:{1}:{2} ({3})
49-
#com.example:artifact:[1.0]->[2.0] (compile,test)
50-
lock.status.full.dependency.changed.version=\ \ \ \ {0}:{1}:[{2}]->[{3}] ({4})
51-
#com.example:artifact:1.0 (compile,test)->(compile)
52-
lock.status.full.dependency.changed.configs=\ \ \ \ {0}:{1}:{2} ({4})->({5})
53-
#com.example:artifact:[1.0]->[2.0] (compile,test)->(compile)
54-
lock.status.full.dependency.changed.all=\ \ \ \ {0}:{1}:[{2}]->[{3}] ({4})->({5})
45+
lock.status.full.dependencies.changed.multiple=\ \ {0} dependencies changed:\n{1}

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package software.purpledragon.sbt.lock.model
1818

1919
import software.purpledragon.sbt.lock.util.MessageUtil
20+
import software.purpledragon.text.TableFormatter
2021

2122
import scala.collection.mutable
2223

@@ -43,7 +44,8 @@ case object LockFileMatches extends LockFileStatus {
4344
LockFileDiffers(Nil, Nil, added, removed, changed)
4445
}
4546

46-
override val toShortReport: String = MessageUtil.formatMessage("lock.status.success")
47+
override val toShortReport: String =
48+
MessageUtil.formatMessage("lock.status.success")
4749
override val toLongReport: String = toShortReport
4850
}
4951

@@ -108,16 +110,14 @@ final case class LockFileDiffers(
108110
}
109111

110112
def dumpDependencies(dependencies: Seq[ResolvedDependency]): String = {
111-
dependencies
112-
.map({ dep =>
113-
MessageUtil.formatMessage(
114-
"lock.status.full.dependency",
115-
dep.org,
116-
dep.name,
117-
dep.version,
118-
dep.configurations.toSeq.sorted.mkString(","))
119-
})
120-
.mkString("\n")
113+
val table =
114+
new TableFormatter(None, prefix = " ", stripTrailingNewline = true)
115+
116+
dependencies foreach { dep =>
117+
table.addRow(s"${dep.org}:${dep.name}", s"(${dep.configurations.mkString(",")})", dep.version)
118+
}
119+
120+
table.toString()
121121
}
122122

123123
if (addedDependencies.nonEmpty) {
@@ -134,32 +134,30 @@ final case class LockFileDiffers(
134134
dumpDependencies(removedDependencies))
135135
}
136136

137-
if (changedDependencies.nonEmpty) {
138-
val changeDetails = changedDependencies map { change =>
139-
val key = (change.versionChanged, change.configurationsChanged) match {
140-
case (true, true) => "lock.status.full.dependency.changed.all"
141-
case (true, false) => "lock.status.full.dependency.changed.version"
142-
case (false, true) => "lock.status.full.dependency.changed.configs"
143-
case _ => "lock.status.full.dependency"
144-
}
145-
146-
MessageUtil.formatMessage(
147-
key,
148-
change.org,
149-
change.name,
137+
def dumpChanges(changes: Seq[ChangedDependency]): String = {
138+
val table =
139+
new TableFormatter(None, prefix = " ", stripTrailingNewline = true)
140+
141+
changes foreach { change =>
142+
table.addRow(
143+
s"${change.org}:${change.name}",
144+
s"(${change.oldConfigurations.mkString(",")})",
145+
if (change.configurationsChanged)
146+
s"-> (${change.newConfigurations.mkString(",")})"
147+
else "",
150148
change.oldVersion,
151-
change.newVersion,
152-
change.oldConfigurations.mkString(","),
153-
change.newConfigurations.mkString(",")
149+
if (change.versionChanged) s"-> ${change.newVersion}" else ""
154150
)
155-
156-
// TODO arts
157151
}
158152

153+
table.toString()
154+
}
155+
156+
if (changedDependencies.nonEmpty) {
159157
errors += MessageUtil.formatPlural(
160158
"lock.status.full.dependencies.changed",
161159
changedDependencies.size,
162-
changeDetails.mkString("\n"))
160+
dumpChanges(changedDependencies))
163161
}
164162

165163
MessageUtil.formatMessage("lock.status.failed.long", errors.mkString("\n"))

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
129129
val expected =
130130
"""Dependency lock check failed:
131131
| 1 dependency added:
132-
| com.example:artifact:1.0 (compile,test)""".stripMargin
132+
| com.example:artifact (compile,test) 1.0""".stripMargin
133133

134134
LockFileMatches.withDependencyChanges(Seq(testDependency()), Nil, Nil).toLongReport shouldBe expected
135135
}
@@ -138,8 +138,8 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
138138
val expected =
139139
"""Dependency lock check failed:
140140
| 2 dependencies removed:
141-
| com.example:artifact:1.0 (compile,test)
142-
| com.example:artifact-2:1.0 (compile,test)""".stripMargin
141+
| com.example:artifact (compile,test) 1.0
142+
| com.example:artifact-2 (compile,test) 1.0""".stripMargin
143143

144144
LockFileMatches
145145
.withDependencyChanges(Nil, Seq(testDependency(), testDependency(name = "artifact-2")), Nil)
@@ -150,7 +150,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
150150
val expected =
151151
"""Dependency lock check failed:
152152
| 1 dependency changed:
153-
| com.example:artifact:[1.0]->[2.0] (compile,test)""".stripMargin
153+
| com.example:artifact (compile,test) 1.0 -> 2.0""".stripMargin
154154

155155
LockFileMatches.withDependencyChanges(Nil, Nil, Seq(testChangedDependency())).toLongReport shouldBe expected
156156
}
@@ -159,7 +159,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
159159
val expected =
160160
"""Dependency lock check failed:
161161
| 1 dependency changed:
162-
| com.example:artifact:1.0 (compile,test)->(compile)""".stripMargin
162+
| com.example:artifact (compile,test) -> (compile) 1.0""".stripMargin
163163

164164
LockFileMatches
165165
.withDependencyChanges(
@@ -173,7 +173,7 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
173173
val expected =
174174
"""Dependency lock check failed:
175175
| 1 dependency changed:
176-
| com.example:artifact:[1.0]->[2.0] (compile,test)->(compile)""".stripMargin
176+
| com.example:artifact (compile,test) -> (compile) 1.0 -> 2.0""".stripMargin
177177

178178
LockFileMatches
179179
.withDependencyChanges(Nil, Nil, Seq(testChangedDependency(newConfigurations = SortedSet("compile"))))
@@ -186,14 +186,14 @@ class LockFileStatusSpec extends AnyFlatSpec with Matchers {
186186
| 1 config added: test1
187187
| 2 configs removed: test2,test3
188188
| 2 dependencies added:
189-
| com.example:artifact1:1.0 (compile)
190-
| com.example:artifact2:1.2 (test)
189+
| com.example:artifact1 (compile) 1.0
190+
| com.example:artifact2 (test) 1.2
191191
| 1 dependency removed:
192-
| com.example:artifact3:3.1.1 (runtime)
192+
| com.example:artifact3 (runtime) 3.1.1
193193
| 3 dependencies changed:
194-
| org.example:version:[1.0]->[2.0] (compile)
195-
| org.example:configs:1.0 (compile,test)->(compile)
196-
| org.example:both:[1.0]->[2.0] (compile)->(compile,test)""".stripMargin
194+
| org.example:version (compile) 1.0 -> 2.0
195+
| org.example:configs (compile,test) -> (compile) 1.0
196+
| org.example:both (compile) -> (compile,test) 1.0 -> 2.0""".stripMargin
197197

198198
val actual = LockFileMatches
199199
.withConfigurationsChanged(Seq("test1"), Seq("test2", "test3"))

0 commit comments

Comments
 (0)