Last active
August 29, 2015 14:02
-
-
Save uemuraj/0ea50fdc07c8a3a38147 to your computer and use it in GitHub Desktop.
jjs にグローバルな関数を追加します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('init-naz.js'); | |
cp('http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar', 'ivy-2.3.0.jar'); | |
unzip('http://archive.apache.org/dist/ant/ivy/2.3.0/apache-ivy-2.3.0-bin.zip', '.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* mkdirs, unzip, cp | |
*/ | |
function mkdirs(dir) { | |
if (dir instanceof java.io.File) { | |
if (dir.exists()) { | |
return true; | |
} | |
return dir.mkdirs(); | |
} | |
if (typeof(dir) == "string") { | |
return mkdirs(new java.io.File(dir)); | |
} | |
} | |
function openInputStream(name) { | |
if (name instanceof java.io.File) { | |
return new java.io.FileInputStream(name); | |
} | |
if (name instanceof java.net.URL) { | |
return name.openStream(); | |
} | |
if (typeof(name) == "string") { | |
try { | |
return openInputStream(new java.io.File(name)); | |
} catch (e) { | |
return openInputStream(new java.net.URL(name)); | |
} | |
} | |
} | |
function openOutputStream(name) { | |
if (name instanceof java.io.File) { | |
mkdirs(name.getParentFile()); | |
return new java.io.FileOutputStream(name); | |
} | |
if (typeof(name) == "string") { | |
var file = new java.io.File(name); | |
mkdirs(file.getParentFile()); | |
return openOutputStream(file); | |
} | |
} | |
function transfer(from, to) { | |
var inp = new java.io.BufferedInputStream(from); | |
var out = new java.io.BufferedOutputStream(to); | |
var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 4096); | |
var length; | |
while ((length = inp.read(buffer)) >= 0) { | |
out.write(buffer, 0, length); | |
} | |
out.flush(); | |
} | |
function unzip(src, dest) { | |
var inp = openInputStream(src); | |
var zip = new java.util.zip.ZipInputStream(inp); | |
var entry; | |
while ((entry = zip.getNextEntry()) != null) { | |
if (entry.isDirectory()) { | |
mkdirs(new java.io.File(dest, entry.getName())); | |
continue; | |
} | |
var out = openOutputStream(new java.io.File(dest, entry.getName())); | |
transfer(zip, out); | |
out.close(); | |
} | |
zip.close(); | |
inp.close(); | |
} | |
function cp(from, to) { | |
var inp = openInputStream(from); | |
var out = openOutputStream(to); | |
transfer(inp, out); | |
inp.close(); | |
out.close(); | |
} |
load() は jjs と jrunscript で共通なので、この内容ならどちらでも動く。
jrunscript ならスクリプトを引数で渡せるからファイルは1つ減らせるか...
@echo off
jrunscript -e ^
load('init-naz.js');^
cp('http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar','ivy-2.3.0.jar');^
unzip('http://archive.apache.org/dist/ant/ivy/2.3.0/apache-ivy-2.3.0-bin.zip','.');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
動かし方はこんな感じ:
jjs -Djava.net.useSystemProxies=true init-naz-test.js
jrunscript -Djava.net.useSystemProxies=true init-naz-test.js