diff options
author | Rob Norris <rob_norris@mac.com> | 2016-03-05 21:23:42 -0500 |
---|---|---|
committer | Rob Norris <rob_norris@mac.com> | 2016-03-05 21:23:42 -0500 |
commit | e1ea7d3fa2d2372363eb60852fb9af321d51d2fa (patch) | |
tree | 999cb79dff0f1652850aa56cc79505ecc24bacdf /nailgun_launcher/NailgunLauncher.java | |
parent | b12d88aded90accf5c6d96b1abf753309a31b921 (diff) | |
download | cbt-e1ea7d3fa2d2372363eb60852fb9af321d51d2fa.tar.gz cbt-e1ea7d3fa2d2372363eb60852fb9af321d51d2fa.tar.bz2 cbt-e1ea7d3fa2d2372363eb60852fb9af321d51d2fa.zip |
nailgun cleanup
Diffstat (limited to 'nailgun_launcher/NailgunLauncher.java')
-rw-r--r-- | nailgun_launcher/NailgunLauncher.java | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/nailgun_launcher/NailgunLauncher.java b/nailgun_launcher/NailgunLauncher.java index a6858d9..e33a959 100644 --- a/nailgun_launcher/NailgunLauncher.java +++ b/nailgun_launcher/NailgunLauncher.java @@ -7,42 +7,55 @@ import java.nio.file.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -/* -This launcher allows to use Nailgun without loading anything else permanenetly into it's classpath. -The main method loads the given class from the given class math, calls it's main methods passing -in the additional arguments. -*/ +/** + * This launcher allows to use Nailgun without loading anything else permanenetly into its + * classpath. The main method loads the given class from the given class math, calls it's main + * methods passing in the additional arguments. + */ public class NailgunLauncher{ - /* Persistent cache for caching classloaders for the JVM life time. - Can be used as needed by user code to improve startup time. */ - public static ConcurrentHashMap<String,ClassLoader> classLoaderCache = new ConcurrentHashMap<String,ClassLoader>(); - public static void main(String[] args){ - try{ - if(args.length < 3){ - System.out.println("usage: <main class> <class path> <... args>"); - } else { - URLClassLoader cl = new URLClassLoader( // TODO: cache this classloader, but invalidate on changes - Arrays.stream( - args[1].split(File.pathSeparator) - ).filter( cp -> !(cp == "") ).map( cp -> { - try { return new URL("file:" + cp); } - catch(MalformedURLException e) { throw new RuntimeException(e); } - }).toArray(URL[]::new) - ){ - public String toString(){ - String suffix = ""; - if(getParent() != ClassLoader.getSystemClassLoader()) - suffix = ", "+getParent(); - return "URLClassLoader(" + Arrays.toString(getURLs()) + suffix +")"; - } - }; - cl .loadClass( args[0] ) - .getMethod( "main", String[].class ) - .invoke( - null/* _cls.newInstance()*/, - (Object) Arrays.stream(args).skip(2).toArray( String[]::new ) - ); - } - } catch (Exception e) { throw new RuntimeException(e); } - } + + /** + * Persistent cache for caching classloaders for the JVM life time. Can be used as needed by user + * code to improve startup time. + */ + public static ConcurrentHashMap<String,ClassLoader> classLoaderCache = + new ConcurrentHashMap<String,ClassLoader>(); + + public static void main(String[] args) throws ClassNotFoundException, + NoSuchMethodException, + IllegalAccessException, + InvocationTargetException { + if (args.length < 3) { + + System.out.println("usage: <main class> <class path> <... args>"); + + } else { + + // TODO: cache this classloader, but invalidate on changes + final URL[] urls = + Arrays.stream( + args[1].split(File.pathSeparator) + ).filter( cp -> !(cp == "") ).map( cp -> { + try { return new URL("file:" + cp); } + catch(MalformedURLException e) { throw new RuntimeException(e); } + }).toArray(URL[]::new); + + URLClassLoader cl = new URLClassLoader(urls) { + public String toString() { + String suffix = ""; + if (getParent() != ClassLoader.getSystemClassLoader()) + suffix = ", "+getParent(); + return "URLClassLoader(" + Arrays.toString(getURLs()) + suffix +")"; + } + }; + + cl.loadClass(args[0]) + .getMethod("main", String[].class) + .invoke( + null/* _cls.newInstance()*/, + (Object) Arrays.stream(args).skip(2).toArray(String[]::new) + ); + + } + } } |