rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java
branchclosure
changeset 1583 89b6b369c13d
parent 1513 ba912ef24b27
child 1584 7b6295731c30
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java	Wed Apr 30 15:04:10 2014 +0200
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java	Wed May 21 23:42:24 2014 +0200
     1.3 @@ -19,7 +19,6 @@
     1.4  
     1.5  import java.io.IOException;
     1.6  import java.io.InputStream;
     1.7 -import org.apidesign.bck2brwsr.core.Exported;
     1.8  
     1.9  /** Build your own virtual machine! Use methods in this class to generate
    1.10   * a skeleton JVM in JavaScript that contains pre-compiled classes of your
    1.11 @@ -54,15 +53,15 @@
    1.12   */
    1.13  public final class Bck2Brwsr {
    1.14      private final ObfuscationLevel level;
    1.15 -    private final StringArray rootcls;
    1.16 +    private final StringArray exported;
    1.17      private final StringArray classes;
    1.18      private final StringArray resources;
    1.19      private final Resources res;
    1.20      private final boolean extension;
    1.21  
    1.22 -    private Bck2Brwsr(ObfuscationLevel level, StringArray rootcls, StringArray classes, StringArray resources, Resources res, boolean extension) {
    1.23 +    private Bck2Brwsr(ObfuscationLevel level, StringArray exported, StringArray classes, StringArray resources, Resources res, boolean extension) {
    1.24          this.level = level;
    1.25 -        this.rootcls = rootcls;
    1.26 +        this.exported = exported;
    1.27          this.classes = classes;
    1.28          this.resources = resources;
    1.29          this.res = res;
    1.30 @@ -105,6 +104,27 @@
    1.31      public static Bck2Brwsr newCompiler() {
    1.32          return new Bck2Brwsr(ObfuscationLevel.NONE, new StringArray(), new StringArray(), new StringArray(), null, false);
    1.33      }
    1.34 +    
    1.35 +    /** Adds exported classes or packages. If the string ends 
    1.36 +     * with slash, it is considered a name of package. If it does not,
    1.37 +     * it is a name of a class (without <code>.class</code> suffix).
    1.38 +     * The exported classes are prevented from being obfuscated. 
    1.39 +     * All public classes in exported packages are prevented from
    1.40 +     * being obfuscated. By listing the packages or classes in this 
    1.41 +     * method, these classes are not guaranteed to be included in
    1.42 +     * the generated script. Use {@link #addClasses} to include
    1.43 +     * the classes.
    1.44 +     * 
    1.45 +     * @param exported names of classes and packages to treat as exported
    1.46 +     * @return new instances of the Bck2Brwsr compiler which inherits
    1.47 +     *   all values from <code>this</code> except list of exported classes
    1.48 +     */
    1.49 +    public Bck2Brwsr addExported(String... exported) {
    1.50 +        return new Bck2Brwsr(
    1.51 +            level, this.exported.addAndNew(exported), 
    1.52 +            classes, resources, res, extension
    1.53 +        );
    1.54 +    }
    1.55  
    1.56      /** Adds additional classes 
    1.57       * to the list of those that should be included in the generated
    1.58 @@ -113,7 +133,7 @@
    1.59       * generated virtual machine code accessible using their fully 
    1.60       * qualified name. This brings the same behavior as if the
    1.61       * classes were added by {@link #addClasses(java.lang.String...) } and
    1.62 -     * were annotated with {@link Exported} annotation.
    1.63 +     * exported via {@link #addExported(java.lang.String...)}.
    1.64       * 
    1.65       * @param classes the classes to add to the compilation
    1.66       * @return new instance of the Bck2Brwsr compiler which inherits
    1.67 @@ -122,10 +142,8 @@
    1.68      public Bck2Brwsr addRootClasses(String... classes) {
    1.69          if (classes.length == 0) {
    1.70              return this;
    1.71 -        } else {
    1.72 -            return new Bck2Brwsr(level, rootcls.addAndNew(classes), this.classes, resources, res,
    1.73 -                                 extension);
    1.74 -        }
    1.75 +        } 
    1.76 +        return addExported(classes).addClasses(classes);
    1.77      }
    1.78      
    1.79      /** Adds additional classes 
    1.80 @@ -143,7 +161,8 @@
    1.81          if (classes.length == 0) {
    1.82              return this;
    1.83          } else {
    1.84 -            return new Bck2Brwsr(level, rootcls, this.classes.addAndNew(classes), resources, res,
    1.85 +            return new Bck2Brwsr(level, exported, 
    1.86 +                this.classes.addAndNew(classes), resources, res,
    1.87                  extension);
    1.88          }
    1.89      }
    1.90 @@ -163,7 +182,7 @@
    1.91          if (resources.length == 0) {
    1.92              return this;
    1.93          } else {
    1.94 -            return new Bck2Brwsr(level, rootcls, this.classes, 
    1.95 +            return new Bck2Brwsr(level, exported, this.classes, 
    1.96                  this.resources.addAndNew(resources), res, extension
    1.97              );
    1.98          }
    1.99 @@ -178,7 +197,7 @@
   1.100       * @since 0.5
   1.101       */
   1.102      public Bck2Brwsr obfuscation(ObfuscationLevel level) {
   1.103 -        return new Bck2Brwsr(level, rootcls, classes, resources, res, extension);
   1.104 +        return new Bck2Brwsr(level, exported, classes, resources, res, extension);
   1.105      }
   1.106      
   1.107      /** A way to change the provider of additional resources (classes) for the 
   1.108 @@ -190,7 +209,7 @@
   1.109       * @since 0.5
   1.110       */
   1.111      public Bck2Brwsr resources(Resources res) {
   1.112 -        return new Bck2Brwsr(level, rootcls, classes, resources, res, extension);
   1.113 +        return new Bck2Brwsr(level, exported, classes, resources, res, extension);
   1.114      }
   1.115  
   1.116      /** Should one generate a library? By default the system generates
   1.117 @@ -205,7 +224,7 @@
   1.118       * @since 0.9
   1.119       */
   1.120      public Bck2Brwsr library(boolean library) {
   1.121 -        return new Bck2Brwsr(level, rootcls, classes, resources, res, library);
   1.122 +        return new Bck2Brwsr(level, exported, classes, resources, res, library);
   1.123      }
   1.124  
   1.125      /** A way to change the provider of additional resources (classes) for the 
   1.126 @@ -264,16 +283,16 @@
   1.127          return res != null ? res : new LdrRsrcs(Bck2Brwsr.class.getClassLoader(), false);
   1.128      }
   1.129      
   1.130 -    String[] allClasses() {
   1.131 -        return classes.addAndNew(rootcls.toArray()).toArray();
   1.132 -    }
   1.133      StringArray allResources() {
   1.134          return resources;
   1.135      }
   1.136  
   1.137 -    
   1.138 -    StringArray rootClasses() {
   1.139 -        return rootcls;
   1.140 +    StringArray classes() {
   1.141 +        return classes;
   1.142 +    }
   1.143 +
   1.144 +    StringArray exported() {
   1.145 +        return exported;
   1.146      }
   1.147      
   1.148      boolean isExtension() {