From acec2187d57aad322ce25773bacf18f256297789 Mon Sep 17 00:00:00 2001 From: Cosmin Basca Date: Tue, 26 Aug 2014 15:01:20 +0200 Subject: [PATCH 1/4] simple migration to scala 2.11.2 (and 2.10.4), support for scala 2.9.X has been dropped. tests pass on both scala versions fixed resource loading for large graphs (correct utf-8 encoding specified explicitly - otherwise the system default one is chosen) bumped version to 0.0.7 updated sbt plugins included sbt assembly plugin support switched to sbt 0.13.0 all tests pass on my mac box (10.9.4) --- build.sbt | 20 +++++++++++------- project/build.properties | 2 +- project/plugins.sbt | 21 +++++++++++++------ .../com/github/mdr/ascii/util/Utils.scala | 8 +++++-- .../diagram/parser/DiagramParserTest.scala | 4 ++-- .../mdr/ascii/graph/GraphGenerators.scala | 7 +++++-- .../graph/TopologicalSortSpecification.scala | 5 ----- .../mdr/ascii/graph/TopologicalSortTest.scala | 4 ++-- .../ascii/layout/Issue3InfiniteLoopTest.scala | 4 ++-- .../mdr/ascii/layout/RoundTripTest.scala | 4 ++-- .../cycles/CycleRemoverSpecification.scala | 4 ---- .../layout/cycles/CycleRemoverTest.scala | 4 ++-- .../ascii/layout/cycles/GraphReflowTest.scala | 4 ++-- .../layering/AssignLayersSpecification.scala | 4 ---- .../layering/CrossingCalculatorTest.scala | 4 ++-- .../LongestDistanceToSinkSpecification.scala | 5 ----- .../layering/LongestDistanceToSinkTest.scala | 4 ++-- .../github/mdr/ascii/util/QuadTreeTest.scala | 4 ++-- 18 files changed, 58 insertions(+), 54 deletions(-) diff --git a/build.sbt b/build.sbt index 33ed0cb..f00768d 100644 --- a/build.sbt +++ b/build.sbt @@ -1,20 +1,26 @@ +import AssemblyKeys._ + +assemblySettings + name := "ascii-graphs" organization := "com.github.mdr" -version := "0.0.6" +version := "0.0.7" + +scalaVersion := "2.11.2" -scalaVersion := "2.10.1" +crossScalaVersions := Seq("2.10.4", "2.11.2") -crossScalaVersions := Seq("2.9.1", "2.9.2", "2.10.1") +scalacOptions ++= Seq("-optimize", "-Yinline-warnings", "-feature", "-deprecation") -scalacOptions ++= Seq("-deprecation") +javacOptions ++= Seq("-source", "1.7", "-target", "1.7") -javacOptions ++= Seq("-source", "1.6", "-target", "1.6") +libraryDependencies ++= Seq() -libraryDependencies += "org.scalatest" %% "scalatest" % "1.9.1" % "test" +libraryDependencies += ("org.scalatest" %% "scalatest" % "2.1.3" % "test") -libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.10.1" % "test" +libraryDependencies += ("org.scalacheck" %% "scalacheck" % "1.11.5" % "test") // Screen-sized dependency graph: // libraryDependencies += "org.vert-x" % "vertx-core" % "1.3.1.final" diff --git a/project/build.properties b/project/build.properties index 9b860e2..0974fce 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.12.3 +sbt.version=0.13.0 diff --git a/project/plugins.sbt b/project/plugins.sbt index 233bdbd..846ebfe 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,11 +1,20 @@ -addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0") +logLevel := Level.Warn + +resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns) + +resolvers ++= Seq( + "Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots", + "Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases" +) -addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.3") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") + +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0") -// addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4-SNAPSHOT") +addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0") -addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8") +addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4") -addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.4.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.2") -addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.0.1") +addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0") diff --git a/src/main/scala/com/github/mdr/ascii/util/Utils.scala b/src/main/scala/com/github/mdr/ascii/util/Utils.scala index 4a1c23e..7333dd1 100644 --- a/src/main/scala/com/github/mdr/ascii/util/Utils.scala +++ b/src/main/scala/com/github/mdr/ascii/util/Utils.scala @@ -1,5 +1,7 @@ package com.github.mdr.ascii.util +import java.net.URL + import scala.annotation.tailrec import scala.io.Source @@ -21,7 +23,9 @@ object Utils { } def adjacentPairs[T](xs: List[T]): List[(T, T)] = xs zip xs.drop(1) + def adjacentTriples[T](xs: List[T]): List[(T, T, T)] = xs zip xs.drop(1) zip xs.drop(2) map { case ((x, y), z) ⇒ (x, y, z) } + def adjacentPairsWithPreviousAndNext[T](xs: List[T]): List[(Option[T], T, T, Option[T])] = (None :: xs.init.map(Some(_))) zip xs zip xs.drop(1) zip (xs.drop(2).map(Some(_)) :+ None) map { case (((x, y), z), u) ⇒ (x, y, z, u) @@ -53,8 +57,8 @@ object Utils { } def getResourceAsString(path: String): String = { - val inputStream = getClass.getResourceAsStream(path) - Source.fromInputStream(inputStream).getLines.mkString("\n") + val url: URL = getClass.getResource(path) + Source.fromURL(url, "utf-8").mkString } /** diff --git a/src/test/scala/com/github/mdr/ascii/diagram/parser/DiagramParserTest.scala b/src/test/scala/com/github/mdr/ascii/diagram/parser/DiagramParserTest.scala index ddc5875..c596e64 100644 --- a/src/test/scala/com/github/mdr/ascii/diagram/parser/DiagramParserTest.scala +++ b/src/test/scala/com/github/mdr/ascii/diagram/parser/DiagramParserTest.scala @@ -1,13 +1,13 @@ package com.github.mdr.ascii.diagram.parser import org.scalatest.matchers.ShouldMatchers -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import com.github.mdr.ascii.diagram.Diagram import com.github.mdr.ascii.diagram.Box import com.github.mdr.ascii.util.Utils import scala.io.Source -class GraphDiagramParserTest extends FlatSpec with ShouldMatchers { +class GraphDiagramParserTest extends FlatSpec with Matchers { "Parser" should "parse labels" in { diff --git a/src/test/scala/com/github/mdr/ascii/graph/GraphGenerators.scala b/src/test/scala/com/github/mdr/ascii/graph/GraphGenerators.scala index d2f3757..a94c904 100644 --- a/src/test/scala/com/github/mdr/ascii/graph/GraphGenerators.scala +++ b/src/test/scala/com/github/mdr/ascii/graph/GraphGenerators.scala @@ -1,13 +1,16 @@ package com.github.mdr.ascii.graph import org.scalacheck._ -import org.scalacheck.Gen.Params +import org.scalacheck.Gen.Parameters import scala.util.Random import com.github.mdr.ascii.layout.cycles.CycleRemover object GraphGenerators { - implicit val graphGen: Gen[Graph[String]] = Gen { p: Params ⇒ Some(RandomGraph.randomGraph(new Random(p.rng))) } + implicit val graphGen: Gen[Graph[String]] = Gen.parameterized { + p: Parameters ⇒ + RandomGraph.randomGraph(p.rng) + } implicit val arbitraryGraph = Arbitrary(graphGen) diff --git a/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortSpecification.scala b/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortSpecification.scala index b28764e..50a6c87 100644 --- a/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortSpecification.scala +++ b/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortSpecification.scala @@ -1,12 +1,7 @@ package com.github.mdr.ascii.graph -import org.scalacheck.Arbitrary -import org.scalacheck.Gen -import org.scalacheck.Gen.Params import org.scalacheck.Prop.forAll import org.scalacheck.Properties -import org.scalacheck.Shrink -import com.github.mdr.ascii.util.Utils import com.github.mdr.ascii.graph.GraphGenerators._ import com.github.mdr.ascii.layout.cycles.CycleRemover diff --git a/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortTest.scala b/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortTest.scala index ccdaa2e..6c67d57 100644 --- a/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortTest.scala +++ b/src/test/scala/com/github/mdr/ascii/graph/TopologicalSortTest.scala @@ -1,10 +1,10 @@ package com.github.mdr.ascii.graph -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import org.scalatest.prop.Checkers -class TopologicalSortTest extends FlatSpec with ShouldMatchers with Checkers { +class TopologicalSortTest extends FlatSpec with Matchers with Checkers { check(""" +-+ +-+ diff --git a/src/test/scala/com/github/mdr/ascii/layout/Issue3InfiniteLoopTest.scala b/src/test/scala/com/github/mdr/ascii/layout/Issue3InfiniteLoopTest.scala index da17a30..1a09ee6 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/Issue3InfiniteLoopTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/Issue3InfiniteLoopTest.scala @@ -1,11 +1,11 @@ package com.github.mdr.ascii.layout import org.scalatest.matchers.ShouldMatchers -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import com.github.mdr.ascii.graph.Graph // https://github.com/mdr/ascii-graphs/issues/3 -class Issue3InfiniteLoopTest extends FlatSpec with ShouldMatchers { +class Issue3InfiniteLoopTest extends FlatSpec with Matchers { "Layouter" should "not go into an infinite loop" in { val v = Set("1", "2", "3", "7", "9") diff --git a/src/test/scala/com/github/mdr/ascii/layout/RoundTripTest.scala b/src/test/scala/com/github/mdr/ascii/layout/RoundTripTest.scala index 784dbe1..27abf3e 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/RoundTripTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/RoundTripTest.scala @@ -1,11 +1,11 @@ package com.github.mdr.ascii.layout -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.layout.RoundTripSpecification._ -class RoundTripTest extends FlatSpec with ShouldMatchers { +class RoundTripTest extends FlatSpec with Matchers { "Round trip" should ("not overwrite an arrow") in { checkRoundTrip(Graph.fromDiagram(""" diff --git a/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverSpecification.scala b/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverSpecification.scala index 7b356c6..2200544 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverSpecification.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverSpecification.scala @@ -2,12 +2,8 @@ package com.github.mdr.ascii.layout.cycles import scala.util.Random._ -import org.scalacheck.Arbitrary -import org.scalacheck.Gen -import org.scalacheck.Gen.Params import org.scalacheck.Prop.forAll import org.scalacheck.Properties -import org.scalacheck.Shrink import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.graph.GraphUtils diff --git a/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverTest.scala b/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverTest.scala index 201c4b1..89494ad 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/cycles/CycleRemoverTest.scala @@ -1,13 +1,13 @@ package com.github.mdr.ascii.layout.cycles -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.graph.GraphUtils import com.github.mdr.ascii.util.Utils -class CycleRemoverTest extends FlatSpec with ShouldMatchers { +class CycleRemoverTest extends FlatSpec with Matchers { check(""" +-+ +-+ diff --git a/src/test/scala/com/github/mdr/ascii/layout/cycles/GraphReflowTest.scala b/src/test/scala/com/github/mdr/ascii/layout/cycles/GraphReflowTest.scala index eba1d34..90b2206 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/cycles/GraphReflowTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/cycles/GraphReflowTest.scala @@ -1,12 +1,12 @@ package com.github.mdr.ascii.layout.cycles -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.util.Utils -class GraphReflowTest extends FlatSpec with ShouldMatchers { +class GraphReflowTest extends FlatSpec with Matchers { reflowingGraph(""" +-+ +-+ diff --git a/src/test/scala/com/github/mdr/ascii/layout/layering/AssignLayersSpecification.scala b/src/test/scala/com/github/mdr/ascii/layout/layering/AssignLayersSpecification.scala index b958939..66dc29b 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/layering/AssignLayersSpecification.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/layering/AssignLayersSpecification.scala @@ -1,11 +1,7 @@ package com.github.mdr.ascii.layout.layering -import org.scalacheck.Arbitrary -import org.scalacheck.Gen -import org.scalacheck.Gen.Params import org.scalacheck.Prop.forAll import org.scalacheck.Properties -import org.scalacheck.Shrink import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.graph.GraphGenerators._ import com.github.mdr.ascii.layout.cycles.CycleRemover diff --git a/src/test/scala/com/github/mdr/ascii/layout/layering/CrossingCalculatorTest.scala b/src/test/scala/com/github/mdr/ascii/layout/layering/CrossingCalculatorTest.scala index 6385167..54ffd73 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/layering/CrossingCalculatorTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/layering/CrossingCalculatorTest.scala @@ -1,6 +1,6 @@ package com.github.mdr.ascii.layout.layering -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.graph.GraphUtils @@ -8,7 +8,7 @@ import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.util.Utils import com.github.mdr.ascii.layout.cycles.CycleRemover -class CrossingCalculatorTest extends FlatSpec with ShouldMatchers { +class CrossingCalculatorTest extends FlatSpec with Matchers { // Note: layer ordering in test data is done alphabetically diff --git a/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkSpecification.scala b/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkSpecification.scala index 5e17a35..87151cb 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkSpecification.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkSpecification.scala @@ -1,15 +1,10 @@ package com.github.mdr.ascii.layout.layering -import org.scalacheck.Arbitrary -import org.scalacheck.Gen -import org.scalacheck.Gen.Params import org.scalacheck.Prop.forAll import org.scalacheck.Properties -import org.scalacheck.Shrink import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.graph.GraphGenerators._ -import com.github.mdr.ascii.layout.cycles.CycleRemover object LongestDistanceToSinkSpecification extends Properties("LongestDistanceToSink") { diff --git a/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkTest.scala b/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkTest.scala index 0843f01..b549d6c 100644 --- a/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkTest.scala +++ b/src/test/scala/com/github/mdr/ascii/layout/layering/LongestDistanceToSinkTest.scala @@ -1,12 +1,12 @@ package com.github.mdr.ascii.layout.layering -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.graph.Graph import com.github.mdr.ascii.graph.GraphUtils import com.github.mdr.ascii.util.Utils -class LongestDistanceToSinkTest extends FlatSpec with ShouldMatchers { +class LongestDistanceToSinkTest extends FlatSpec with Matchers { distancesToSinks(""" +-+ +-+ +-+ diff --git a/src/test/scala/com/github/mdr/ascii/util/QuadTreeTest.scala b/src/test/scala/com/github/mdr/ascii/util/QuadTreeTest.scala index 6a0c6d6..a807aca 100644 --- a/src/test/scala/com/github/mdr/ascii/util/QuadTreeTest.scala +++ b/src/test/scala/com/github/mdr/ascii/util/QuadTreeTest.scala @@ -1,10 +1,10 @@ package com.github.mdr.ascii.util -import org.scalatest.FlatSpec +import org.scalatest.{ Matchers, FlatSpec } import org.scalatest.matchers.ShouldMatchers import com.github.mdr.ascii.common._ -class QuadTreeTest extends FlatSpec with ShouldMatchers { +class QuadTreeTest extends FlatSpec with Matchers { "A QuadTree" should "work with one element" in { val tree = new QuadTree[Region](Dimension(16, 16)) From fa3d71f27ada1f026c00aa725e65a9ce947b94c5 Mon Sep 17 00:00:00 2001 From: Cosmin Basca Date: Tue, 26 Aug 2014 15:01:53 +0200 Subject: [PATCH 2/4] ignore .DS_Store on mac --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ffbc731..987a70d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ target/ .project .classpath .idea* + +src/main/.DS_Store From aefcb8b502706e4c7ccb322e77a09488c0433d8f Mon Sep 17 00:00:00 2001 From: Cosmin Basca Date: Tue, 26 Aug 2014 15:03:25 +0200 Subject: [PATCH 3/4] updated basic example --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58635f6..ff57405 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ You can use it via sbt: # Graph layout - import com.github.mdr.ascii.layout._ + import com.github.mdr.ascii.graph.Graph + import com.github.mdr.ascii.layout.GraphLayout val graph = Graph( vertices = List( @@ -19,7 +20,7 @@ You can use it via sbt: "V2" -> "V5", "V2" -> "V6")) - val ascii = Layouter.renderGraph(graph) + val ascii = GraphLayout.renderGraph(graph) println(ascii) From bc441e57f6d02976b45283c9e4f0e9db80249f2c Mon Sep 17 00:00:00 2001 From: Cosmin Basca Date: Tue, 26 Aug 2014 15:03:46 +0200 Subject: [PATCH 4/4] updated latest version of ascii graphs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff57405..92be59a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ An ASCII-art diagram library for graphs. It supports both parsing existing diagr You can use it via sbt: - libraryDependencies += "com.github.mdr" %% "ascii-graphs" % "0.0.3" + libraryDependencies += "com.github.mdr" %% "ascii-graphs" % "0.0.7" # Graph layout