Merge pull request #5914 from eed3si9n/wip/dependencygraph_fix

Rename some sbt-dependency-graph keys
This commit is contained in:
eugene yokota 2020-10-02 08:37:03 -04:00 committed by GitHub
commit aa91a1b304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 31 deletions

View File

@ -24,13 +24,12 @@ trait MiniDependencyTreeKeys {
val toFile = inputKey[File]("Writes the task value to the given file") val toFile = inputKey[File]("Writes the task value to the given file")
// internal // internal
private[sbt] val ignoreMissingUpdate = private[sbt] val dependencyTreeIgnoreMissingUpdate =
TaskKey[UpdateReport]("dependencyUpdate", "sbt-dependency-graph version of update") taskKey[UpdateReport]("update used for dependencyTree task")
private[sbt] val moduleGraphStore = private[sbt] val dependencyTreeModuleGraphStore =
TaskKey[ModuleGraph]("module-graph-store", "The stored module-graph from the last run") taskKey[ModuleGraph]("The stored module-graph from the last run")
val whatDependsOn = val whatDependsOn = inputKey[String]("Shows information about what depends on the given module")
InputKey[String]("what-depends-on", "Shows information about what depends on the given module") private[sbt] val dependencyTreeCrossProjectId = settingKey[ModuleID]("")
private[sbt] val crossProjectId = SettingKey[ModuleID]("dependency-graph-cross-project-id")
} }
object MiniDependencyTreeKeys extends MiniDependencyTreeKeys object MiniDependencyTreeKeys extends MiniDependencyTreeKeys
@ -72,7 +71,9 @@ abstract class DependencyTreeKeys {
val dependencyBrowseTree = taskKey[URI]( val dependencyBrowseTree = taskKey[URI](
"Opens an HTML page that can be used to view the dependency tree" "Opens an HTML page that can be used to view the dependency tree"
) )
val dependencyTreeModuleGraph = taskKey[ModuleGraph]("The dependency graph for a project") // 0 was added to avoid conflict with sbt-dependency-tree
private[sbt] val dependencyTreeModuleGraph0 =
taskKey[ModuleGraph]("The dependency graph for a project")
val dependencyList = val dependencyList =
taskKey[Unit]("Prints a list of all dependencies to the console") taskKey[Unit]("Prints a list of all dependencies to the console")

View File

@ -36,23 +36,25 @@ object DependencyTreeSettings {
// disable the cached resolution engine (exposing a scoped `ivyModule` used directly by `updateTask`), as it // disable the cached resolution engine (exposing a scoped `ivyModule` used directly by `updateTask`), as it
// generates artificial module descriptors which are internal to sbt, making it hard to reconstruct the // generates artificial module descriptors which are internal to sbt, making it hard to reconstruct the
// dependency tree // dependency tree
ignoreMissingUpdate / updateOptions := updateOptions.value.withCachedResolution(false), dependencyTreeIgnoreMissingUpdate / updateOptions := updateOptions.value
ignoreMissingUpdate / ivyConfiguration := { .withCachedResolution(false),
// inTask will make sure the new definition will pick up `updateOptions in ignoreMissingUpdate` dependencyTreeIgnoreMissingUpdate / ivyConfiguration := {
inTask(ignoreMissingUpdate, Classpaths.mkIvyConfiguration).value // inTask will make sure the new definition will pick up `updateOptions in dependencyTreeIgnoreMissingUpdate`
inTask(dependencyTreeIgnoreMissingUpdate, Classpaths.mkIvyConfiguration).value
}, },
ignoreMissingUpdate / ivyModule := { dependencyTreeIgnoreMissingUpdate / ivyModule := {
// concatenating & inlining ivySbt & ivyModule default task implementations, as `SbtAccess.inTask` does // concatenating & inlining ivySbt & ivyModule default task implementations, as `SbtAccess.inTask` does
// NOT correctly force the scope when applied to `TaskKey.toTask` instances (as opposed to raw // NOT correctly force the scope when applied to `TaskKey.toTask` instances (as opposed to raw
// implementations like `Classpaths.mkIvyConfiguration` or `Classpaths.updateTask`) // implementations like `Classpaths.mkIvyConfiguration` or `Classpaths.updateTask`)
val is = new IvySbt((ivyConfiguration in ignoreMissingUpdate).value) val is = new IvySbt((ivyConfiguration in dependencyTreeIgnoreMissingUpdate).value)
new is.Module(moduleSettings.value) new is.Module(moduleSettings.value)
}, },
// don't fail on missing dependencies // don't fail on missing dependencies
ignoreMissingUpdate / updateConfiguration := updateConfiguration.value.withMissingOk(true), dependencyTreeIgnoreMissingUpdate / updateConfiguration := updateConfiguration.value
ignoreMissingUpdate := { .withMissingOk(true),
dependencyTreeIgnoreMissingUpdate := {
// inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in ignoreMissingUpdate` // inTask will make sure the new definition will pick up `ivyModule/updateConfiguration in ignoreMissingUpdate`
inTask(ignoreMissingUpdate, Classpaths.updateTask).value inTask(dependencyTreeIgnoreMissingUpdate, Classpaths.updateTask).value
}, },
) )
@ -62,19 +64,22 @@ object DependencyTreeSettings {
*/ */
lazy val baseBasicReportingSettings: Seq[Def.Setting[_]] = lazy val baseBasicReportingSettings: Seq[Def.Setting[_]] =
Seq( Seq(
crossProjectId := CrossVersion(scalaVersion.value, scalaBinaryVersion.value)( dependencyTreeCrossProjectId := CrossVersion(scalaVersion.value, scalaBinaryVersion.value)(
projectID.value projectID.value
), ),
dependencyTreeModuleGraph := { dependencyTreeModuleGraph0 := {
val sv = scalaVersion.value val sv = scalaVersion.value
val g = ignoreMissingUpdate.value val g = dependencyTreeIgnoreMissingUpdate.value
.configuration(configuration.value) .configuration(configuration.value)
.map(report => SbtUpdateReport.fromConfigurationReport(report, crossProjectId.value)) .map(
report =>
SbtUpdateReport.fromConfigurationReport(report, dependencyTreeCrossProjectId.value)
)
.getOrElse(ModuleGraph.empty) .getOrElse(ModuleGraph.empty)
if (dependencyTreeIncludeScalaLibrary.value) g if (dependencyTreeIncludeScalaLibrary.value) g
else GraphTransformations.ignoreScalaLibrary(sv, g) else GraphTransformations.ignoreScalaLibrary(sv, g)
}, },
moduleGraphStore := (dependencyTreeModuleGraph storeAs moduleGraphStore triggeredBy dependencyTreeModuleGraph).value, dependencyTreeModuleGraphStore := (dependencyTreeModuleGraph0 storeAs dependencyTreeModuleGraphStore triggeredBy dependencyTreeModuleGraph0).value,
) ++ renderingTaskSettings(dependencyTree, rendering.AsciiTree.asciiTree _) ) ++ renderingTaskSettings(dependencyTree, rendering.AsciiTree.asciiTree _)
/** /**
@ -95,7 +100,7 @@ object DependencyTreeSettings {
target.value / "dependencies-%s.dot".format(config.toString) target.value / "dependencies-%s.dot".format(config.toString)
}, },
dependencyDot / asString := rendering.DOT.dotGraph( dependencyDot / asString := rendering.DOT.dotGraph(
dependencyTreeModuleGraph.value, dependencyTreeModuleGraph0.value,
dependencyDotHeader.value, dependencyDotHeader.value,
dependencyDotNodeLabel.value, dependencyDotNodeLabel.value,
rendering.DOT.AngleBrackets rendering.DOT.AngleBrackets
@ -118,7 +123,7 @@ object DependencyTreeSettings {
dependencyGraphML := dependencyGraphMLTask.value, dependencyGraphML := dependencyGraphMLTask.value,
whatDependsOn := { whatDependsOn := {
val ArtifactPattern(org, name, versionFilter) = artifactPatternParser.parsed val ArtifactPattern(org, name, versionFilter) = artifactPatternParser.parsed
val graph = dependencyTreeModuleGraph.value val graph = dependencyTreeModuleGraph0.value
val modules = val modules =
versionFilter match { versionFilter match {
case Some(version) => GraphModuleId(org, name, version) :: Nil case Some(version) => GraphModuleId(org, name, version) :: Nil
@ -153,7 +158,7 @@ object DependencyTreeSettings {
val str = (key / asString).value val str = (key / asString).value
s.log.info(str) s.log.info(str)
}, },
key / asString := renderer(dependencyTreeModuleGraph.value), key / asString := renderer(dependencyTreeModuleGraph0.value),
key / toFile := { key / toFile := {
val (targetFile, force) = targetFileAndForceParser.parsed val (targetFile, force) = targetFileAndForceParser.parsed
writeToFile(key.key.label, (asString in key).value, targetFile, force, streams.value) writeToFile(key.key.label, (asString in key).value, targetFile, force, streams.value)
@ -163,7 +168,7 @@ object DependencyTreeSettings {
def dependencyGraphMLTask = def dependencyGraphMLTask =
Def.task { Def.task {
val resultFile = dependencyGraphMLFile.value val resultFile = dependencyGraphMLFile.value
val graph = dependencyTreeModuleGraph.value val graph = dependencyTreeModuleGraph0.value
rendering.GraphML.saveAsGraphML(graph, resultFile.getAbsolutePath) rendering.GraphML.saveAsGraphML(graph, resultFile.getAbsolutePath)
streams.value.log.info("Wrote dependency graph to '%s'" format resultFile) streams.value.log.info("Wrote dependency graph to '%s'" format resultFile)
resultFile resultFile
@ -171,7 +176,7 @@ object DependencyTreeSettings {
def browseGraphHTMLTask = def browseGraphHTMLTask =
Def.task { Def.task {
val graph = dependencyTreeModuleGraph.value val graph = dependencyTreeModuleGraph0.value
val dotGraph = rendering.DOT.dotGraph( val dotGraph = rendering.DOT.dotGraph(
graph, graph,
dependencyDotHeader.value, dependencyDotHeader.value,
@ -185,7 +190,7 @@ object DependencyTreeSettings {
def browseTreeHTMLTask = def browseTreeHTMLTask =
Def.task { Def.task {
val graph = dependencyTreeModuleGraph.value val graph = dependencyTreeModuleGraph0.value
val renderedTree = TreeView.createJson(graph) val renderedTree = TreeView.createJson(graph)
val link = TreeView.createLink(renderedTree, target.value) val link = TreeView.createLink(renderedTree, target.value)
streams.value.log.info(s"HTML tree written to $link") streams.value.log.info(s"HTML tree written to $link")
@ -234,7 +239,7 @@ object DependencyTreeSettings {
import sbt.internal.util.complete.DefaultParsers._ import sbt.internal.util.complete.DefaultParsers._
val artifactPatternParser: Def.Initialize[State => Parser[ArtifactPattern]] = val artifactPatternParser: Def.Initialize[State => Parser[ArtifactPattern]] =
Keys.resolvedScoped { ctx => (state: State) => Keys.resolvedScoped { ctx => (state: State) =>
val graph = Defaults.loadFromContext(moduleGraphStore, ctx, state) getOrElse ModuleGraph( val graph = Defaults.loadFromContext(dependencyTreeModuleGraphStore, ctx, state) getOrElse ModuleGraph(
Nil, Nil,
Nil Nil
) )
@ -255,7 +260,7 @@ object DependencyTreeSettings {
} }
.reduceOption(_ | _) .reduceOption(_ | _)
.getOrElse { .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. // If the dependencyTreeModuleGraphStore 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( ((Space ~> token(StringBasic, "<organization>")) ~ (Space ~> token(
StringBasic, StringBasic,
"<module>" "<module>"

View File

@ -1,3 +1,3 @@
# to initialize parser with deps # to initialize parser with deps
> Compile/dependencyTreeModuleGraph > Compile/dependencyTreeModuleGraph0
> check > check