1.1 --- a/javaquery/demo-calculator/nbactions.xml Fri Mar 15 20:33:01 2013 +0100
1.2 +++ b/javaquery/demo-calculator/nbactions.xml Mon Mar 18 09:04:46 2013 +0100
1.3 @@ -23,7 +23,7 @@
1.4 <actionName>run</actionName>
1.5 <goals>
1.6 <goal>package</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 <properties>
1.11 <skipTests>true</skipTests>
2.1 --- a/javaquery/demo-calculator/pom.xml Fri Mar 15 20:33:01 2013 +0100
2.2 +++ b/javaquery/demo-calculator/pom.xml Mon Mar 18 09:04:46 2013 +0100
2.3 @@ -22,6 +22,7 @@
2.4 <executions>
2.5 <execution>
2.6 <goals>
2.7 + <goal>j2js</goal>
2.8 <goal>brwsr</goal>
2.9 </goals>
2.10 </execution>
2.11 @@ -29,6 +30,7 @@
2.12 <configuration>
2.13 <directory>${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/</directory>
2.14 <startpage>index.xhtml</startpage>
2.15 + <javascript>${project.build.directory}/bck2brwsr.js</javascript>
2.16 </configuration>
2.17 </plugin>
2.18 <plugin>
2.19 @@ -102,13 +104,5 @@
2.20 <artifactId>javaquery.api</artifactId>
2.21 <version>0.5-SNAPSHOT</version>
2.22 </dependency>
2.23 - <dependency>
2.24 - <groupId>org.apidesign.bck2brwsr</groupId>
2.25 - <artifactId>vm4brwsr</artifactId>
2.26 - <classifier>js</classifier>
2.27 - <type>zip</type>
2.28 - <version>0.5-SNAPSHOT</version>
2.29 - <scope>provided</scope>
2.30 - </dependency>
2.31 </dependencies>
2.32 </project>
3.1 --- a/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml Fri Mar 15 20:33:01 2013 +0100
3.2 +++ b/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml Mon Mar 18 09:04:46 2013 +0100
3.3 @@ -37,15 +37,6 @@
3.4 <include>*:rt</include>
3.5 </includes>
3.6 </dependencySet>
3.7 - <dependencySet>
3.8 - <useProjectArtifact>false</useProjectArtifact>
3.9 - <scope>provided</scope>
3.10 - <includes>
3.11 - <include>*:js</include>
3.12 - </includes>
3.13 - <unpack>true</unpack>
3.14 - <outputDirectory>/</outputDirectory>
3.15 - </dependencySet>
3.16 </dependencySets>
3.17 <files>
3.18 <file>
3.19 @@ -53,6 +44,10 @@
3.20 <outputDirectory>/</outputDirectory>
3.21 </file>
3.22 <file>
3.23 + <source>${project.build.directory}/bck2brwsr.js</source>
3.24 + <outputDirectory>/</outputDirectory>
3.25 + </file>
3.26 + <file>
3.27 <source>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</source>
3.28 <outputDirectory>/</outputDirectory>
3.29 <destName>index.xhtml</destName>
4.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java Fri Mar 15 20:33:01 2013 +0100
4.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java Mon Mar 18 09:04:46 2013 +0100
4.3 @@ -44,11 +44,17 @@
4.4 /** Root of the class files */
4.5 @Parameter(defaultValue="${project.build.directory}/classes")
4.6 private File classes;
4.7 - /** File to generate. Defaults bootjava.js in the first non-empty
4.8 - package under the classes directory */
4.9 + /** JavaScript file to generate */
4.10 @Parameter
4.11 private File javascript;
4.12
4.13 + /** Additional classes that should be pre-compiled into the javascript
4.14 + * file. By default compiles all classes found under <code>classes</code>
4.15 + * directory and their transitive closure.
4.16 + */
4.17 + @Parameter
4.18 + private List<String> compileclasses;
4.19 +
4.20 @Parameter(defaultValue="${project}")
4.21 private MavenProject prj;
4.22
4.23 @@ -60,13 +66,14 @@
4.24 throw new MojoExecutionException("Can't find " + classes);
4.25 }
4.26
4.27 - if (javascript == null) {
4.28 - javascript = new File(findNonEmptyFolder(classes), "bootjava.js");
4.29 - }
4.30 -
4.31 List<String> arr = new ArrayList<String>();
4.32 long newest = collectAllClasses("", classes, arr);
4.33
4.34 + if (compileclasses != null) {
4.35 + arr.retainAll(compileclasses);
4.36 + arr.addAll(compileclasses);
4.37 + }
4.38 +
4.39 if (javascript.lastModified() > newest) {
4.40 return;
4.41 }
4.42 @@ -81,17 +88,6 @@
4.43 }
4.44 }
4.45
4.46 - private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
4.47 - if (!dir.isDirectory()) {
4.48 - throw new MojoExecutionException("Not a directory " + dir);
4.49 - }
4.50 - File[] arr = dir.listFiles();
4.51 - if (arr.length == 1 && arr[0].isDirectory()) {
4.52 - return findNonEmptyFolder(arr[0]);
4.53 - }
4.54 - return dir;
4.55 - }
4.56 -
4.57 private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
4.58 File[] files = toCheck.listFiles();
4.59 if (files != null) {
4.60 @@ -104,7 +100,8 @@
4.61 }
4.62 return newest;
4.63 } else if (toCheck.getName().endsWith(".class")) {
4.64 - arr.add(prefix.substring(0, prefix.length() - 7));
4.65 + final String cls = prefix.substring(0, prefix.length() - 7);
4.66 + arr.add(cls);
4.67 return toCheck.lastModified();
4.68 } else {
4.69 return 0L;
4.70 @@ -115,7 +112,9 @@
4.71 List<URL> arr = new ArrayList<URL>();
4.72 arr.add(root.toURI().toURL());
4.73 for (Artifact a : deps) {
4.74 - arr.add(a.getFile().toURI().toURL());
4.75 + if (a.getFile() != null) {
4.76 + arr.add(a.getFile().toURI().toURL());
4.77 + }
4.78 }
4.79 return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
4.80 }