diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-17 21:35:48 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-17 21:35:48 -0800 |
commit | 26e3702f3fccdedbb9dd44574678e9217d16959c (patch) | |
tree | f00f3aee83c5259313cf0847f9dcd246d67dd20e /core | |
parent | a7f182ee709d77070ca53c28833821ad638a6743 (diff) | |
download | mill-26e3702f3fccdedbb9dd44574678e9217d16959c.tar.gz mill-26e3702f3fccdedbb9dd44574678e9217d16959c.tar.bz2 mill-26e3702f3fccdedbb9dd44574678e9217d16959c.zip |
Implement downloading/caching of binaries and java-source-folder support to make better-files benchmarks compile; fixes https://github.com/lihaoyi/mill/issues/37
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/mill/modules/Util.scala | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/src/main/scala/mill/modules/Util.scala b/core/src/main/scala/mill/modules/Util.scala new file mode 100644 index 00000000..cd674bad --- /dev/null +++ b/core/src/main/scala/mill/modules/Util.scala @@ -0,0 +1,26 @@ +package mill.modules + +import ammonite.ops.RelPath +import mill.eval.PathRef +import mill.util.Ctx + +object Util { + def download(url: String, dest: RelPath)(implicit ctx: Ctx.DestCtx) = { + ammonite.ops.mkdir(ctx.dest) + val out = ctx.dest / dest + + val website = new java.net.URI(url).toURL + val rbc = java.nio.channels.Channels.newChannel(website.openStream) + try{ + val fos = new java.io.FileOutputStream(out.toIO) + try{ + fos.getChannel.transferFrom(rbc, 0, java.lang.Long.MAX_VALUE) + PathRef(out) + } finally{ + fos.close() + } + } finally{ + rbc.close() + } + } +} |