new backend to generate graph directly from sbt data structures, fixes #39

This commit is contained in:
Johannes Rudolph 2015-11-17 19:16:02 +01:00
parent 191d12aa7a
commit a89e63f956
4 changed files with 55 additions and 5 deletions

View File

@ -55,6 +55,7 @@ trait DependencyGraphKeys {
// internal
private[graph] val moduleGraphStore = TaskKey[ModuleGraph]("module-graph-store", "The stored module-graph from the last run")
private[graph] val whatDependsOn = InputKey[Unit]("what-depends-on", "Shows information about what depends on the given module")
private[graph] val crossProjectId = SettingKey[ModuleID]("dependency-graph-cross-project-id")
}
object DependencyGraphKeys extends DependencyGraphKeys

View File

@ -16,6 +16,7 @@
package net.virtualvoid.sbt.graph
import net.virtualvoid.sbt.graph.frontend.SbtUpdateReport
import sbt._
import Keys._
@ -51,12 +52,11 @@ object DependencyGraphSettings {
def ivyReportForConfig(config: Configuration) = inConfig(config)(Seq(
ivyReport <<= ivyReportFunction map (_(config.toString)) dependsOn (ignoreMissingUpdate),
moduleGraph <<= ivyReport map (absoluteReportPath.andThen(frontend.IvyReport.fromReportFile)),
crossProjectId <<= (scalaVersion, scalaBinaryVersion, projectID)((sV, sBV, id) CrossVersion(sV, sBV)(id)),
moduleGraph <<= sbtUpdateReportGraph,
moduleGraph <<= (scalaVersion, moduleGraph, filterScalaLibrary) map { (scalaV, graph, filter)
if (filter)
GraphTransformations.ignoreScalaLibrary(scalaV, graph)
else
graph
if (filter) GraphTransformations.ignoreScalaLibrary(scalaV, graph)
else graph
},
moduleGraphStore <<= moduleGraph storeAs moduleGraphStore triggeredBy moduleGraph,
asciiGraph <<= moduleGraph map rendering.AsciiGraph.asciiGraph,
@ -100,6 +100,12 @@ object DependencyGraphSettings {
},
licenseInfo <<= (moduleGraph, streams) map showLicenseInfo))
def ivyReportGraph = ivyReport map (absoluteReportPath.andThen(frontend.IvyReport.fromReportFile))
def sbtUpdateReportGraph =
(ignoreMissingUpdate, crossProjectId, configuration) map { (update, root, config)
SbtUpdateReport.fromConfigurationReport(update.configuration(config.name).get, root)
}
def printAsciiGraphTask =
(streams, asciiGraph) map (_.log.info(_))

View File

@ -0,0 +1,42 @@
/*
* Copyright 2015 Johannes Rudolph
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.virtualvoid.sbt.graph
package frontend
import sbt._
object SbtUpdateReport {
def fromConfigurationReport(report: ConfigurationReport, rootInfo: sbt.ModuleID): ModuleGraph = {
implicit def id(sbtId: sbt.ModuleID): ModuleId = ModuleId(sbtId.organization, sbtId.name, sbtId.revision)
def moduleEdges(orgArt: OrganizationArtifactReport): Seq[(Module, Seq[Edge])] = {
val chosenVersion = orgArt.modules.find(!_.evicted).map(_.module.revision)
orgArt.modules.map(moduleEdge(chosenVersion))
}
def moduleEdge(chosenVersion: Option[String])(report: ModuleReport): (Module, Seq[Edge]) = {
val evictedByVersion = if (report.evicted) chosenVersion else None
(Module(report.module, license = report.licenses.headOption.map(_._1), evictedByVersion = evictedByVersion, error = report.problem),
report.callers.map(caller Edge(caller.caller, report.module)))
}
val (nodes, edges) = report.details.flatMap(moduleEdges).unzip
val root = Module(rootInfo)
ModuleGraph(root +: nodes, edges.flatten)
}
}

View File

@ -18,4 +18,5 @@ package net.virtualvoid.sbt
package object graph {
type Edge = (ModuleId, ModuleId)
def Edge(from: ModuleId, to: ModuleId): Edge = from -> to
}