vm/src/main/java/org/apidesign/vm4brwsr/Zips.java
branchemul
changeset 702 fa42b3d8cbbc
parent 690 8929a6558ae4
child 706 a48961ff3e6b
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java	Wed Feb 06 17:22:14 2013 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Zips.java	Thu Feb 07 13:41:56 2013 +0100
     1.3 @@ -19,7 +19,6 @@
     1.4  
     1.5  import java.io.ByteArrayInputStream;
     1.6  import java.io.IOException;
     1.7 -import java.io.InputStream;
     1.8  import java.net.URL;
     1.9  import java.util.zip.ZipEntry;
    1.10  import java.util.zip.ZipInputStream;
    1.11 @@ -36,7 +35,7 @@
    1.12      public static void init() {
    1.13      }
    1.14      
    1.15 -    public static byte[] loadFromCp(Object[] classpath, String res) {
    1.16 +    public static byte[] loadFromCp(Object[] classpath, String res) throws Exception {
    1.17          for (int i = 0; i < classpath.length; i++) {
    1.18              Object c = classpath[i];
    1.19              if (c instanceof String) {
    1.20 @@ -46,13 +45,17 @@
    1.21                      c = classpath[i] = z;
    1.22                      final byte[] man = z.findRes("META-INF/MANIFEST.MF");
    1.23                      if (man != null) {
    1.24 -                        processClassPathAttr(man, url, classpath);
    1.25 +                        String mainClass = processClassPathAttr(man, url, classpath);
    1.26 +                        if (mainClass != null) {
    1.27 +                            Class.forName(mainClass);
    1.28 +                        }
    1.29                      }
    1.30 -                } catch (IOException ex) {
    1.31 +                } catch (Exception ex) {
    1.32                      classpath[i] = ex;
    1.33 +                    throw ex;
    1.34                  }
    1.35              }
    1.36 -            if (c instanceof Zips) {
    1.37 +            if (res != null && c instanceof Zips) {
    1.38                  Object checkRes = ((Zips)c).findRes(res);
    1.39                  if (checkRes instanceof byte[]) {
    1.40                      return (byte[])checkRes;
    1.41 @@ -95,30 +98,26 @@
    1.42          return z;
    1.43      }
    1.44  
    1.45 -    private static void processClassPathAttr(final byte[] man, String url, Object[] classpath) throws IOException {
    1.46 -        try (InputStream is = initIS(new ByteArrayInputStream(man))) {
    1.47 +    private static String processClassPathAttr(final byte[] man, String url, Object[] classpath) throws IOException {
    1.48 +        try (ParseMan is = new ParseMan(new ByteArrayInputStream(man))) {
    1.49              String cp = is.toString();
    1.50 -            if (cp == null) {
    1.51 -                return;
    1.52 +            if (cp != null) {
    1.53 +                cp = cp.trim();
    1.54 +                for (int p = 0; p < cp.length();) {
    1.55 +                    int n = cp.indexOf(' ', p);
    1.56 +                    if (n == -1) {
    1.57 +                        n = cp.length();
    1.58 +                    }
    1.59 +                    String el = cp.substring(p, n);
    1.60 +                    URL u = new URL(new URL(url), el);
    1.61 +                    classpath = addToArray(classpath, u.toString());
    1.62 +                    p = n + 1;
    1.63 +                }
    1.64              }
    1.65 -            cp = cp.trim();
    1.66 -            for (int p = 0; p < cp.length();) {
    1.67 -                int n = cp.indexOf(' ', p);
    1.68 -                if (n == -1) {
    1.69 -                    n = cp.length();
    1.70 -                }
    1.71 -                String el = cp.substring(p, n);
    1.72 -                URL u = new URL(new URL(url), el);
    1.73 -                classpath = addToArray(classpath, u.toString());
    1.74 -                p = n + 1;
    1.75 -            }
    1.76 +            return is.getMainClass();
    1.77          }
    1.78      }
    1.79  
    1.80 -    private static InputStream initIS(InputStream is) throws IOException {
    1.81 -        return new ParseCPAttr(is);
    1.82 -    }
    1.83 -    
    1.84      private static Object[] addToArray(Object[] arr, String value) {
    1.85          final int last = arr.length;
    1.86          Object[] ret = enlargeArray(arr, last + 1);