From 26e3702f3fccdedbb9dd44574678e9217d16959c Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 17 Jan 2018 21:35:48 -0800 Subject: Implement downloading/caching of binaries and java-source-folder support to make better-files benchmarks compile; fixes https://github.com/lihaoyi/mill/issues/37 --- core/src/main/scala/mill/modules/Util.scala | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/src/main/scala/mill/modules/Util.scala (limited to 'core') 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() + } + } +} -- cgit v1.2.3