Need to be able to load classes from classpath to find out if a method overrides something in a superclass.
1.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Fri Sep 26 10:44:54 2014 +0200
1.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Fri Sep 26 13:42:15 2014 +0200
1.3 @@ -68,8 +68,33 @@
1.4 * @throws IOException if something goes wrong
1.5 */
1.6 public static Bck2Brwsr configureFrom(Bck2Brwsr c, File jar) throws IOException {
1.7 + return configureFrom(c, jar, null);
1.8 + }
1.9 +
1.10 + /** Creates new compiler pre-configured from the content of
1.11 + * provided JAR file. The compiler will compile all classes.
1.12 + * The system understands OSGi manifest entries and will export
1.13 + * all packages that are exported in the JAR file. The system
1.14 + * also recognizes META-INF/services and makes sure the class names
1.15 + * are not mangled.
1.16 + *
1.17 + * @param c the compiler to {@link Bck2Brwsr#addClasses(java.lang.String...) add classes},
1.18 + * {@link Bck2Brwsr#addResources(java.lang.String...) add resources} and
1.19 + * {@link Bck2Brwsr#addExported(java.lang.String...) exported objects} to.
1.20 + * Can be <code>null</code> - in such case an
1.21 + * {@link Bck2Brwsr#newCompiler() empty compiler} is constructed.
1.22 + * @param jar the file to process
1.23 + * @param classpath additional resources to make available during
1.24 + * compilation, but not include them in the generated JavaScript
1.25 + * @return newly configured compiler
1.26 + * @throws IOException if something goes wrong
1.27 + * @since 0.11
1.28 + */
1.29 + public static Bck2Brwsr configureFrom(
1.30 + Bck2Brwsr c, File jar, final ClassLoader classpath
1.31 + ) throws IOException {
1.32 if (jar.isDirectory()) {
1.33 - return configureDir(c, jar);
1.34 + return configureDir(c, jar, classpath);
1.35 }
1.36 final JarFile jf = new JarFile(jar);
1.37 final List<String> classes = new ArrayList<>();
1.38 @@ -77,7 +102,7 @@
1.39 Set<String> exported = new HashSet<>();
1.40 class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
1.41 JarRes() {
1.42 - super(classes);
1.43 + super(classpath, classes);
1.44 }
1.45 @Override
1.46 public InputStream get(String resource) throws IOException {
1.47 @@ -94,14 +119,14 @@
1.48 listJAR(jf, jarRes, resources, exported);
1.49
1.50 String cp = jf.getManifest().getMainAttributes().getValue("Class-Path"); // NOI18N
1.51 - String[] classpath = cp == null ? new String[0] : cp.split(" ");
1.52 + String[] parts = cp == null ? new String[0] : cp.split(" ");
1.53
1.54 if (c == null) {
1.55 c = Bck2Brwsr.newCompiler();
1.56 }
1.57
1.58 return c
1.59 - .library(classpath)
1.60 + .library(parts)
1.61 .addClasses(classes.toArray(new String[classes.size()]))
1.62 .addExported(exported.toArray(new String[exported.size()]))
1.63 .addResources(resources.toArray(new String[resources.size()]))
1.64 @@ -189,9 +214,11 @@
1.65 private final List<String> classes;
1.66 private final Map<String,byte[]> converted = new HashMap<>();
1.67 private final BytecodeProcessor proc;
1.68 + private final ClassLoader cp;
1.69
1.70 - protected EmulationResources(List<String> classes) {
1.71 + protected EmulationResources(ClassLoader cp, List<String> classes) {
1.72 this.classes = classes;
1.73 + this.cp = cp != null ? cp : Bck2BrwsrJars.class.getClassLoader();
1.74 BytecodeProcessor p;
1.75 try {
1.76 Class<?> bpClass = Class.forName("org.apidesign.bck2brwsr.aot.RetroLambda");
1.77 @@ -216,7 +243,7 @@
1.78 if (is != null) {
1.79 return is;
1.80 }
1.81 - Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
1.82 + Enumeration<URL> en = cp.getResources(name);
1.83 URL u = null;
1.84 while (en.hasMoreElements()) {
1.85 u = en.nextElement();
1.86 @@ -259,12 +286,12 @@
1.87 }
1.88 }
1.89
1.90 - private static Bck2Brwsr configureDir(Bck2Brwsr c, final File dir) throws IOException {
1.91 + private static Bck2Brwsr configureDir(Bck2Brwsr c, final File dir, ClassLoader cp) throws IOException {
1.92 List<String> arr = new ArrayList<>();
1.93 List<String> classes = new ArrayList<>();
1.94 class DirRes extends EmulationResources {
1.95 - public DirRes(List<String> classes) {
1.96 - super(classes);
1.97 + public DirRes(ClassLoader cp, List<String> classes) {
1.98 + super(cp, classes);
1.99 }
1.100
1.101 @Override
1.102 @@ -280,7 +307,7 @@
1.103 return null;
1.104 }
1.105 }
1.106 - DirRes dirRes = new DirRes(classes);
1.107 + DirRes dirRes = new DirRes(cp, classes);
1.108 listDir(dir, null, dirRes, arr);
1.109 if (c == null) {
1.110 c = Bck2Brwsr.newCompiler();
2.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java Fri Sep 26 10:44:54 2014 +0200
2.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java Fri Sep 26 13:42:15 2014 +0200
2.3 @@ -121,7 +121,7 @@
2.4 getLog().info("Skipping " + mainJavaScript + " as it already exists.");
2.5 } else {
2.6 getLog().info("Generating " + mainJavaScript);
2.7 - Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar);
2.8 + Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader);
2.9 if (exports != null) {
2.10 for (String e : exports) {
2.11 c = c.addExported(e.replace('.', '/'));
2.12 @@ -159,10 +159,9 @@
2.13
2.14 private void aotLibrary(Artifact a, File js, URLClassLoader loader) throws IOException {
2.15 FileWriter w = new FileWriter(js);
2.16 - Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile());
2.17 + Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile(), loader);
2.18 c.
2.19 obfuscation(obfuscation).
2.20 - resources(loader).
2.21 generate(w);
2.22 w.close();
2.23 }