Moving the JAR file parsing and processing into a shared library closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 26 May 2014 17:52:56 +0200
branchclosure
changeset 159936746c46716a
parent 1598 ec62383beb7d
child 1600 824cb8b9c4f9
Moving the JAR file parsing and processing into a shared library
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
launcher/http/pom.xml
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java
rt/aot/pom.xml
rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java
rt/mojo/pom.xml
rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java
rt/pom.xml
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon May 26 16:20:51 2014 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon May 26 17:52:56 2014 +0200
     1.3 @@ -562,7 +562,7 @@
     1.4  
     1.5      abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader) throws IOException;
     1.6      abstract String harnessResource();
     1.7 -    String compileJar(JarFile jar) throws IOException {
     1.8 +    String compileJar(URL jar) throws IOException {
     1.9          return null;
    1.10      }
    1.11      String compileFromClassPath(URL f, Res loader) throws IOException {
    1.12 @@ -582,8 +582,8 @@
    1.13      final class Res {
    1.14          private final Set<URL> ignore = new HashSet<URL>();
    1.15          
    1.16 -        String compileJar(JarFile jar, URL jarURL) throws IOException {
    1.17 -            String ret = BaseHTTPLauncher.this.compileJar(jar);
    1.18 +        String compileJar(URL jarURL) throws IOException {
    1.19 +            String ret = BaseHTTPLauncher.this.compileJar(jarURL);
    1.20              ignore.add(jarURL);
    1.21              return ret;
    1.22          }
    1.23 @@ -745,7 +745,7 @@
    1.24                  response.setCharacterEncoding("UTF-8");
    1.25                  if (url.getProtocol().equals("jar")) {
    1.26                      JarURLConnection juc = (JarURLConnection) url.openConnection();
    1.27 -                    String s = loader.compileJar(juc.getJarFile(), juc.getJarFileURL());
    1.28 +                    String s = loader.compileJar(juc.getJarFileURL());
    1.29                      if (s != null) {
    1.30                          Writer w = response.getWriter();
    1.31                          w.append(s);
     2.1 --- a/launcher/http/pom.xml	Mon May 26 16:20:51 2014 +0200
     2.2 +++ b/launcher/http/pom.xml	Mon May 26 17:52:56 2014 +0200
     2.3 @@ -67,5 +67,11 @@
     2.4        <version>${project.version}</version>
     2.5        <scope>test</scope>
     2.6      </dependency>
     2.7 +    <dependency>
     2.8 +      <groupId>org.apidesign.bck2brwsr</groupId>
     2.9 +      <artifactId>aot</artifactId>
    2.10 +      <version>0.9-SNAPSHOT</version>
    2.11 +      <type>jar</type>
    2.12 +    </dependency>
    2.13    </dependencies>
    2.14  </project>
     3.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon May 26 16:20:51 2014 +0200
     3.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Mon May 26 17:52:56 2014 +0200
     3.3 @@ -18,16 +18,14 @@
     3.4  package org.apidesign.bck2brwsr.launcher;
     3.5  
     3.6  import java.io.File;
     3.7 -import java.io.FileReader;
     3.8  import java.io.IOException;
     3.9 -import java.io.InputStream;
    3.10  import java.io.InputStreamReader;
    3.11  import java.io.Reader;
    3.12  import java.net.MalformedURLException;
    3.13 +import java.net.URISyntaxException;
    3.14  import java.net.URL;
    3.15  import java.util.HashSet;
    3.16  import java.util.Set;
    3.17 -import java.util.jar.JarFile;
    3.18  import java.util.logging.Level;
    3.19  
    3.20  /**
    3.21 @@ -48,8 +46,14 @@
    3.22      }
    3.23  
    3.24      @Override
    3.25 -    String compileJar(JarFile jar) throws IOException {
    3.26 -        return CompileCP.compileJAR(jar, testClasses);
    3.27 +    String compileJar(URL jar) throws IOException {
    3.28 +        File f;
    3.29 +        try {
    3.30 +            f = new File(jar.toURI());
    3.31 +        } catch (URISyntaxException ex) {
    3.32 +            throw new IOException(ex);
    3.33 +        }
    3.34 +        return CompileCP.compileJAR(f, testClasses);
    3.35      }
    3.36  
    3.37      @Override
     4.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Mon May 26 16:20:51 2014 +0200
     4.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Mon May 26 17:52:56 2014 +0200
     4.3 @@ -17,28 +17,22 @@
     4.4   */
     4.5  package org.apidesign.bck2brwsr.launcher;
     4.6  
     4.7 -import java.io.BufferedReader;
     4.8  import java.io.File;
     4.9  import java.io.IOException;
    4.10  import java.io.InputStream;
    4.11 -import java.io.InputStreamReader;
    4.12  import java.io.StringWriter;
    4.13  import java.net.JarURLConnection;
    4.14  import java.net.URISyntaxException;
    4.15  import java.net.URL;
    4.16  import java.util.ArrayList;
    4.17  import java.util.Enumeration;
    4.18 -import java.util.HashSet;
    4.19  import java.util.List;
    4.20  import java.util.Set;
    4.21 -import java.util.jar.JarEntry;
    4.22 -import java.util.jar.JarFile;
    4.23  import java.util.logging.Level;
    4.24  import java.util.logging.Logger;
    4.25 -import java.util.zip.ZipEntry;
    4.26 +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
    4.27  import org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher.Res;
    4.28  import org.apidesign.vm4brwsr.Bck2Brwsr;
    4.29 -import org.apidesign.vm4brwsr.ObfuscationLevel;
    4.30  
    4.31  /**
    4.32   *
    4.33 @@ -46,31 +40,11 @@
    4.34   */
    4.35  class CompileCP {
    4.36      private static final Logger LOG = Logger.getLogger(CompileCP.class.getName());
    4.37 -    static String compileJAR(final JarFile jar, Set<String> testClasses) 
    4.38 +    static String compileJAR(final File jar, Set<String> testClasses) 
    4.39      throws IOException {
    4.40 -        List<String> arr = new ArrayList<>();
    4.41 -        List<String> classes = new ArrayList<>();
    4.42 -        Set<String> keep = new HashSet<String>(testClasses);
    4.43 -        listJAR(jar, classes, arr, keep);
    4.44 -        
    4.45          StringWriter w = new StringWriter();
    4.46          try {
    4.47 -            class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
    4.48 -                @Override
    4.49 -                public InputStream get(String resource) throws IOException {
    4.50 -                    InputStream is = jar.getInputStream(new ZipEntry(resource));
    4.51 -                    return is == null ? super.get(resource) : is;
    4.52 -                }
    4.53 -            }
    4.54 -            
    4.55 -            Bck2Brwsr.newCompiler()
    4.56 -                .addClasses(classes.toArray(new String[0]))
    4.57 -                .addExported(keep.toArray(new String[0]))
    4.58 -                .addResources(arr.toArray(new String[0]))
    4.59 -                //.obfuscation(ObfuscationLevel.FULL)
    4.60 -                .library(true)
    4.61 -                .resources(new JarRes())
    4.62 -                .generate(w);
    4.63 +            Bck2BrwsrJars.configureFrom(null, jar).generate(w);
    4.64              w.flush();
    4.65              return w.toString();
    4.66          } catch (IOException ex) {
    4.67 @@ -126,56 +100,7 @@
    4.68          return null;
    4.69      }
    4.70      
    4.71 -    private static void listJAR(
    4.72 -        JarFile j, List<String> classes,
    4.73 -        List<String> resources, Set<String> keep
    4.74 -    ) throws IOException {
    4.75 -        Enumeration<JarEntry> en = j.entries();
    4.76 -        while (en.hasMoreElements()) {
    4.77 -            JarEntry e = en.nextElement();
    4.78 -            final String n = e.getName();
    4.79 -            if (n.endsWith("/")) {
    4.80 -                continue;
    4.81 -            }
    4.82 -            int last = n.lastIndexOf('/');
    4.83 -            String pkg = n.substring(0, last + 1);
    4.84 -            if (skipPkg(pkg)) {
    4.85 -                continue;
    4.86 -            }
    4.87 -            if (n.endsWith(".class")) {
    4.88 -                classes.add(n.substring(0, n.length() - 6));
    4.89 -            } else {
    4.90 -                resources.add(n);
    4.91 -                if (n.startsWith("META-INF/services/") && keep != null) {
    4.92 -                    BufferedReader r = new BufferedReader(new InputStreamReader(j.getInputStream(e)));
    4.93 -                    for (;;) {
    4.94 -                        String l = r.readLine();
    4.95 -                        if (l == null) {
    4.96 -                            break;
    4.97 -                        }
    4.98 -                        if (l.startsWith("#")) {
    4.99 -                            continue;
   4.100 -                        }
   4.101 -                        keep.add(l.replace('.', '/'));
   4.102 -                    }
   4.103 -                }
   4.104 -            }
   4.105 -        }
   4.106 -        String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
   4.107 -        if (exp != null && keep != null) {
   4.108 -            for (String def : exp.split(",")) {
   4.109 -                for (String sep : def.split(";")) {
   4.110 -                    keep.add(sep.replace('.', '/') + "/");
   4.111 -                    break;
   4.112 -                }
   4.113 -            }
   4.114 -        }
   4.115 -    }
   4.116  
   4.117 -    private static boolean skipPkg(String pkg) {
   4.118 -        return pkg.equals("org/apidesign/bck2brwsr/launcher/");
   4.119 -    }
   4.120 -    
   4.121      private static void listDir(File f, String pref, List<String> classes, List<String> resources) throws IOException {
   4.122          File[] arr = f.listFiles();
   4.123          if (arr == null) {
   4.124 @@ -193,21 +118,24 @@
   4.125      }
   4.126  
   4.127      static void compileVM(StringBuilder sb, final Res r) throws IOException {
   4.128 -        List<String> arr = new ArrayList<>();
   4.129 -        List<String> classes = new ArrayList<>();
   4.130 -
   4.131 -        {
   4.132 +        final Bck2Brwsr rt;
   4.133 +        try {
   4.134              URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
   4.135              JarURLConnection juc = (JarURLConnection)u.openConnection();
   4.136 -            listJAR(juc.getJarFile(), classes, arr, null);
   4.137 +            rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
   4.138 +        } catch (URISyntaxException ex) {
   4.139 +            throw new IOException(ex);
   4.140          }
   4.141 -        {
   4.142 +        final Bck2Brwsr all;
   4.143 +        try {
   4.144              URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
   4.145              JarURLConnection juc = (JarURLConnection)u.openConnection();
   4.146 -            listJAR(juc.getJarFile(), classes, arr, null);
   4.147 +            all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI()));
   4.148 +        } catch (URISyntaxException ex) {
   4.149 +            throw new IOException(ex);
   4.150          }
   4.151  
   4.152 -        Bck2Brwsr.newCompiler().addRootClasses(classes.toArray(new String[0]))
   4.153 +        all.library(false)
   4.154              //.obfuscation(ObfuscationLevel.FULL)
   4.155              .resources(new Bck2Brwsr.Resources() {
   4.156                  @Override
   4.157 @@ -222,7 +150,7 @@
   4.158  
   4.159          @Override
   4.160          public InputStream get(String name) throws IOException {
   4.161 -            Enumeration<URL> en = CompileCP.class.getClassLoader().getResources(name);
   4.162 +            Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
   4.163              URL u = null;
   4.164              while (en.hasMoreElements()) {
   4.165                  u = en.nextElement();
   4.166 @@ -232,10 +160,11 @@
   4.167                  return null;
   4.168              }
   4.169              if (u.toExternalForm().contains("/rt.jar!")) {
   4.170 -                LOG.warning(name + "No bootdelegation for ");
   4.171 +                LOG.log(Level.WARNING, "{0}No bootdelegation for ", name);
   4.172                  return null;
   4.173              }
   4.174              return u.openStream();
   4.175          }
   4.176      }
   4.177 +    
   4.178  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/rt/aot/pom.xml	Mon May 26 17:52:56 2014 +0200
     5.3 @@ -0,0 +1,20 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5.6 +    <modelVersion>4.0.0</modelVersion>
     5.7 +    <parent>
     5.8 +        <groupId>org.apidesign.bck2brwsr</groupId>
     5.9 +        <artifactId>rt</artifactId>
    5.10 +        <version>0.9-SNAPSHOT</version>
    5.11 +    </parent>
    5.12 +    <name>Ahead of Time Compilation</name>
    5.13 +    <artifactId>aot</artifactId>
    5.14 +    <packaging>jar</packaging>
    5.15 +    <dependencies>
    5.16 +        <dependency>
    5.17 +            <groupId>org.apidesign.bck2brwsr</groupId>
    5.18 +            <artifactId>vm4brwsr</artifactId>
    5.19 +            <version>${project.version}</version>
    5.20 +            <type>jar</type>
    5.21 +        </dependency>
    5.22 +    </dependencies>
    5.23 +</project>
    5.24 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Mon May 26 17:52:56 2014 +0200
     6.3 @@ -0,0 +1,157 @@
     6.4 +/**
     6.5 + * Back 2 Browser Bytecode Translator
     6.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 + *
     6.8 + * This program is free software: you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU General Public License as published by
    6.10 + * the Free Software Foundation, version 2 of the License.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU General Public License
    6.18 + * along with this program. Look for COPYING file in the top folder.
    6.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 + */
    6.21 +package org.apidesign.bck2brwsr.aot;
    6.22 +
    6.23 +import java.io.BufferedReader;
    6.24 +import java.io.File;
    6.25 +import java.io.IOException;
    6.26 +import java.io.InputStream;
    6.27 +import java.io.InputStreamReader;
    6.28 +import java.net.URL;
    6.29 +import java.util.ArrayList;
    6.30 +import java.util.Enumeration;
    6.31 +import java.util.HashSet;
    6.32 +import java.util.List;
    6.33 +import java.util.Set;
    6.34 +import java.util.jar.JarEntry;
    6.35 +import java.util.jar.JarFile;
    6.36 +import java.util.logging.Level;
    6.37 +import java.util.logging.Logger;
    6.38 +import java.util.zip.ZipEntry;
    6.39 +import org.apidesign.vm4brwsr.Bck2Brwsr;
    6.40 +
    6.41 +/** Utilities to process JAR files and set a compiler
    6.42 + * up 
    6.43 + *
    6.44 + * @author Jaroslav Tulach
    6.45 + */
    6.46 +public final class Bck2BrwsrJars {
    6.47 +    private static final Logger LOG = Logger.getLogger(Bck2BrwsrJars.class.getName());
    6.48 +    
    6.49 +    private Bck2BrwsrJars() {
    6.50 +    }
    6.51 +    
    6.52 +    /** Creates new compiler pre-configured from the content of 
    6.53 +     * provided JAR file. The compiler will compile all classes.
    6.54 +     * The system understands OSGi manifest entries and will export
    6.55 +     * all packages that are exported in the JAR file. The system
    6.56 +     * also recognizes META-INF/services and makes sure the file names
    6.57 +     * are not mangled.
    6.58 +     * 
    6.59 +     * @param c the compiler to {@link Bck2Brwsr#addClasses(java.lang.String...) add classes},
    6.60 +     *    {@link Bck2Brwsr#addResources(java.lang.String...) add resources} and
    6.61 +     *    {@link Bck2Brwsr#addExported(java.lang.String...) exported objects} to.
    6.62 +     *    Can be <code>null</code> - in such case an 
    6.63 +     *    {@link Bck2Brwsr#newCompiler() empty compiler} is constructed.
    6.64 +     * @param jar the file to process
    6.65 +     * @return newly configured compiler
    6.66 +     * @throws IOException if something goes wrong
    6.67 +     */
    6.68 +    public static Bck2Brwsr configureFrom(Bck2Brwsr c, File jar) throws IOException {
    6.69 +        try (JarFile jf = new JarFile(jar)) {
    6.70 +            List<String> classes = new ArrayList<>();
    6.71 +            List<String> resources = new ArrayList<>();
    6.72 +            Set<String> exported = new HashSet<>();
    6.73 +            
    6.74 +            listJAR(jf, classes, resources, exported);
    6.75 +            
    6.76 +            class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
    6.77 +
    6.78 +                @Override
    6.79 +                public InputStream get(String resource) throws IOException {
    6.80 +                    InputStream is = jf.getInputStream(new ZipEntry(resource));
    6.81 +                    return is == null ? super.get(resource) : is;
    6.82 +                }
    6.83 +            }
    6.84 +            return Bck2Brwsr.newCompiler()
    6.85 +                .library(true)
    6.86 +                .addClasses(classes.toArray(new String[classes.size()]))
    6.87 +                .addExported(exported.toArray(new String[exported.size()]))
    6.88 +                .addResources(resources.toArray(new String[resources.size()]))
    6.89 +                .resources(new JarRes());
    6.90 +        }
    6.91 +    }
    6.92 +    
    6.93 +    private static void listJAR(
    6.94 +        JarFile j, List<String> classes,
    6.95 +        List<String> resources, Set<String> keep
    6.96 +    ) throws IOException {
    6.97 +        Enumeration<JarEntry> en = j.entries();
    6.98 +        while (en.hasMoreElements()) {
    6.99 +            JarEntry e = en.nextElement();
   6.100 +            final String n = e.getName();
   6.101 +            if (n.endsWith("/")) {
   6.102 +                continue;
   6.103 +            }
   6.104 +            int last = n.lastIndexOf('/');
   6.105 +            String pkg = n.substring(0, last + 1);
   6.106 +            if (pkg.startsWith("java/")) {
   6.107 +                keep.add(pkg);
   6.108 +            }
   6.109 +            if (n.endsWith(".class")) {
   6.110 +                classes.add(n.substring(0, n.length() - 6));
   6.111 +            } else {
   6.112 +                resources.add(n);
   6.113 +                if (n.startsWith("META-INF/services/") && keep != null) {
   6.114 +                    BufferedReader r = new BufferedReader(new InputStreamReader(j.getInputStream(e)));
   6.115 +                    for (;;) {
   6.116 +                        String l = r.readLine();
   6.117 +                        if (l == null) {
   6.118 +                            break;
   6.119 +                        }
   6.120 +                        if (l.startsWith("#")) {
   6.121 +                            continue;
   6.122 +                        }
   6.123 +                        keep.add(l.replace('.', '/'));
   6.124 +                    }
   6.125 +                }
   6.126 +            }
   6.127 +        }
   6.128 +        String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
   6.129 +        if (exp != null && keep != null) {
   6.130 +            for (String def : exp.split(",")) {
   6.131 +                for (String sep : def.split(";")) {
   6.132 +                    keep.add(sep.replace('.', '/') + "/");
   6.133 +                    break;
   6.134 +                }
   6.135 +            }
   6.136 +        }
   6.137 +    }
   6.138 +
   6.139 +    static class EmulationResources implements Bck2Brwsr.Resources {
   6.140 +
   6.141 +        @Override
   6.142 +        public InputStream get(String name) throws IOException {
   6.143 +            Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
   6.144 +            URL u = null;
   6.145 +            while (en.hasMoreElements()) {
   6.146 +                u = en.nextElement();
   6.147 +            }
   6.148 +            if (u == null) {
   6.149 +                LOG.log(Level.WARNING, "Cannot find {0}", name);
   6.150 +                return null;
   6.151 +            }
   6.152 +            if (u.toExternalForm().contains("/rt.jar!")) {
   6.153 +                LOG.log(Level.WARNING, "{0}No bootdelegation for ", name);
   6.154 +                return null;
   6.155 +            }
   6.156 +            return u.openStream();
   6.157 +        }
   6.158 +    }
   6.159 +    
   6.160 +}
     7.1 --- a/rt/mojo/pom.xml	Mon May 26 16:20:51 2014 +0200
     7.2 +++ b/rt/mojo/pom.xml	Mon May 26 17:52:56 2014 +0200
     7.3 @@ -91,5 +91,11 @@
     7.4          <artifactId>launcher.fx</artifactId>
     7.5        <version>${project.version}</version>
     7.6      </dependency>
     7.7 +    <dependency>
     7.8 +        <groupId>org.apidesign.bck2brwsr</groupId>
     7.9 +        <artifactId>aot</artifactId>
    7.10 +      <version>0.9-SNAPSHOT</version>
    7.11 +      <type>jar</type>
    7.12 +    </dependency>
    7.13  </dependencies>
    7.14  </project>
     8.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java	Mon May 26 16:20:51 2014 +0200
     8.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java	Mon May 26 17:52:56 2014 +0200
     8.3 @@ -46,6 +46,7 @@
     8.4  import org.apache.maven.plugins.annotations.Parameter;
     8.5  import org.apache.maven.plugins.annotations.ResolutionScope;
     8.6  import org.apache.maven.project.MavenProject;
     8.7 +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
     8.8  import org.apidesign.vm4brwsr.Bck2Brwsr;
     8.9  import org.apidesign.vm4brwsr.ObfuscationLevel;
    8.10  
    8.11 @@ -130,22 +131,12 @@
    8.12      }
    8.13  
    8.14      private void aotLibrary(Artifact a, File js, URLClassLoader loader) throws IOException {
    8.15 -        List<String> classes = new ArrayList<String>();
    8.16 -        List<String> resources = new ArrayList<String>();
    8.17 -        Set<String> exported = new HashSet<String>();
    8.18 -        
    8.19 -        JarFile jf = new JarFile(a.getFile());
    8.20 -        listJAR(jf, classes , resources, exported);
    8.21 -        
    8.22          FileWriter w = new FileWriter(js);
    8.23 -        Bck2Brwsr.newCompiler().
    8.24 -                obfuscation(obfuscation).
    8.25 -                library(true).
    8.26 -                resources(loader).
    8.27 -                addResources(resources.toArray(new String[0])).
    8.28 -                addClasses(classes.toArray(new String[0])).
    8.29 -                addExported(exported.toArray(new String[0])).
    8.30 -                generate(w);
    8.31 +        Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile());
    8.32 +        c.
    8.33 +            obfuscation(obfuscation).
    8.34 +            resources(loader).
    8.35 +            generate(w);
    8.36          w.close();
    8.37      }
    8.38      private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
    8.39 @@ -160,54 +151,4 @@
    8.40          }
    8.41          return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
    8.42      }
    8.43 -    
    8.44 -    private static void listJAR(
    8.45 -            JarFile j, List<String> classes,
    8.46 -            List<String> resources, Set<String> exported
    8.47 -    ) throws IOException {
    8.48 -        Enumeration<JarEntry> en = j.entries();
    8.49 -        while (en.hasMoreElements()) {
    8.50 -            JarEntry e = en.nextElement();
    8.51 -            final String n = e.getName();
    8.52 -            if (n.endsWith("/")) {
    8.53 -                continue;
    8.54 -            }
    8.55 -            int last = n.lastIndexOf('/');
    8.56 -            String pkg = n.substring(0, last + 1);
    8.57 -            if (n.endsWith(".class")) {
    8.58 -                classes.add(n.substring(0, n.length() - 6));
    8.59 -            } else {
    8.60 -                resources.add(n);
    8.61 -                if (n.startsWith("META-INF/services/") && exported != null) {
    8.62 -                    final InputStream is = j.getInputStream(e);
    8.63 -                    exportedServices(is, exported);
    8.64 -                    is.close();
    8.65 -                }
    8.66 -            }
    8.67 -        }
    8.68 -        String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
    8.69 -        if (exp != null && exported != null) {
    8.70 -            for (String def : exp.split(",")) {
    8.71 -                for (String sep : def.split(";")) {
    8.72 -                    exported.add(sep.replace('.', '/') + "/");
    8.73 -                    break;
    8.74 -                }
    8.75 -            }
    8.76 -        }
    8.77 -    }
    8.78 -
    8.79 -    static void exportedServices(final InputStream is, Set<String> exported) throws IOException {
    8.80 -        BufferedReader r = new BufferedReader(new InputStreamReader(is));
    8.81 -        for (;;) {
    8.82 -            String l = r.readLine();
    8.83 -            if (l == null) {
    8.84 -                break;
    8.85 -            }
    8.86 -            if (l.startsWith("#")) {
    8.87 -                continue;
    8.88 -            }
    8.89 -            exported.add(l.replace('.', '/'));
    8.90 -        }
    8.91 -    }
    8.92 -    
    8.93  }
     9.1 --- a/rt/pom.xml	Mon May 26 16:20:51 2014 +0200
     9.2 +++ b/rt/pom.xml	Mon May 26 17:52:56 2014 +0200
     9.3 @@ -17,5 +17,6 @@
     9.4      <module>mojo</module>
     9.5      <module>vm</module>
     9.6      <module>vmtest</module>
     9.7 +    <module>aot</module>
     9.8    </modules>
     9.9  </project>