Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying classifiers in ivy deps #159

Merged
merged 1 commit into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions scalalib/src/mill/scalalib/Dep.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
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)
case Array(a, "", b, "", c) => Dep.Scala(a, b, c, cross = true)
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 = {
Expand All @@ -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 = {
Expand All @@ -44,4 +61,4 @@ object Dep{
implicit def rw = RW.merge[Dep](
Java.rw, Scala.rw, Point.rw
)
}
}
7 changes: 7 additions & 0 deletions scalalib/test/src/mill/scalalib/ResolveDepsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ object ResolveDepsTests extends TestSuite {
assert(paths.nonEmpty)
}

'resolveValidDepsWithClassifier - {
val deps = Agg(ivy"org.lwjgl:lwjgl:3.1.1;classifier=natives-macos")
val Success(paths) = evalDeps(deps)
assert(paths.nonEmpty)
assert(paths.items.next.path.toString.contains("natives-macos"))
}

'errOnInvalidOrgDeps - {
val deps = Agg(ivy"xxx.yyy.invalid::pprint:0.5.3")
val Failure(errMsg, _) = evalDeps(deps)
Expand Down