1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java Fri Feb 01 18:42:07 2013 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java Tue Feb 05 13:20:07 2013 +0100
1.3 @@ -17,7 +17,9 @@
1.4 */
1.5 package org.apidesign.vm4brwsr;
1.6
1.7 +import java.io.ByteArrayInputStream;
1.8 import java.io.IOException;
1.9 +import java.io.InputStream;
1.10 import java.net.URL;
1.11 import java.util.zip.ZipEntry;
1.12 import java.util.zip.ZipInputStream;
1.13 @@ -39,7 +41,13 @@
1.14 Object c = classpath[i];
1.15 if (c instanceof String) {
1.16 try {
1.17 - c = classpath[i] = toZip((String)c);
1.18 + String url = (String)c;
1.19 + final Zips z = toZip(url);
1.20 + c = classpath[i] = z;
1.21 + final byte[] man = z.findRes("META-INF/MANIFEST.MF");
1.22 + if (man != null) {
1.23 + processClassPathAttr(man, url, classpath);
1.24 + }
1.25 } catch (IOException ex) {
1.26 classpath[i] = ex;
1.27 }
1.28 @@ -87,6 +95,38 @@
1.29 return z;
1.30 }
1.31
1.32 + private static void processClassPathAttr(final byte[] man, String url, Object[] classpath) throws IOException {
1.33 + try (InputStream is = initIS(new ByteArrayInputStream(man))) {
1.34 + String cp = is.toString();
1.35 + if (cp == null) {
1.36 + return;
1.37 + }
1.38 + for (int p = 0; p < cp.length();) {
1.39 + int n = cp.indexOf(':', p);
1.40 + if (n == -1) {
1.41 + n = cp.length();
1.42 + }
1.43 + String el = cp.substring(p, n);
1.44 + URL u = new URL(new URL(url), el);
1.45 + classpath = addToArray(classpath, u.toString());
1.46 + p = n;
1.47 + }
1.48 + }
1.49 + }
1.50 +
1.51 + private static InputStream initIS(InputStream is) throws IOException {
1.52 + return new ParseCPAttr(is);
1.53 + }
1.54 +
1.55 + private static Object[] addToArray(Object[] arr, String value) {
1.56 + final int last = arr.length;
1.57 + Object[] ret = enlargeArray(arr, last + 1);
1.58 + ret[last] = value;
1.59 + return ret;
1.60 + }
1.61 +
1.62 + @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;throw('Arr: ' + arr);")
1.63 + private static native Object[] enlargeArray(Object[] arr, int len);
1.64 @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
1.65 private static native void enlargeArray(byte[] arr, int len);
1.66