From 3c1187fc24a6fdc1dd8ac37522afa39aba81967b Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Sat, 24 Feb 2018 15:56:21 -0800 Subject: Allow specifying classifiers in ivy deps (#159) --- scalalib/src/mill/scalalib/Dep.scala | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'scalalib/src') diff --git a/scalalib/src/mill/scalalib/Dep.scala b/scalalib/src/mill/scalalib/Dep.scala index 8ecd39ee..78f454f2 100644 --- a/scalalib/src/mill/scalalib/Dep.scala +++ b/scalalib/src/mill/scalalib/Dep.scala @@ -1,11 +1,22 @@ package mill.scalalib import mill.util.JsonFormatters._ import upickle.default.{macroRW, ReadWriter => RW} -sealed trait Dep +sealed trait Dep { + def configure(attributes: coursier.Attributes): Dep +} object Dep{ implicit def parse(signature: String) = { - signature.split(':') match{ + val parts = signature.split(';') + val module = parts.head + val attributes = parts.tail.foldLeft(coursier.Attributes()) { (as, s) => + s.split('=') match { + case Array("classifier", v) => as.copy(classifier = v) + case Array(k, v) => throw new Exception(s"Unrecognized attribute: [$s]") + case _ => throw new Exception(s"Unable to parse attribute specifier: [$s]") + } + } + (module.split(':') match { case Array(a, b, c) => Dep.Java(a, b, c, cross = false) case Array(a, b, "", c) => Dep.Java(a, b, c, cross = true) case Array(a, "", b, c) => Dep.Scala(a, b, c, cross = false) @@ -13,12 +24,14 @@ object Dep{ case Array(a, "", "", b, c) => Dep.Point(a, b, c, cross = false) case Array(a, "", "", b, "", c) => Dep.Point(a, b, c, cross = true) case _ => throw new Exception(s"Unable to parse signature: [$signature]") - } + }).configure(attributes = attributes) } def apply(org: String, name: String, version: String, cross: Boolean): Dep = { this(coursier.Dependency(coursier.Module(org, name), version), cross) } - case class Java(dep: coursier.Dependency, cross: Boolean) extends Dep + case class Java(dep: coursier.Dependency, cross: Boolean) extends Dep { + def configure(attributes: coursier.Attributes): Dep = copy(dep = dep.copy(attributes = attributes)) + } object Java{ implicit def rw: RW[Java] = macroRW def apply(org: String, name: String, version: String, cross: Boolean): Dep = { @@ -27,14 +40,18 @@ object Dep{ } implicit def default(dep: coursier.Dependency): Dep = new Java(dep, false) def apply(dep: coursier.Dependency, cross: Boolean) = Scala(dep, cross) - case class Scala(dep: coursier.Dependency, cross: Boolean) extends Dep + case class Scala(dep: coursier.Dependency, cross: Boolean) extends Dep { + def configure(attributes: coursier.Attributes): Dep = copy(dep = dep.copy(attributes = attributes)) + } object Scala{ implicit def rw: RW[Scala] = macroRW def apply(org: String, name: String, version: String, cross: Boolean): Dep = { Scala(coursier.Dependency(coursier.Module(org, name), version), cross) } } - case class Point(dep: coursier.Dependency, cross: Boolean) extends Dep + case class Point(dep: coursier.Dependency, cross: Boolean) extends Dep { + def configure(attributes: coursier.Attributes): Dep = copy(dep = dep.copy(attributes = attributes)) + } object Point{ implicit def rw: RW[Point] = macroRW def apply(org: String, name: String, version: String, cross: Boolean): Dep = { @@ -44,4 +61,4 @@ object Dep{ implicit def rw = RW.merge[Dep]( Java.rw, Scala.rw, Point.rw ) -} \ No newline at end of file +} -- cgit v1.2.3