Skip to content

Commit

Permalink
Substitute the empty version in $ivy-import with mill version
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Oct 12, 2021
1 parent 5f6538e commit 2b22e36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 7 additions & 1 deletion main/src/mill/main/MillIvyHook.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ import mill.BuildInfo
*
* - supports the format `org:::name::version` for mill plugins;
* which is equivalent to `org:::name_mill$MILL_BIN_PLATFORM:version`
*
* - replaces the empty version for scala dependencies as $MILL_VERSION
*/
object MillIvyHook extends BaseIvy(plugin = false) {
override def resolve(
interp: ImportHook.InterpreterInterface,
signatures: Seq[String]
): Either[String, (Seq[coursierapi.Dependency], Seq[File])] = {

// replace platform notation
// replace platform notation and empty version
val millSigs: Seq[String] = for (signature <- signatures) yield {
// if (signature.endsWith(":") && signature.count(_ == ":") == 4) signature + "$MILL_VERSION"
// else
signature.split("[:]") match {
case Array(org, "", pname, "", version)
if org.length > 0 && pname.length > 0 && version.length > 0 =>
s"${org}::${pname}_mill$$MILL_BIN_PLATFORM:${version}"
case Array(org, "", "", pname, "", version)
if org.length > 0 && pname.length > 0 && version.length > 0 =>
s"${org}:::${pname}_mill$$MILL_BIN_PLATFORM:${version}"
case Array(org, "", name) if org.length > 0 && name.length > 0 && signature.endsWith(":") =>
s"${org}::${name}:$$MILL_VERSION"
case _ => signature
}
}
Expand Down
20 changes: 14 additions & 6 deletions main/test/src/main/MillIvyHookTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import coursierapi.{Dependency => CDependency, Module => CModule, ScalaVersion =
import utest.{TestSuite, Tests, _}

object MillIvyHookTest extends TestSuite {
val wd = os.pwd
val wd = os.Path("/tmp")
def mapDep(d: CDependency): Seq[File] =
Seq(
(wd / d.getModule.getOrganization / d.getModule.getName / d.getVersion / s"${d.getModule.getName}-${d.getVersion}.jar").toIO
(wd / s"${d.getModule.getOrganization}__${d.getModule.getName}__${d.getVersion}__${d.getModule.getName}-${d.getVersion}.jar").toIO
)
override def tests: Tests = Tests {
val interp = new InterpreterInterface {
Expand All @@ -23,11 +23,11 @@ object MillIvyHookTest extends TestSuite {
}
test("simple") {
val deps = Seq(
("a:b:c", CDependency.of("a", "b", "c"), wd / "a" / "b" / "c" / "b-c.jar"),
("a:b:c", CDependency.of("a", "b", "c"), wd / "a__b__c__b-c.jar"),
(
"a::b:c",
CDependency.of(CModule.parse("a::b", CScalaVersion.of("2.13.6")), "c"),
wd / "a" / "b_2.13" / "c" / "b_2.13-c.jar"
wd / "a__b_2.13__c__b_2.13-c.jar"
),
(
"a::b::c",
Expand All @@ -38,7 +38,15 @@ object MillIvyHookTest extends TestSuite {
),
"c"
),
wd / "a" / s"b_mill${mill.BuildInfo.millBinPlatform}_2.13" / "c" / s"b_mill${mill.BuildInfo.millBinPlatform}_2.13-c.jar"
wd / s"a__b_mill${mill.BuildInfo.millBinPlatform}_2.13__c__b_mill${mill.BuildInfo.millBinPlatform}_2.13-c.jar"
),
(
s"a::b:",
CDependency.of(
CModule.parse("a::b", CScalaVersion.of("2.13.6")),
mill.BuildInfo.millVersion
),
wd / s"a__b_2.13__${mill.BuildInfo.millVersion}__b_2.13-${mill.BuildInfo.millVersion}.jar"
)
)
val checks = deps.map { case (coord, dep, path) =>
Expand All @@ -48,7 +56,7 @@ object MillIvyHookTest extends TestSuite {
val resolved = MillIvyHook.resolve(interp, Seq(coord))
assert(
// first check only adds context to the exception message
!coord.isEmpty && resolved == expected
coord.nonEmpty && dep.toString.nonEmpty && resolved == expected
)
}
}
Expand Down

0 comments on commit 2b22e36

Please sign in to comment.