Merge with default branch to get fixed argument type (ClassLoader instead of URLClassLoader) fx
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 20 Mar 2013 11:53:10 +0100
branchfx
changeset 859d39fbe061519
parent 856 8d6534b67252
parent 858 afba662cf624
child 969 df08556c5c7c
Merge with default branch to get fixed argument type (ClassLoader instead of URLClassLoader)
rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java
     1.1 --- a/javaquery/demo-calculator-dynamic/nbactions.xml	Wed Mar 20 08:48:06 2013 +0100
     1.2 +++ b/javaquery/demo-calculator-dynamic/nbactions.xml	Wed Mar 20 11:53:10 2013 +0100
     1.3 @@ -23,7 +23,7 @@
     1.4              <actionName>run</actionName>
     1.5              <goals>
     1.6                  <goal>process-classes</goal>
     1.7 -                <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
     1.8 +                <goal>org.apidesign.bck2brwsr:mojo:0.5-SNAPSHOT:brwsr</goal>
     1.9              </goals>
    1.10          </action>
    1.11      </actions>
     2.1 --- a/javaquery/demo-calculator/nbactions.xml	Wed Mar 20 08:48:06 2013 +0100
     2.2 +++ b/javaquery/demo-calculator/nbactions.xml	Wed Mar 20 11:53:10 2013 +0100
     2.3 @@ -23,7 +23,7 @@
     2.4              <actionName>run</actionName>
     2.5              <goals>
     2.6                  <goal>package</goal>
     2.7 -                <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
     2.8 +                <goal>org.apidesign.bck2brwsr:mojo:0.5-SNAPSHOT:brwsr</goal>
     2.9              </goals>
    2.10              <properties>
    2.11                  <skipTests>true</skipTests>
     3.1 --- a/javaquery/demo-calculator/pom.xml	Wed Mar 20 08:48:06 2013 +0100
     3.2 +++ b/javaquery/demo-calculator/pom.xml	Wed Mar 20 11:53:10 2013 +0100
     3.3 @@ -22,6 +22,7 @@
     3.4                  <executions>
     3.5                      <execution>
     3.6                          <goals>
     3.7 +                            <goal>j2js</goal>
     3.8                              <goal>brwsr</goal>
     3.9                          </goals>
    3.10                      </execution>
    3.11 @@ -29,6 +30,7 @@
    3.12                  <configuration>
    3.13                      <directory>${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/</directory>
    3.14                      <startpage>index.xhtml</startpage>
    3.15 +                    <javascript>${project.build.directory}/bck2brwsr.js</javascript>
    3.16                  </configuration>
    3.17              </plugin>
    3.18           <plugin>
    3.19 @@ -102,13 +104,5 @@
    3.20        <artifactId>javaquery.api</artifactId>
    3.21        <version>0.5-SNAPSHOT</version>
    3.22      </dependency>
    3.23 -    <dependency>
    3.24 -      <groupId>org.apidesign.bck2brwsr</groupId>
    3.25 -      <artifactId>vm4brwsr</artifactId>
    3.26 -      <classifier>js</classifier>
    3.27 -      <type>zip</type>
    3.28 -      <version>0.5-SNAPSHOT</version>
    3.29 -      <scope>provided</scope>
    3.30 -    </dependency>
    3.31    </dependencies>
    3.32  </project>
     4.1 --- a/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml	Wed Mar 20 08:48:06 2013 +0100
     4.2 +++ b/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml	Wed Mar 20 11:53:10 2013 +0100
     4.3 @@ -37,15 +37,6 @@
     4.4              <include>*:rt</include>
     4.5          </includes>
     4.6      </dependencySet>
     4.7 -    <dependencySet>
     4.8 -        <useProjectArtifact>false</useProjectArtifact>
     4.9 -        <scope>provided</scope>
    4.10 -        <includes>
    4.11 -            <include>*:js</include>
    4.12 -        </includes>
    4.13 -        <unpack>true</unpack>
    4.14 -        <outputDirectory>/</outputDirectory>
    4.15 -    </dependencySet>
    4.16    </dependencySets> 
    4.17    <files>
    4.18      <file>
    4.19 @@ -53,6 +44,10 @@
    4.20        <outputDirectory>/</outputDirectory>
    4.21      </file>
    4.22      <file>
    4.23 +      <source>${project.build.directory}/bck2brwsr.js</source>
    4.24 +      <outputDirectory>/</outputDirectory>
    4.25 +    </file>
    4.26 +    <file>
    4.27        <source>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</source>
    4.28        <outputDirectory>/</outputDirectory>
    4.29        <destName>index.xhtml</destName>
     5.1 --- a/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Wed Mar 20 08:48:06 2013 +0100
     5.2 +++ b/rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java	Wed Mar 20 11:53:10 2013 +0100
     5.3 @@ -21,7 +21,6 @@
     5.4  import java.io.File;
     5.5  import java.io.IOException;
     5.6  import java.lang.reflect.Method;
     5.7 -import java.net.URLClassLoader;
     5.8  import org.apidesign.vm4brwsr.Bck2Brwsr;
     5.9  
    5.10  /** An abstraction for executing tests in a Bck2Brwsr virtual machine.
    5.11 @@ -101,7 +100,7 @@
    5.12       * @return interface that allows one to stop the server
    5.13       * @throws IOException if something goes wrong
    5.14       */
    5.15 -    public static Closeable showURL(URLClassLoader classes, String startpage) throws IOException {
    5.16 +    public static Closeable showURL(ClassLoader classes, String startpage) throws IOException {
    5.17          Bck2BrwsrLauncher l = new WebViewLauncher();
    5.18          l.addClassLoader(classes);
    5.19          l.showURL(startpage);
     6.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java	Wed Mar 20 08:48:06 2013 +0100
     6.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java	Wed Mar 20 11:53:10 2013 +0100
     6.3 @@ -44,11 +44,17 @@
     6.4      /** Root of the class files */
     6.5      @Parameter(defaultValue="${project.build.directory}/classes")
     6.6      private File classes;
     6.7 -    /** File to generate. Defaults bootjava.js in the first non-empty 
     6.8 -     package under the classes directory */
     6.9 +    /** JavaScript file to generate */
    6.10      @Parameter
    6.11      private File javascript;
    6.12      
    6.13 +    /** Additional classes that should be pre-compiled into the javascript 
    6.14 +     * file. By default compiles all classes found under <code>classes</code>
    6.15 +     * directory and their transitive closure.
    6.16 +     */
    6.17 +    @Parameter
    6.18 +    private List<String> compileclasses;
    6.19 +    
    6.20      @Parameter(defaultValue="${project}")
    6.21      private MavenProject prj;
    6.22      
    6.23 @@ -60,13 +66,14 @@
    6.24              throw new MojoExecutionException("Can't find " + classes);
    6.25          }
    6.26  
    6.27 -        if (javascript == null) {
    6.28 -            javascript = new File(findNonEmptyFolder(classes), "bootjava.js");
    6.29 -        }
    6.30 -
    6.31          List<String> arr = new ArrayList<String>();
    6.32          long newest = collectAllClasses("", classes, arr);
    6.33          
    6.34 +        if (compileclasses != null) {
    6.35 +            arr.retainAll(compileclasses);
    6.36 +            arr.addAll(compileclasses);
    6.37 +        }
    6.38 +        
    6.39          if (javascript.lastModified() > newest) {
    6.40              return;
    6.41          }
    6.42 @@ -81,17 +88,6 @@
    6.43          }
    6.44      }
    6.45  
    6.46 -    private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
    6.47 -        if (!dir.isDirectory()) {
    6.48 -            throw new MojoExecutionException("Not a directory " + dir);
    6.49 -        }
    6.50 -        File[] arr = dir.listFiles();
    6.51 -        if (arr.length == 1 && arr[0].isDirectory()) {
    6.52 -            return findNonEmptyFolder(arr[0]);
    6.53 -        }
    6.54 -        return dir;
    6.55 -    }
    6.56 -
    6.57      private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
    6.58          File[] files = toCheck.listFiles();
    6.59          if (files != null) {
    6.60 @@ -104,7 +100,8 @@
    6.61              }
    6.62              return newest;
    6.63          } else if (toCheck.getName().endsWith(".class")) {
    6.64 -            arr.add(prefix.substring(0, prefix.length() - 7));
    6.65 +            final String cls = prefix.substring(0, prefix.length() - 7);
    6.66 +            arr.add(cls);
    6.67              return toCheck.lastModified();
    6.68          } else {
    6.69              return 0L;
    6.70 @@ -115,7 +112,9 @@
    6.71          List<URL> arr = new ArrayList<URL>();
    6.72          arr.add(root.toURI().toURL());
    6.73          for (Artifact a : deps) {
    6.74 -            arr.add(a.getFile().toURI().toURL());
    6.75 +            if (a.getFile() != null) {
    6.76 +                arr.add(a.getFile().toURI().toURL());
    6.77 +            }
    6.78          }
    6.79          return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
    6.80      }
     7.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Wed Mar 20 08:48:06 2013 +0100
     7.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Wed Mar 20 11:53:10 2013 +0100
     7.3 @@ -40,6 +40,15 @@
     7.4          compareCode("org/apidesign/vm4brwsr/Classes.class");
     7.5      }
     7.6  
     7.7 +    @Test public void compareGeneratedCodeForToolkitClass() throws Exception {
     7.8 +        String genCode = compareCode("org/apidesign/vm4brwsr/Bck2BrwsrToolkit.class");
     7.9 +        int indx = genCode.indexOf("gt = 65604");
    7.10 +        if (indx >= 0) {
    7.11 +            fail("Goto to an invalid label:\n...." + genCode.substring(indx - 30, indx + 30) + "....");
    7.12 +        }
    7.13 +        fail(genCode);
    7.14 +    }
    7.15 +
    7.16      @BeforeClass
    7.17      public static void compileTheCode() throws Exception {
    7.18          code = TestVM.compileClass("org/apidesign/vm4brwsr/VMinVM");
    7.19 @@ -49,7 +58,7 @@
    7.20          code = null;
    7.21      }
    7.22      
    7.23 -    private void compareCode(final String nm) throws Exception, IOException {
    7.24 +    private String compareCode(final String nm) throws Exception, IOException {
    7.25          byte[] arr = BytesLoader.readClass(nm);
    7.26          String ret1 = VMinVM.toJavaScript(arr);
    7.27          
    7.28 @@ -88,5 +97,7 @@
    7.29              msg.append(code.toString());
    7.30              fail(msg.toString());
    7.31          }
    7.32 +        
    7.33 +        return ret1;
    7.34      }
    7.35  }
     8.1 Binary file rt/vm/src/test/resources/org/apidesign/vm4brwsr/Bck2BrwsrToolkit.class has changed