From a89e63f95618b29adf28c7196867118640ad8bca Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Tue, 17 Nov 2015 19:16:02 +0100 Subject: [PATCH] new backend to generate graph directly from sbt data structures, fixes #39 --- .../sbt/graph/DependencyGraphKeys.scala | 1 + .../sbt/graph/DependencyGraphSettings.scala | 16 ++++--- .../sbt/graph/frontend/SbtUpdateReport.scala | 42 +++++++++++++++++++ .../net/virtualvoid/sbt/graph/package.scala | 1 + 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/main/scala/net/virtualvoid/sbt/graph/frontend/SbtUpdateReport.scala diff --git a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphKeys.scala b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphKeys.scala index 06b77eca5..d8ccdf62b 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphKeys.scala +++ b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphKeys.scala @@ -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 \ No newline at end of file diff --git a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala index ea8c9f681..3c5be5790 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala +++ b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala @@ -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(_)) diff --git a/src/main/scala/net/virtualvoid/sbt/graph/frontend/SbtUpdateReport.scala b/src/main/scala/net/virtualvoid/sbt/graph/frontend/SbtUpdateReport.scala new file mode 100644 index 000000000..fe802ef2c --- /dev/null +++ b/src/main/scala/net/virtualvoid/sbt/graph/frontend/SbtUpdateReport.scala @@ -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) + } +} diff --git a/src/main/scala/net/virtualvoid/sbt/graph/package.scala b/src/main/scala/net/virtualvoid/sbt/graph/package.scala index 1fe4e5fc1..41921bcfa 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/package.scala +++ b/src/main/scala/net/virtualvoid/sbt/graph/package.scala @@ -18,4 +18,5 @@ package net.virtualvoid.sbt package object graph { type Edge = (ModuleId, ModuleId) + def Edge(from: ModuleId, to: ModuleId): Edge = from -> to }