Merge pull request #154 from jrudolph/modernize-build

Update to sbt 1.1.6
This commit is contained in:
Johannes Rudolph 2018-07-16 12:09:59 +02:00 committed by GitHub
commit e597bcf804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 119 additions and 91 deletions

View File

@ -1,8 +1,6 @@
ScriptedPlugin.scriptedSettings
ScriptedPlugin.scriptedLaunchOpts += s"-Dproject.version=${version.value}"
scriptedLaunchOpts += s"-Dproject.version=${version.value}"
libraryDependencies ++= {
println(s"Evaluated ${sbtVersion in pluginCrossBuild value}")
if ((sbtVersion in pluginCrossBuild).value startsWith "0.13")
Seq("com.github.mdr" %% "ascii-graphs" % "0.0.3")
else
@ -10,15 +8,15 @@ libraryDependencies ++= {
}
libraryDependencies += "org.specs2" %% "specs2-core" % "3.9.5" % Test
libraryDependencies += "org.specs2" %% "specs2-core" % "3.10.0" % Test
libraryDependencies += Defaults.sbtPluginExtra(
"com.dwijnand" % "sbt-compat" % "1.1.0",
"com.dwijnand" % "sbt-compat" % "1.2.6",
(sbtBinaryVersion in pluginCrossBuild).value,
(scalaBinaryVersion in update).value
)
crossSbtVersions := Seq("1.0.2", "0.13.16")
crossSbtVersions := Seq("1.1.6", "0.13.16")
scalacOptions ++= Seq(
"-deprecation",

View File

@ -1 +1 @@
sbt.version=0.13.16
sbt.version=1.1.6

View File

@ -1,4 +1,4 @@
libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.1")
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "2.0.0")

View File

@ -55,6 +55,5 @@ object AsciiGraph {
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.")
}
}
)
})
}

View File

