Don't fail in parsing when whatDependsOn is called without running any other command first, fixes #95

If no other command was run first, tab completion runs now in degraded mode
again, not showing any concrete suggestions but just the general syntax.

This probably regressed in #155 where I probably couldn't remember the reason
for the fallback...
This commit is contained in:
Johannes Rudolph 2018-08-23 16:52:04 +02:00
parent cf7926d4f5
commit 6b176a9ca1
No known key found for this signature in database
GPG Key ID: 4D293A24CCD39E19
4 changed files with 66 additions and 1 deletions

View File

@ -197,7 +197,13 @@ object DependencyGraphSettings {
case ((org, name), version) ArtifactPattern(org, name, version)
}
}
.reduceOption(_ | _).getOrElse(failure("No dependencies found"))
.reduceOption(_ | _).getOrElse {
// If the moduleGraphStore couldn't be loaded because no dependency tree command was run before, we should still provide a parser for the command.
((Space ~> token(StringBasic, "<organization>")) ~ (Space ~> token(StringBasic, "<module>")) ~ (Space ~> token(StringBasic, "<version?>")).?).map {
case ((org, mod), version)
ArtifactPattern(org, mod, version)
}
}
}
// This is to support 0.13.8's InlineConfigurationWithExcludes while not forcing 0.13.8

View File

@ -0,0 +1,56 @@
version := "0.1.0-SNAPSHOT"
organization := "default"
name := "whatDependsOn"
scalaVersion := "2.9.1"
resolvers += "typesafe maven" at "https://repo.typesafe.com/typesafe/maven-releases/"
libraryDependencies ++= Seq(
"com.codahale" % "jerkson_2.9.1" % "0.5.0",
"org.codehaus.jackson" % "jackson-mapper-asl" % "1.9.10" // as another version of asl
)
val check = TaskKey[Unit]("check")
check := {
def sanitize(str: String): String = str.split('\n').map(_.trim).mkString("\n")
def checkOutput(output: String, expected: String): Unit =
require(sanitize(expected) == sanitize(output), s"Tree should have been [\n${sanitize(expected)}\n] but was [\n${sanitize(output)}\n]")
val withVersion =
(whatDependsOn in Compile)
.toTask(" org.codehaus.jackson jackson-core-asl 1.9.11")
.value
val expectedGraphWithVersion =
"""org.codehaus.jackson:jackson-core-asl:1.9.11
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
| |
| +-org.codehaus.jackson:jackson-mapper-asl:1.9.11
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
| |
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
| """.stripMargin
checkOutput(withVersion, expectedGraphWithVersion)
val withoutVersion =
(whatDependsOn in Compile)
.toTask(" org.codehaus.jackson jackson-mapper-asl")
.value
val expectedGraphWithoutVersion =
"""org.codehaus.jackson:jackson-mapper-asl:1.9.11
| +-com.codahale:jerkson_2.9.1:0.5.0 [S]
| | +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
| |
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
|
|org.codehaus.jackson:jackson-mapper-asl:1.9.10 (evicted by: 1.9.11)
| +-default:whatdependson_2.9.1:0.1.0-SNAPSHOT [S]
| """.stripMargin
checkOutput(withoutVersion, expectedGraphWithoutVersion)
}

View File

@ -0,0 +1 @@
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % sys.props("project.version"))

View File

@ -0,0 +1,2 @@
# same as whatDependsOn test but without the initialization to prime the parser
> check