Port dependency-management/info

This commit is contained in:
Eugene Yokota 2016-03-29 00:22:55 -04:00
parent 63b11243d3
commit 7520bd99a5
2 changed files with 40 additions and 43 deletions

View File

@ -0,0 +1,40 @@
import scala.xml._
lazy val root = (project in file(".")).
settings(
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
ivyXML <<= (customInfo, organization, moduleName, version) apply inlineXML,
scalaVersion := "2.9.1",
projectID ~= (_ cross false),
customInfo <<= baseDirectory{_ / "info" exists },
TaskKey[Unit]("check-download") <<= checkDownload,
delivered <<= deliverLocal map XML.loadFile,
TaskKey[Unit]("check-info") <<= checkInfo
)
lazy val delivered = TaskKey[NodeSeq]("delivered")
lazy val customInfo = SettingKey[Boolean]("custom-info")
def inlineXML(addInfo: Boolean, organization: String, moduleID: String, version: String): NodeSeq =
if(addInfo)
(<info organisation={organization} module={moduleID} revision={version}>
<license name="Two-clause BSD-style" url="http://github.com/szeiger/scala-query/blob/master/LICENSE.txt" />
<description homepage="http://github.com/szeiger/scala-query/">
ScalaQuery is a type-safe database query API for Scala.
</description>
</info>
<dependency org="org.scala-tools.testing" name="scalacheck_2.9.1" rev="1.9"/>)
else
<dependency org="org.scala-tools.testing" name="scalacheck_2.9.1" rev="1.9"/>
def checkDownload = (dependencyClasspath in Compile) map { cp => if(cp.isEmpty) sys.error("Dependency not downloaded"); () }
def checkInfo = (customInfo, delivered) map { (addInfo, d) =>
if((d \ "info").isEmpty)
sys.error("No info tag generated")
else if(addInfo) {
if( !deliveredWithCustom(d) ) sys.error("Expected 'license' and 'description' tags in info tag, got: \n" + (d \ "info")) else ()
} else
if( deliveredWithCustom(d) ) sys.error("Expected empty 'info' tag, got: \n" + (d \ "info")) else ()
}
def deliveredWithCustom(d: NodeSeq) = (d \ "info" \ "license").nonEmpty && (d \ "info" \ "description").nonEmpty

View File

@ -1,43 +0,0 @@
import sbt._
import Import._
import Keys._
import scala.xml._
object InfoTest extends Build
{
lazy val root = Project("root", file(".")) settings(
ivyPaths <<= (baseDirectory, target)( (dir, t) => new IvyPaths(dir, Some(t / "ivy-cache"))),
ivyXML <<= (customInfo, organization, moduleName, version) apply inlineXML,
scalaVersion := "2.9.1",
projectID ~= (_ cross false),
customInfo <<= baseDirectory{_ / "info" exists },
TaskKey[Unit]("check-download") <<= checkDownload,
delivered <<= deliverLocal map XML.loadFile,
TaskKey[Unit]("check-info") <<= checkInfo
)
lazy val delivered = TaskKey[NodeSeq]("delivered")
lazy val customInfo = SettingKey[Boolean]("custom-info")
def inlineXML(addInfo: Boolean, organization: String, moduleID: String, version: String): NodeSeq =
if(addInfo)
(<info organisation={organization} module={moduleID} revision={version}>
<license name="Two-clause BSD-style" url="http://github.com/szeiger/scala-query/blob/master/LICENSE.txt" />
<description homepage="http://github.com/szeiger/scala-query/">
ScalaQuery is a type-safe database query API for Scala.
</description>
</info>
<dependency org="org.scala-tools.testing" name="scalacheck_2.9.1" rev="1.9"/>)
else
<dependency org="org.scala-tools.testing" name="scalacheck_2.9.1" rev="1.9"/>
def checkDownload = (dependencyClasspath in Compile) map { cp => if(cp.isEmpty) sys.error("Dependency not downloaded"); () }
def checkInfo = (customInfo, delivered) map { (addInfo, d) =>
if((d \ "info").isEmpty)
sys.error("No info tag generated")
else if(addInfo) {
if( !deliveredWithCustom(d) ) sys.error("Expected 'license' and 'description' tags in info tag, got: \n" + (d \ "info")) else ()
} else
if( deliveredWithCustom(d) ) sys.error("Expected empty 'info' tag, got: \n" + (d \ "info")) else ()
}
def deliveredWithCustom(d: NodeSeq) = (d \ "info" \ "license").nonEmpty && (d \ "info" \ "description").nonEmpty
}