Honor ignoreBootClassPath attribute in all mojos
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 11 Jan 2015 09:54:37 +0100
changeset 1769f6057dc5922c
parent 1766 75671373fa87
child 1770 223aedca178d
Honor ignoreBootClassPath attribute in all mojos
rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java
rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java
rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java
     1.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Sat Jan 10 19:38:00 2015 +0100
     1.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Sun Jan 11 09:54:37 2015 +0100
     1.3 @@ -96,8 +96,35 @@
     1.4      public static Bck2Brwsr configureFrom(
     1.5          Bck2Brwsr c, File jar, final ClassLoader classpath
     1.6      ) throws IOException {
     1.7 +        return configureFrom(c, jar, classpath, true);
     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 NetBeans
    1.13 +     * module system manifest entries and will export
    1.14 +     * all packages that are exported in the JAR file. The system
    1.15 +     * also recognizes META-INF/services and makes sure the class names
    1.16 +     * are not mangled.
    1.17 +     * 
    1.18 +     * @param c the compiler to {@link Bck2Brwsr#addClasses(java.lang.String...) add classes},
    1.19 +     *    {@link Bck2Brwsr#addResources(java.lang.String...) add resources} and
    1.20 +     *    {@link Bck2Brwsr#addExported(java.lang.String...) exported objects} to.
    1.21 +     *    Can be <code>null</code> - in such case an 
    1.22 +     *    {@link Bck2Brwsr#newCompiler() empty compiler} is constructed.
    1.23 +     * @param jar the file to process
    1.24 +     * @param classpath additional resources to make available during
    1.25 +     *   compilation, but not include them in the generated JavaScript
    1.26 +     * @param ignoreBootClassPath should we ignore classes on bootclasspath?
    1.27 +     * @return newly configured compiler
    1.28 +     * @throws IOException if something goes wrong
    1.29 +     * @since 0.14
    1.30 +     */
    1.31 +    public static Bck2Brwsr configureFrom(
    1.32 +        Bck2Brwsr c, File jar, final ClassLoader classpath, final boolean ignoreBootClassPath
    1.33 +    ) throws IOException {
    1.34          if (jar.isDirectory()) {
    1.35 -            return configureDir(c, jar, classpath);
    1.36 +            return configureDir(ignoreBootClassPath, c, jar, classpath);
    1.37          }
    1.38          final JarFile jf = new JarFile(jar);
    1.39          final List<String> classes = new ArrayList<>();
    1.40 @@ -105,7 +132,7 @@
    1.41          Set<String> exported = new HashSet<>();
    1.42          class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
    1.43              JarRes() {
    1.44 -                super(classpath, classes);
    1.45 +                super(ignoreBootClassPath, classpath, classes);
    1.46              }
    1.47              @Override
    1.48              public InputStream get(String resource) throws IOException {
    1.49 @@ -236,8 +263,10 @@
    1.50          private final Map<String,byte[]> converted = new HashMap<>();
    1.51          private final BytecodeProcessor proc;
    1.52          private final ClassLoader cp;
    1.53 +        private final boolean ignoreBootClassPath;
    1.54  
    1.55 -        protected EmulationResources(ClassLoader cp, List<String> classes) {
    1.56 +        protected EmulationResources(boolean ignoreBootClassPath, ClassLoader cp, List<String> classes) {
    1.57 +            this.ignoreBootClassPath = ignoreBootClassPath;
    1.58              this.classes = classes;
    1.59              this.cp = cp != null ? cp : Bck2BrwsrJars.class.getClassLoader();
    1.60              BytecodeProcessor p;
    1.61 @@ -273,7 +302,7 @@
    1.62                  LOG.log(Level.FINE, "Cannot find {0}", name);
    1.63                  return null;
    1.64              }
    1.65 -            if (u.toExternalForm().contains("/rt.jar!")) {
    1.66 +            if (ignoreBootClassPath && u.toExternalForm().contains("/rt.jar!")) {
    1.67                  LOG.log(Level.WARNING, "No bootdelegation for {0}", name);
    1.68                  return null;
    1.69              }
    1.70 @@ -307,12 +336,12 @@
    1.71          }
    1.72      }
    1.73      
    1.74 -    private static Bck2Brwsr configureDir(Bck2Brwsr c, final File dir, ClassLoader cp) throws IOException {
    1.75 +    private static Bck2Brwsr configureDir(final boolean ignoreBootClassPath, Bck2Brwsr c, final File dir, ClassLoader cp) throws IOException {
    1.76          List<String> arr = new ArrayList<>();
    1.77          List<String> classes = new ArrayList<>();
    1.78          class DirRes extends EmulationResources {
    1.79              public DirRes(ClassLoader cp, List<String> classes) {
    1.80 -                super(cp, classes);
    1.81 +                super(ignoreBootClassPath, cp, classes);
    1.82              }
    1.83  
    1.84              @Override
     2.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sat Jan 10 19:38:00 2015 +0100
     2.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AOTLibrary.java	Sun Jan 11 09:54:37 2015 +0100
     2.3 @@ -78,7 +78,10 @@
     2.4      
     2.5      @Parameter
     2.6      private String[] aotDeps;
     2.7 -    
     2.8 +
     2.9 +    @Parameter(defaultValue = "true")
    2.10 +    private boolean ignoreBootClassPath;
    2.11 +
    2.12      @Override
    2.13      public void execute() throws MojoExecutionException, MojoFailureException {
    2.14          URLClassLoader loader;
    2.15 @@ -161,7 +164,7 @@
    2.16                          continue;
    2.17                      }
    2.18                      getLog().info("Generating bck2brwsr for " + a.getFile());
    2.19 -                    Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile(), loader);
    2.20 +                    Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile(), loader, ignoreBootClassPath);
    2.21                      if (exports != null) {
    2.22                          for (String e : exports) {
    2.23                              c = c.addExported(e.replace('.', '/'));
    2.24 @@ -197,7 +200,7 @@
    2.25      }
    2.26  
    2.27      private Bck2Brwsr configureMain(URLClassLoader loader) throws IOException {
    2.28 -        Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader);
    2.29 +        Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader, ignoreBootClassPath);
    2.30          if (exports != null) {
    2.31              for (String e : exports) {
    2.32                  c = c.addExported(e.replace('.', '/'));
     3.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java	Sat Jan 10 19:38:00 2015 +0100
     3.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java	Sun Jan 11 09:54:37 2015 +0100
     3.3 @@ -85,6 +85,9 @@
     3.4      @Parameter(defaultValue = "true")
     3.5      private boolean generateAotLibraries;
     3.6      
     3.7 +    @Parameter(defaultValue = "true")
     3.8 +    private boolean ignoreBootClassPath;
     3.9 +    
    3.10      /**
    3.11       * The obfuscation level for the generated JavaScript file.
    3.12       *
    3.13 @@ -131,7 +134,7 @@
    3.14                  getLog().info("Skipping " + mainJavaScript + " as it already exists.");
    3.15              } else {
    3.16                  getLog().info("Generating " + mainJavaScript);
    3.17 -                Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader);
    3.18 +                Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar, loader, ignoreBootClassPath);
    3.19                  if (exports != null) {
    3.20                      for (String e : exports) {
    3.21                          c = c.addExported(e.replace('.', '/'));
    3.22 @@ -201,7 +204,7 @@
    3.23          }
    3.24          getLog().info("Generating " + js);
    3.25          Writer w = new OutputStreamWriter(new FileOutputStream(js), "UTF-8");
    3.26 -        Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile(), loader);
    3.27 +        Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile(), loader, ignoreBootClassPath);
    3.28          c.
    3.29              obfuscation(obfuscation).
    3.30              generate(w);