diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-02 20:15:00 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-02 20:21:37 -0800 |
commit | 2e50c963eecadcf7bd6ecd6956584ab099d5273a (patch) | |
tree | 2f66db3102be7b958cf56429c6dd60c2ae610766 /core/src | |
parent | 4d79af93f907264a16abe3661ea417a268b0ef67 (diff) | |
download | mill-2e50c963eecadcf7bd6ecd6956584ab099d5273a.tar.gz mill-2e50c963eecadcf7bd6ecd6956584ab099d5273a.tar.bz2 mill-2e50c963eecadcf7bd6ecd6956584ab099d5273a.zip |
compile zinc compiler bridges on demand to remove restriction on supported scala versions
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/mill/modules/Util.scala | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/core/src/mill/modules/Util.scala b/core/src/mill/modules/Util.scala index d53cfcc9..542f58d1 100644 --- a/core/src/mill/modules/Util.scala +++ b/core/src/mill/modules/Util.scala @@ -1,11 +1,12 @@ package mill.modules -import ammonite.ops.{Path, RelPath} + +import ammonite.ops.{Path, RelPath, empty, mkdir, read} import mill.eval.PathRef import mill.util.Ctx object Util { - def download(url: String, dest: RelPath)(implicit ctx: Ctx.DestCtx) = { + def download(url: String, dest: RelPath = "download")(implicit ctx: Ctx.DestCtx) = { ammonite.ops.mkdir(ctx.dest) val out = ctx.dest / dest @@ -23,4 +24,46 @@ object Util { rbc.close() } } + + def downloadUnpackZip(url: String, dest: RelPath = "unpacked") + (implicit ctx: Ctx.DestCtx) = { + ctx.dest + mkdir(ctx.dest) + + val tmpName = if (dest == empty / "tmp.zip") "tmp2.zip" else "tmp.zip" + val downloaded = download(url, tmpName) + unpackZip(downloaded.path, dest) + } + + def unpackZip(src: Path, dest: RelPath = "unpacked") + (implicit ctx: Ctx.DestCtx) = { + mkdir(ctx.dest) + + val byteStream = read.getInputStream(src) + val zipStream = new java.util.zip.ZipInputStream(byteStream) + while({ + zipStream.getNextEntry match{ + case null => false + case entry => + if (!entry.isDirectory) { + val entryDest = ctx.dest / dest / RelPath(entry.getName) + mkdir(entryDest / ammonite.ops.up) + val fileOut = new java.io.FileOutputStream(entryDest.toString) + val buffer = new Array[Byte](4096) + while ( { + zipStream.read(buffer) match { + case -1 => false + case n => + fileOut.write(buffer, 0, n) + true + } + }) () + fileOut.close() + } + zipStream.closeEntry() + true + } + })() + PathRef(ctx.dest / dest) + } } |