From 279dea35147d286724aaf0365a18c98e60395521 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Mon, 14 Aug 2017 15:36:50 +0200 Subject: [PATCH] only provide `dependencyGraph` / `asciiGraph` in sbt 0.13 --- build.sbt | 9 +++++-- .../sbt/graph/rendering/AsciiGraph.scala | 22 ++++++++++++++++ .../sbt/graph/rendering/AsciiGraph.scala | 22 ++++++++++++++++ .../sbt/graph/DependencyGraphSettings.scala | 25 ++----------------- 4 files changed, 53 insertions(+), 25 deletions(-) rename src/main/{scala => scala-sbt-0.13}/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala (62%) create mode 100644 src/main/scala-sbt-1.0/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala diff --git a/build.sbt b/build.sbt index 6b4943943..ab195ffae 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,13 @@ ScriptedPlugin.scriptedSettings -libraryDependencies += "com.github.mdr" %% "ascii-graphs" % "0.0.3" +libraryDependencies ++= { + if (sbtVersion.value startsWith "0.13") + Seq("com.github.mdr" %% "ascii-graphs" % "0.0.3") + else + Nil +} -libraryDependencies += "org.specs2" %% "specs2" % "2.3.11" % "test" +libraryDependencies += "org.specs2" %% "specs2-core" % "3.9.1" % "test" scalacOptions ++= Seq("-deprecation", "-unchecked") diff --git a/src/main/scala/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala b/src/main/scala-sbt-0.13/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala similarity index 62% rename from src/main/scala/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala rename to src/main/scala-sbt-0.13/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala index 8da025149..701fdce7d 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala +++ b/src/main/scala-sbt-0.13/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala @@ -18,6 +18,8 @@ package net.virtualvoid.sbt.graph package rendering import com.github.mdr.ascii.layout._ +import net.virtualvoid.sbt.graph.DependencyGraphKeys._ +import sbt.Keys._ object AsciiGraph { def asciiGraph(graph: ModuleGraph): String = @@ -35,4 +37,24 @@ object AsciiGraph { val edges = moduleGraph.edges.toList.map { case (from, to) ⇒ (renderVertex(moduleGraph.module(from)), renderVertex(moduleGraph.module(to))) } Graph(vertices, edges) } + + def asciiGraphSetttings = Seq[sbt.Def.Setting[_]]( + DependencyGraphKeys.asciiGraph := asciiGraph(moduleGraph.value), + dependencyGraph := { + val force = DependencyGraphSettings.shouldForceParser.parsed + val log = streams.value.log + if (force || moduleGraph.value.nodes.size < 15) { + log.info(rendering.AsciiGraph.asciiGraph(moduleGraph.value)) + log.info("\n\n") + log.info("Note: The old tree layout is still available by using `dependency-tree`") + } + + log.info(rendering.AsciiTree.asciiTree(moduleGraph.value)) + + if (!force) { + log.info("\n") + log.info("Note: The graph was estimated to be too big to display (> 15 nodes). Use `sbt 'dependency-graph --force'` (with the single quotes) to force graph display.") + } + } + ) } diff --git a/src/main/scala-sbt-1.0/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala b/src/main/scala-sbt-1.0/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala new file mode 100644 index 000000000..b9e187a3b --- /dev/null +++ b/src/main/scala-sbt-1.0/net/virtualvoid/sbt/graph/rendering/AsciiGraph.scala @@ -0,0 +1,22 @@ +/* + * Copyright 2017 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 rendering + +object AsciiGraph { + def asciiGraphSetttings = Seq.empty[sbt.Def.Setting[_]] +} \ 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 ab0fd6779..790453585 100644 --- a/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala +++ b/src/main/scala/net/virtualvoid/sbt/graph/DependencyGraphSettings.scala @@ -18,15 +18,11 @@ package net.virtualvoid.sbt.graph import sbt._ import Keys._ - import CrossVersion._ - import sbt.complete.Parser - import org.apache.ivy.core.resolve.ResolveOptions - import net.virtualvoid.sbt.graph.backend.{ IvyReport, SbtUpdateReport } -import net.virtualvoid.sbt.graph.rendering.DagreHTML +import net.virtualvoid.sbt.graph.rendering.{ AsciiGraph, DagreHTML } import net.virtualvoid.sbt.graph.util.IOUtil object DependencyGraphSettings { @@ -55,23 +51,6 @@ object DependencyGraphSettings { else graph }, moduleGraphStore <<= moduleGraph storeAs moduleGraphStore triggeredBy moduleGraph, - asciiGraph <<= moduleGraph map rendering.AsciiGraph.asciiGraph, - dependencyGraph <<= InputTask(shouldForceParser) { force ⇒ - (force, moduleGraph, streams) map { (force, graph, streams) ⇒ - if (force || graph.nodes.size < 15) { - streams.log.info(rendering.AsciiGraph.asciiGraph(graph)) - streams.log.info("\n\n") - streams.log.info("Note: The old tree layout is still available by using `dependency-tree`") - } else { - streams.log.info(rendering.AsciiTree.asciiTree(graph)) - - if (!force) { - streams.log.info("\n") - streams.log.info("Note: The graph was estimated to be too big to display (> 15 nodes). Use `sbt 'dependency-graph --force'` (with the single quotes) to force graph display.") - } - } - } - }, asciiTree <<= moduleGraph map rendering.AsciiTree.asciiTree, dependencyTree <<= print(asciiTree), dependencyGraphMLFile <<= target / "dependencies-%s.graphml".format(config.toString), @@ -101,7 +80,7 @@ object DependencyGraphSettings { streams.log.info(rendering.AsciiTree.asciiTree(GraphTransformations.reverseGraphStartingAt(graph, module))) } }, - licenseInfo <<= (moduleGraph, streams) map showLicenseInfo)) + licenseInfo <<= (moduleGraph, streams) map showLicenseInfo) ++ AsciiGraph.asciiGraphSetttings) def ivyReportFunctionTask = (sbtVersion, target, projectID, ivyModule, appConfiguration, streams) map { (sbtV, target, projectID, ivyModule, config, streams) ⇒