@ -22,9 +22,9 @@ object DependencyGraphSbtCompat {
}
/**
* This is copied directly from https://github.com/sbt/sbt/blob/2952a2b9b672c5402b824ad2d2076243eb643598/main/src/main/scala/sbt/Defaults.scala#L1471-L1523
* and then changed to update the UpdateConfiguration to ignore missing artifacts.
*/
* This is copied directly from https://github.com/sbt/sbt/blob/2952a2b9b672c5402b824ad2d2076243eb643598/main/src/main/scala/sbt/Defaults.scala#L1471-L1523
* and then changed to update the UpdateConfiguration to ignore missing artifacts.
*/
def updateTask(task: TaskKey[_]): Initialize[Task[UpdateReport]] = Def.task {
val depsUpdated = transitiveUpdate.value.exists(!_.stats.cached)
val isRoot = executionRoots.value contains resolvedScoped.value
@ -32,8 +32,8 @@ object DependencyGraphSbtCompat {
val s = streams.value
val fullUpdateOutput = s.cacheDirectory / "out"
val forceUpdateByTime = forceUpdate match {
case None => false
case Some(period) =>
case None false
case Some(period)
val elapsedDuration = new FiniteDuration(System.currentTimeMillis() - fullUpdateOutput.lastModified(), TimeUnit.MILLISECONDS)
fullUpdateOutput.exists() && elapsedDuration > period
}
@ -42,17 +42,17 @@ object DependencyGraphSbtCompat {
// Only substitute unmanaged jars for managed jars when the major.minor parts of the versions the same for:
// the resolved Scala version and the scalaHome version: compatible (weakly- no qualifier checked)
// the resolved Scala version and the declared scalaVersion: assume the user intended scalaHome to override anything with scalaVersion
def subUnmanaged(subVersion: String, jars: Seq[File]) = (sv: String) =>
def subUnmanaged(subVersion: String, jars: Seq[File]) = (sv: String)
(partialVersion(sv), partialVersion(subVersion), partialVersion(scalaVersion.value)) match {
case (Some(res), Some(sh), _) if res == sh => jars
case (Some(res), _, Some(decl)) if res == decl => jars
case _ => Nil
case (Some(res), Some(sh), _) if res == sh jars
case (Some(res), _, Some(decl)) if res == decl jars
case _ Nil
}
val subScalaJars: String => Seq[File] = Defaults.unmanagedScalaInstanceOnly.value match {
case Some(si) => subUnmanaged(si.version, si.jars)
case None => sv => if (scalaProvider.version == sv) scalaProvider.jars else Nil
val subScalaJars: String Seq[File] = Defaults.unmanagedScalaInstanceOnly.value match {
case Some(si) subUnmanaged(si.version, si.jars)
case None sv if (scalaProvider.version == sv) scalaProvider.jars else Nil
}
val transform: UpdateReport => UpdateReport = r => sbt.Classpaths.substituteScalaFiles(scalaOrganization.value, r)(subScalaJars)
val transform: UpdateReport UpdateReport = r sbt.Classpaths.substituteScalaFiles(scalaOrganization.value, r)(subScalaJars)
val uwConfig = (unresolvedWarningConfiguration in update).value
val show = Reference.display(thisProjectRef.value)
val st = state.value
@ -66,9 +66,9 @@ object DependencyGraphSbtCompat {
// This code bumps up the sbt.UpdateConfiguration.logging to Full when logLevel is Debug.
import UpdateLogging.{ Full, DownloadOnly, Default }
val uc = (logLevel in update).?.value orElse st.get(logLevel.key) match {
case Some(Level.Debug) if uc0.logging == Default => uc0.copy(logging = Full)
case Some(x) if uc0.logging == Default => uc0.copy(logging = DownloadOnly)
case _ => uc0
case Some(Level.Debug) if uc0.logging == Default uc0.copy(logging = Full)
case Some(x) if uc0.logging == Default uc0.copy(logging = DownloadOnly)
case _ uc0
}
val ewo =
if (executionRoots.value exists { _.key == evicted.key }) EvictionWarningOptions.empty

View File

@ -58,7 +58,6 @@ object DependencyGraphSbtCompat {
ewo = evictionOptions,
mavenStyle = publishMavenStyle.value,
compatWarning = compatibilityWarningOptions.value,
log = s.log
)
log = s.log)
}
}

View File

@ -19,53 +19,76 @@ package net.virtualvoid.sbt.graph
import sbt._
trait DependencyGraphKeys {
val dependencyGraphMLFile = SettingKey[File]("dependency-graph-ml-file",
val dependencyGraphMLFile = SettingKey[File](
"dependency-graph-ml-file",
"The location the graphml file should be generated at")
val dependencyGraphML = TaskKey[File]("dependency-graph-ml",
val dependencyGraphML = TaskKey[File](
"dependency-graph-ml",
"Creates a graphml file containing the dependency-graph for a project")
val dependencyDotFile = SettingKey[File]("dependency-dot-file",
val dependencyDotFile = SettingKey[File](
"dependency-dot-file",
"The location the dot file should be generated at")
val dependencyDotNodeLabel = SettingKey[(String, String, String) String]("dependency-dot-node-label",
val dependencyDotNodeLabel = SettingKey[(String, String, String) String](
"dependency-dot-node-label",
"Returns a formated string of a dependency. Takes organisation, name and version as parameters")
val dependencyDotHeader = SettingKey[String]("dependency-dot-header",
val dependencyDotHeader = SettingKey[String](
"dependency-dot-header",
"The header of the dot file. (e.g. to set your preferred node shapes)")
val dependencyDot = TaskKey[File]("dependency-dot",
val dependencyDot = TaskKey[File](
"dependency-dot",
"Creates a dot file containing the dependency-graph for a project")
val dependencyDotString = TaskKey[String]("dependency-dot-string",
val dependencyDotString = TaskKey[String](
"dependency-dot-string",
"Creates a String containing the dependency-graph for a project in dot format")
val dependencyBrowseGraphTarget = SettingKey[File]("dependency-browse-graph-target",
val dependencyBrowseGraphTarget = SettingKey[File](
"dependency-browse-graph-target",
"The location dependency browse graph files should be put.")
val dependencyBrowseGraphHTML = TaskKey[URI]("dependency-browse-graph-html",
val dependencyBrowseGraphHTML = TaskKey[URI](
"dependency-browse-graph-html",
"Creates an HTML page that can be used to view the graph.")
val dependencyBrowseGraph = TaskKey[URI]("dependency-browse-graph",
val dependencyBrowseGraph = TaskKey[URI](
"dependency-browse-graph",
"Opens an HTML page that can be used to view the graph.")
val moduleGraph = TaskKey[ModuleGraph]("module-graph",
val moduleGraph = TaskKey[ModuleGraph](
"module-graph",
"The dependency graph for a project")
val moduleGraphIvyReport = TaskKey[ModuleGraph]("module-graph-ivy-report",
val moduleGraphIvyReport = TaskKey[ModuleGraph](
"module-graph-ivy-report",
"The dependency graph for a project as generated from an Ivy Report XML")
val moduleGraphSbt = TaskKey[ModuleGraph]("module-graph-sbt",
val moduleGraphSbt = TaskKey[ModuleGraph](
"module-graph-sbt",
"The dependency graph for a project as generated from SBT data structures.")
val asciiGraph = TaskKey[String]("dependency-graph-string",
val asciiGraph = TaskKey[String](
"dependency-graph-string",
"Returns a string containing the ascii representation of the dependency graph for a project")
val dependencyGraph = InputKey[Unit]("dependency-graph",
val dependencyGraph = InputKey[Unit](
"dependency-graph",
"Prints the ascii graph to the console")
val asciiTree = TaskKey[String]("dependency-tree-string",
val asciiTree = TaskKey[String](
"dependency-tree-string",
"Returns a string containing an ascii tree representation of the dependency graph for a project")
val dependencyTree = TaskKey[Unit]("dependency-tree",
val dependencyTree = TaskKey[Unit](
"dependency-tree",
"Prints an ascii tree of all the dependencies to the console")
val dependencyList = TaskKey[Unit]("dependency-list",
val dependencyList = TaskKey[Unit](
"dependency-list",
"Prints a list of all dependencies to the console")
val dependencyStats = TaskKey[Unit]("dependency-stats",
val dependencyStats = TaskKey[Unit](
"dependency-stats",
"Prints statistics for all dependencies to the console")
val ivyReportFunction = TaskKey[String File]("ivy-report-function",
val ivyReportFunction = TaskKey[String File](
"ivy-report-function",
"A function which returns the file containing the ivy report from the ivy cache for a given configuration")
val ivyReport = TaskKey[File]("ivy-report",
val ivyReport = TaskKey[File](
"ivy-report",
"A task which returns the location of the ivy report file for a given configuration (default `compile`).")
val ignoreMissingUpdate = Keys.update in ivyReport
val filterScalaLibrary = SettingKey[Boolean]("filter-scala-library",
val filterScalaLibrary = SettingKey[Boolean](
"filter-scala-library",
"Specifies if scala dependency should be filtered in dependency-* output")
val licenseInfo = TaskKey[Unit]("dependency-license-info",
val licenseInfo = TaskKey[Unit](
"dependency-license-info",
"Aggregates and shows information about the licenses of dependencies")
// internal

View File

@ -160,20 +160,19 @@ object DependencyGraphSettings {
}
val artifactIdParser: Def.Initialize[State Parser[ModuleId]] =
resolvedScoped { ctx
(state: State)
val graph = loadFromContext(moduleGraphStore, ctx, state) getOrElse ModuleGraph(Nil, Nil)
resolvedScoped { ctx (state: State)
val graph = loadFromContext(moduleGraphStore, ctx, state) getOrElse ModuleGraph(Nil, Nil)
import sbt.complete.DefaultParsers._
graph.nodes.map(_.id).map {
case id @ ModuleId(org, name, version)
(Space ~ token(org) ~ token(Space ~ name) ~ token(Space ~ version)).map(_ id)
}.reduceOption(_ | _).getOrElse {
(Space ~> token(StringBasic, "organization") ~ Space ~ token(StringBasic, "module") ~ Space ~ token(StringBasic, "version")).map {
case ((((org, _), mod), _), version)
ModuleId(org, mod, version)
}
import sbt.complete.DefaultParsers._
graph.nodes.map(_.id).map {
case id @ ModuleId(org, name, version)
(Space ~ token(org) ~ token(Space ~ name) ~ token(Space ~ version)).map(_ id)
}.reduceOption(_ | _).getOrElse {
(Space ~> token(StringBasic, "organization") ~ Space ~ token(StringBasic, "module") ~ Space ~ token(StringBasic, "version")).map {
case ((((org, _), mod), _), version)
ModuleId(org, mod, version)
}
}
}
// This is to support 0.13.8's InlineConfigurationWithExcludes while not forcing 0.13.8

View File

@ -36,7 +36,8 @@ object IvyReport {
revision mod \ "revision"
rev = revision.attribute("name").get.text
moduleId = moduleIdFromElement(mod, rev)
module = Module(moduleId,
module = Module(
moduleId,
(revision \ "license").headOption.flatMap(_.attribute("name")).map(_.text),
evictedByVersion = (revision \ "evicted-by").headOption.flatMap(_.attribute("rev").map(_.text)),
error = revision.attribute("error").map(_.text))

View File

@ -38,7 +38,8 @@ object SbtUpdateReport {
def moduleEdge(chosenVersion: Option[String])(report: ModuleReport): (Module, Seq[Edge]) = {
val evictedByVersion = if (report.evicted) chosenVersion else None
val jarFile = report.artifacts.find(_._1.`type` == "jar").orElse(report.artifacts.find(_._1.extension == "jar")).map(_._2)
(Module(
(
Module(
id = report.module,
license = report.licenses.headOption.map(_._1),
evictedByVersion = evictedByVersion,

View File

@ -22,17 +22,19 @@ import sbinary.Format
import scala.collection.mutable.{ HashMap, MultiMap, Set }
case class ModuleId(organisation: String,
name: String,
version: String) {
case class ModuleId(
organisation: String,
name: String,
version: String) {
def idString: String = organisation + ":" + name + ":" + version
}
case class Module(id: ModuleId,
license: Option[String] = None,
extraInfo: String = "",
evictedByVersion: Option[String] = None,
jarFile: Option[File] = None,
error: Option[String] = None) {
case class Module(
id: ModuleId,
license: Option[String] = None,
extraInfo: String = "",
evictedByVersion: Option[String] = None,
jarFile: Option[File] = None,
error: Option[String] = None) {
def hadError: Boolean = error.isDefined
def isUsed: Boolean = !isEvicted
def isEvicted: Boolean = evictedByVersion.isDefined

View File

@ -20,15 +20,17 @@ package rendering
object DOT {
val EvictedStyle = "stroke-dasharray: 5,5"
def dotGraph(graph: ModuleGraph,
dotHead: String,
nodeFormation: (String, String, String) String,
labelRendering: HTMLLabelRendering): String = {
def dotGraph(
graph: ModuleGraph,
dotHead: String,
nodeFormation: (String, String, String) String,
labelRendering: HTMLLabelRendering): String = {
val nodes = {
for (n graph.nodes) yield {
val style = if (n.isEvicted) EvictedStyle else ""
val label = nodeFormation(n.id.organisation, n.id.name, n.id.version)
""" "%s"[%s style="%s"]""".format(n.id.idString,
""" "%s"[%s style="%s"]""".format(
n.id.idString,
labelRendering.renderLabel(label),
style)
}

View File

@ -20,12 +20,12 @@ package rendering
object Statistics {
def renderModuleStatsList(graph: ModuleGraph): String = {
case class ModuleStats(
id: ModuleId,
numDirectDependencies: Int,
numTransitiveDependencies: Int,
selfSize: Option[Long],
transitiveSize: Long,
transitiveDependencyStats: Map[ModuleId, ModuleStats]) {
id: ModuleId,
numDirectDependencies: Int,
numTransitiveDependencies: Int,
selfSize: Option[Long],
transitiveSize: Long,
transitiveDependencyStats: Map[ModuleId, ModuleStats]) {
def transitiveStatsWithSelf: Map[ModuleId, ModuleStats] = transitiveDependencyStats + (id -> this)
}

View File

@ -13,10 +13,11 @@ object AsciiTreeLayout {
// [info] | +-baz
// [info] |
// [info] +-quux
def toAscii[A](top: A,
children: A Seq[A],
display: A String,
maxColumn: Int = defaultColumnSize): String = {
def toAscii[A](
top: A,
children: A Seq[A],
display: A String,
maxColumn: Int = defaultColumnSize): String = {
val twoSpaces = " " + " " // prevent accidentally being converted into a tab
def limitLine(s: String): String =
if (s.length > maxColumn) s.slice(0, maxColumn - 2) + ".."

View File

@ -5,7 +5,10 @@ import net.virtualvoid.sbt.graph.DependencyGraphKeys.dependencyDot
import scala.collection.mutable.ListBuffer
def defaultSettings =
Seq(scalaVersion := "2.9.2")
Seq(
scalaVersion := "2.9.2",
version := "0.1-SNAPSHOT"
)
lazy val justATransiviteDependencyEndpointProject =
Project("just-a-transitive-dependency-endpoint", file("a"))