bck2brwsr archetype
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 09 Jan 2013 20:55:26 +0100
changeset 4210236ad6ab4d2
parent 420 3497ecd097df
child 422 8e0818ad6c4d
bck2brwsr archetype
mojo/pom.xml
mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java
mojo/src/main/resources/META-INF/maven/archetype-metadata.xml
mojo/src/main/resources/archetype-resources/nbactions.xml
mojo/src/main/resources/archetype-resources/pom.xml
mojo/src/main/resources/archetype-resources/src/main/java/App.java
mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml
pom.xml
     1.1 --- a/mojo/pom.xml	Tue Jan 08 16:32:11 2013 +0100
     1.2 +++ b/mojo/pom.xml	Wed Jan 09 20:55:26 2013 +0100
     1.3 @@ -11,7 +11,7 @@
     1.4    <artifactId>mojo</artifactId>
     1.5    <version>0.3-SNAPSHOT</version>
     1.6    <packaging>maven-plugin</packaging>
     1.7 -  <name>Maven Mojo to Compile to JavaScript</name>
     1.8 +  <name>Bck2Brwsr Maven Project</name>
     1.9    <url>http://maven.apache.org</url>
    1.10        <build>
    1.11          <plugins>
     2.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Tue Jan 08 16:32:11 2013 +0100
     2.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Wed Jan 09 20:55:26 2013 +0100
     2.3 @@ -44,6 +44,9 @@
     2.4      /** Resource to show as initial page */
     2.5      @Parameter
     2.6      private String startpage;
     2.7 +
     2.8 +    @Parameter
     2.9 +    private String startpackage;
    2.10      
    2.11      @Parameter(defaultValue="${project}")
    2.12      private MavenProject prj;
    2.13 @@ -63,9 +66,9 @@
    2.14              
    2.15              Closeable httpServer;
    2.16              try {
    2.17 -                httpServer = Launcher.showURL(url, startpage);
    2.18 +                httpServer = Launcher.showURL(url, startpage());
    2.19              } catch (Exception ex) {
    2.20 -                throw new MojoExecutionException("Can't open " + startpage, ex);
    2.21 +                throw new MojoExecutionException("Can't open " + startpage(), ex);
    2.22              }
    2.23              System.in.read();
    2.24              httpServer.close();
    2.25 @@ -73,34 +76,12 @@
    2.26              throw new MojoExecutionException("Can't show the browser", ex);
    2.27          }
    2.28      }
    2.29 -
    2.30 -    private static File findNonEmptyFolder(File dir) throws MojoExecutionException {
    2.31 -        if (!dir.isDirectory()) {
    2.32 -            throw new MojoExecutionException("Not a directory " + dir);
    2.33 -        }
    2.34 -        File[] arr = dir.listFiles();
    2.35 -        if (arr.length == 1 && arr[0].isDirectory()) {
    2.36 -            return findNonEmptyFolder(arr[0]);
    2.37 -        }
    2.38 -        return dir;
    2.39 -    }
    2.40 -
    2.41 -    private static long collectAllClasses(String prefix, File toCheck, List<String> arr) {
    2.42 -        File[] files = toCheck.listFiles();
    2.43 -        if (files != null) {
    2.44 -            long newest = 0L;
    2.45 -            for (File f : files) {
    2.46 -                long lastModified = collectAllClasses(prefix + f.getName() + "/", f, arr);
    2.47 -                if (newest < lastModified) {
    2.48 -                    newest = lastModified;
    2.49 -                }
    2.50 -            }
    2.51 -            return newest;
    2.52 -        } else if (toCheck.getName().endsWith(".class")) {
    2.53 -            arr.add(prefix.substring(0, prefix.length() - 7));
    2.54 -            return toCheck.lastModified();
    2.55 +    
    2.56 +    private String startpage() {
    2.57 +        if (startpackage == null) {
    2.58 +            return startpage;
    2.59          } else {
    2.60 -            return 0L;
    2.61 +            return startpackage.replace('.', '/') + '/' + startpage;
    2.62          }
    2.63      }
    2.64  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml	Wed Jan 09 20:55:26 2013 +0100
     3.3 @@ -0,0 +1,42 @@
     3.4 +<?xml version="1.0" encoding="UTF-8"?>
     3.5 +<!--
     3.6 +
     3.7 +    Back 2 Browser Bytecode Translator
     3.8 +    Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.9 +
    3.10 +    This program is free software: you can redistribute it and/or modify
    3.11 +    it under the terms of the GNU General Public License as published by
    3.12 +    the Free Software Foundation, version 2 of the License.
    3.13 +
    3.14 +    This program is distributed in the hope that it will be useful,
    3.15 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.16 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.17 +    GNU General Public License for more details.
    3.18 +
    3.19 +    You should have received a copy of the GNU General Public License
    3.20 +    along with this program. Look for COPYING file in the top folder.
    3.21 +    If not, see http://opensource.org/licenses/GPL-2.0.
    3.22 +
    3.23 +-->
    3.24 +<archetype-descriptor name="bck2brwsr">
    3.25 +  <fileSets>
    3.26 +    <fileSet filtered="true" packaged="true">
    3.27 +      <directory>src/main/java</directory>
    3.28 +      <includes>
    3.29 +        <include>**/*.java</include>
    3.30 +      </includes>
    3.31 +    </fileSet>
    3.32 +    <fileSet filtered="true" packaged="true">
    3.33 +      <directory>src/main/resources</directory>
    3.34 +      <includes>
    3.35 +        <include>**/*.xhtml</include>
    3.36 +      </includes>
    3.37 +    </fileSet>
    3.38 +    <fileSet filtered="false" packaged="false">
    3.39 +      <directory></directory>
    3.40 +      <includes>
    3.41 +        <include>nbactions.xml</include>
    3.42 +      </includes>
    3.43 +    </fileSet>
    3.44 +  </fileSets>    
    3.45 +</archetype-descriptor>
    3.46 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/mojo/src/main/resources/archetype-resources/nbactions.xml	Wed Jan 09 20:55:26 2013 +0100
     4.3 @@ -0,0 +1,10 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<actions>
     4.6 +    <action>
     4.7 +        <actionName>run</actionName>
     4.8 +        <goals>
     4.9 +            <goal>process-classes</goal>
    4.10 +            <goal>org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr</goal>
    4.11 +        </goals>
    4.12 +    </action>
    4.13 +</actions>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml	Wed Jan 09 20:55:26 2013 +0100
     5.3 @@ -0,0 +1,58 @@
     5.4 +<?xml version="1.0"?>
     5.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     5.6 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5.7 +  <modelVersion>4.0.0</modelVersion>
     5.8 +
     5.9 +  <groupId>${groupId}</groupId>
    5.10 +  <artifactId>${artifactId}</artifactId>
    5.11 +  <version>${version}</version>
    5.12 +  <packaging>jar</packaging>
    5.13 +
    5.14 +  <name>${artifactId}</name>
    5.15 +
    5.16 +  <properties>
    5.17 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    5.18 +  </properties>
    5.19 +  <build>
    5.20 +      <plugins>
    5.21 +            <plugin>
    5.22 +                <groupId>org.apidesign.bck2brwsr</groupId>
    5.23 +                <artifactId>mojo</artifactId>
    5.24 +                <version>0.3-SNAPSHOT</version>
    5.25 +                <executions>
    5.26 +                    <execution>
    5.27 +                        <goals>
    5.28 +                            <goal>brwsr</goal>
    5.29 +                        </goals>
    5.30 +                    </execution>
    5.31 +                </executions>
    5.32 +                <configuration>
    5.33 +                    <startpackage>${package}</startpackage>
    5.34 +                    <startpage>index.xhtml</startpage>
    5.35 +                </configuration>
    5.36 +            </plugin>
    5.37 +         <plugin>
    5.38 +            <groupId>org.apache.maven.plugins</groupId>
    5.39 +            <artifactId>maven-compiler-plugin</artifactId>
    5.40 +            <version>2.3.2</version>
    5.41 +            <configuration>
    5.42 +               <source>1.7</source>
    5.43 +               <target>1.7</target>
    5.44 +            </configuration>
    5.45 +         </plugin>
    5.46 +      </plugins>
    5.47 +  </build>
    5.48 +
    5.49 +  <dependencies>
    5.50 +    <dependency>
    5.51 +      <groupId>org.apidesign.bck2brwsr</groupId>
    5.52 +      <artifactId>emul</artifactId>
    5.53 +      <version>0.3-SNAPSHOT</version>
    5.54 +    </dependency>
    5.55 +    <dependency>
    5.56 +      <groupId>org.apidesign.bck2brwsr</groupId>
    5.57 +      <artifactId>javaquery.api</artifactId>
    5.58 +      <version>0.3-SNAPSHOT</version>
    5.59 +    </dependency>
    5.60 +  </dependencies>
    5.61 +</project>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/java/App.java	Wed Jan 09 20:55:26 2013 +0100
     6.3 @@ -0,0 +1,15 @@
     6.4 +package ${package};
     6.5 +
     6.6 +import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
     6.7 +import org.apidesign.bck2brwsr.htmlpage.api.Page;
     6.8 +
     6.9 +/** Edit the index.xhtml file. Use 'id' to name certain HTML elements.
    6.10 + * Use this class to define behavior of the elements.
    6.11 + */
    6.12 +@Page(xhtml="index.xhtml", className="Index")
    6.13 +public class App {
    6.14 +    @OnClick(id="hello")
    6.15 +    static void hello() {
    6.16 +        Index.HELLO.setDisabled(true);
    6.17 +    }
    6.18 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/mojo/src/main/resources/archetype-resources/src/main/resources/index.xhtml	Wed Jan 09 20:55:26 2013 +0100
     7.3 @@ -0,0 +1,16 @@
     7.4 +<?xml version="1.0" encoding="UTF-8"?>
     7.5 +<!DOCTYPE html>
     7.6 +<html xmlns="http://www.w3.org/1999/xhtml">
     7.7 +    <head>
     7.8 +        <title>Bck2Brwsr's Hello World</title>
     7.9 +    </head>
    7.10 +    <body>
    7.11 +        <button id="hello">Hello World!</button>
    7.12 +
    7.13 +        <script src="/bck2brwsr.js"></script>
    7.14 +        <script src="/vm.js"></script>
    7.15 +        <script type="text/javascript">
    7.16 +            vm.loadClass('${package}.Index');
    7.17 +        </script>
    7.18 +    </body>
    7.19 +</html>
     8.1 --- a/pom.xml	Tue Jan 08 16:32:11 2013 +0100
     8.2 +++ b/pom.xml	Wed Jan 09 20:55:26 2013 +0100
     8.3 @@ -73,6 +73,7 @@
     8.4                         <exclude>javap/**</exclude>
     8.5                         <exclude>*</exclude>
     8.6                         <exclude>.*/**</exclude>
     8.7 +                       <exclude>mojo/src/main/resources/archetype-resources/**</exclude>
     8.8                    </excludes>
     8.9                </configuration>
    8.10            </plugin>