Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.

Commit 1d8649e

Browse files
authored
Merge pull request #159 from jrudolph/fix-95
Don't fail in parsing when whatDependsOn is called without running any other command first, fixes #95
2 parents 9a5d519 + 6b176a9 commit 1d8649e

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ object DependencyGraphSettings {
197197
case ((org, name), version) ArtifactPattern(org, name, version)
198198
}
199199
}
200-
.reduceOption(_ | _).getOrElse(failure("No dependencies found"))
200+
.reduceOption(_ | _).getOrElse {
201+
// If the moduleGraphStore couldn't be loaded because no dependency tree command was run before, we should still provide a parser for the command.
202+
((Space ~> token(StringBasic, "<organization>")) ~ (Space ~> token(StringBasic, "<module>")) ~ (Space ~> token(StringBasic, "<version?>")).?).map {
203+
case ((org, mod), version)
204+
ArtifactPattern(org, mod, version)
205+
}
206+
}
201207
}
202208

203209
// This is to support 0.13.8's InlineConfigurationWithExcludes while not forcing 0.13.8
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version := "0.1.0-SNAPSHOT"
2+
3+
organization := "default"
4+
5+
name := "whatDependsOn"
6+
7+
scalaVersion := "2.9.1"
8+
9+
resolvers += "typesafe maven" at "https://repo.typesafe.com/typesafe/maven-releases/"
10+
11+
libraryDependencies ++= Seq(
12+
"com.codahale" % "jerkson_2.9.1" % "0.5.0",
13+
"org.codehaus.jackson" % "jackson-mapper-asl" % "1.9.10" // as another version of asl
14+
)
15+
16+
val check = TaskKey[Unit]("check")
17+
18+
check := {
19+
def sanitize(str: String): String = str.split('\n').map(_.trim).mkString("\n")
20+
def checkOutput(output: String, expected: String): Unit =
21+
require(sanitize(expected) == sanitize(output), s"Tree should have been [\n${sanitize(expected)}\n] but was [\n${sanitize(output)}\n]")
22+
23+
val withVersion =
24+
(whatDependsOn in Compile)
25+
.toTask(" org.codehaus.jackson jackson-core-asl 1.9.11")
26+
.value
27+
val expectedGraphWithVersion =
28+
"""org.codehaus.jackson:jackson-core-asl:1.9.11
29+
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
30+
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
31+
| |
32+
| +-org.codehaus.jackson:jackson-mapper-asl:1.9.11
33+
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
34+
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
35+
| |
36+
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
37+
| """.stripMargin
38+
39+
checkOutput(withVersion, expectedGraphWithVersion)
40+
41+
val withoutVersion =
42+
(whatDependsOn in Compile)
43+
.toTask(" org.codehaus.jackson jackson-mapper-asl")
44+
.value
45+
val expectedGraphWithoutVersion =
46+
"""org.codehaus.jackson:jackson-mapper-asl:1.9.11
47+
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
48+
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
49+
| |
50+
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
51+
|
52+
|org.codehaus.jackson:jackson-mapper-asl:1.9.10 (evicted by: 1.9.11)
53+
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
54+
| """.stripMargin
55+
checkOutput(withoutVersion, expectedGraphWithoutVersion)
56+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# same as whatDependsOn test but without the initialization to prime the parser
2+
> check

0 commit comments

Comments
 (0)