1.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java Mon May 26 10:19:43 2014 +0200
1.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java Mon May 26 17:52:56 2014 +0200
1.3 @@ -46,6 +46,7 @@
1.4 import org.apache.maven.plugins.annotations.Parameter;
1.5 import org.apache.maven.plugins.annotations.ResolutionScope;
1.6 import org.apache.maven.project.MavenProject;
1.7 +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
1.8 import org.apidesign.vm4brwsr.Bck2Brwsr;
1.9 import org.apidesign.vm4brwsr.ObfuscationLevel;
1.10
1.11 @@ -130,22 +131,12 @@
1.12 }
1.13
1.14 private void aotLibrary(Artifact a, File js, URLClassLoader loader) throws IOException {
1.15 - List<String> classes = new ArrayList<String>();
1.16 - List<String> resources = new ArrayList<String>();
1.17 - Set<String> exported = new HashSet<String>();
1.18 -
1.19 - JarFile jf = new JarFile(a.getFile());
1.20 - listJAR(jf, classes , resources, exported);
1.21 -
1.22 FileWriter w = new FileWriter(js);
1.23 - Bck2Brwsr.newCompiler().
1.24 - obfuscation(obfuscation).
1.25 - library(true).
1.26 - resources(loader).
1.27 - addResources(resources.toArray(new String[0])).
1.28 - addClasses(classes.toArray(new String[0])).
1.29 - addExported(exported.toArray(new String[0])).
1.30 - generate(w);
1.31 + Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile());
1.32 + c.
1.33 + obfuscation(obfuscation).
1.34 + resources(loader).
1.35 + generate(w);
1.36 w.close();
1.37 }
1.38 private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
1.39 @@ -160,54 +151,4 @@
1.40 }
1.41 return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
1.42 }
1.43 -
1.44 - private static void listJAR(
1.45 - JarFile j, List<String> classes,
1.46 - List<String> resources, Set<String> exported
1.47 - ) throws IOException {
1.48 - Enumeration<JarEntry> en = j.entries();
1.49 - while (en.hasMoreElements()) {
1.50 - JarEntry e = en.nextElement();
1.51 - final String n = e.getName();
1.52 - if (n.endsWith("/")) {
1.53 - continue;
1.54 - }
1.55 - int last = n.lastIndexOf('/');
1.56 - String pkg = n.substring(0, last + 1);
1.57 - if (n.endsWith(".class")) {
1.58 - classes.add(n.substring(0, n.length() - 6));
1.59 - } else {
1.60 - resources.add(n);
1.61 - if (n.startsWith("META-INF/services/") && exported != null) {
1.62 - final InputStream is = j.getInputStream(e);
1.63 - exportedServices(is, exported);
1.64 - is.close();
1.65 - }
1.66 - }
1.67 - }
1.68 - String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
1.69 - if (exp != null && exported != null) {
1.70 - for (String def : exp.split(",")) {
1.71 - for (String sep : def.split(";")) {
1.72 - exported.add(sep.replace('.', '/') + "/");
1.73 - break;
1.74 - }
1.75 - }
1.76 - }
1.77 - }
1.78 -
1.79 - static void exportedServices(final InputStream is, Set<String> exported) throws IOException {
1.80 - BufferedReader r = new BufferedReader(new InputStreamReader(is));
1.81 - for (;;) {
1.82 - String l = r.readLine();
1.83 - if (l == null) {
1.84 - break;
1.85 - }
1.86 - if (l.startsWith("#")) {
1.87 - continue;
1.88 - }
1.89 - exported.add(l.replace('.', '/'));
1.90 - }
1.91 - }
1.92 -
1.93 }