OSDN Git Service

added src
author殿内 誠司 <tonouchi@users.sourceforge.jp>
Wed, 4 Mar 2009 12:41:23 +0000 (21:41 +0900)
committer殿内 誠司 <tonouchi@users.sourceforge.jp>
Wed, 4 Mar 2009 12:41:23 +0000 (21:41 +0900)
19 files changed:
src/main/resources/META-INF/maven/archetype.xml [new file with mode: 0644]
src/main/resources/archetype-resources/jar/pom.xml [new file with mode: 0644]
src/main/resources/archetype-resources/jar/src/main/java/Start.java [new file with mode: 0644]
src/main/resources/archetype-resources/jar/src/main/resources/META-INF/MANIFEST.MF [new file with mode: 0644]
src/main/resources/archetype-resources/jar/src/main/resources/log4j.properties [new file with mode: 0644]
src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/DBUnitUtil.java [new file with mode: 0644]
src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/SQLExecutor.java [new file with mode: 0644]
src/main/resources/archetype-resources/pom.xml [new file with mode: 0644]
src/main/resources/archetype-resources/src/main/assembly/execwar.xml [new file with mode: 0644]
src/main/resources/archetype-resources/war/pom.xml [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.html [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.java [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/WicketApplication.java [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/resources/META-INF/persistence.xml [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/resources/log4j.properties [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/main/webapp/WEB-INF/web.xml [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/test/java/Start.java [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/DBUnitUtil.java [new file with mode: 0644]
src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/SQLExecutor.java [new file with mode: 0644]

diff --git a/src/main/resources/META-INF/maven/archetype.xml b/src/main/resources/META-INF/maven/archetype.xml
new file mode 100644 (file)
index 0000000..42b1724
--- /dev/null
@@ -0,0 +1,27 @@
+
+<archetype>
+    <id>executable-war-maven-archetype</id>
+    <resources>
+        <resource>src/main/assembly/execwar.xml</resource>
+        <resource>src/site/apt/apt.apt</resource>
+        <resource>src/site/fml/fml.fml</resource>
+        <resource>src/site/resources/resource.html</resource>
+        <resource>src/site/xdoc/xdoc.xml</resource>
+        <resource>jar/pom.xml</resource>
+        <resource>jar/src/main/java/Start.java</resource>
+        <resource>jar/src/main/resources/META-INF/MANIFEST.MF</resource>
+        <resource>jar/src/main/resources/log4j.properties</resource>
+        <resource>jar/src/test/java/org/tonouchi/test/util/DBUnitUtil.java</resource>
+        <resource>jar/src/test/java/org/tonouchi/test/util/SQLExecutor.java</resource>
+        <resource>war/pom.xml</resource>
+        <resource>war/src/main/webapp/WEB-INF/web.xml</resource>
+        <resource>war/src/main/resources/META-INF/persistence.xml</resource>
+        <resource>war/src/main/resources/log4j.properties</resource>
+        <resource>war/src/main/java/org/tonouchi/example/HomePage.html</resource>
+        <resource>war/src/main/java/org/tonouchi/example/HomePage.java</resource>
+        <resource>war/src/main/java/org/tonouchi/example/WicketApplication.java</resource>
+        <resource>war/src/test/java/Start.java</resource>
+        <resource>war/src/test/java/org/tonouchi/test/util/DBUnitUtil.java</resource>
+        <resource>war/src/test/java/org/tonouchi/test/util/SQLExecutor.java</resource>
+    </resources>
+</archetype>
diff --git a/src/main/resources/archetype-resources/jar/pom.xml b/src/main/resources/archetype-resources/jar/pom.xml
new file mode 100644 (file)
index 0000000..a8e0552
--- /dev/null
@@ -0,0 +1,121 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>${groupId}</groupId>
+    <artifactId>${artifactId}-jar</artifactId>
+    <version>${version}</version>
+    <packaging>jar</packaging>
+    <name>${artifactId}-jar</name>
+    <parent>
+        <groupId>${groupId}</groupId>
+        <artifactId>${artifactId}</artifactId>
+        <version>${version}</version>
+    </parent>
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <configuration>
+                        <source>1.5</source>
+                        <target>1.5</target>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-assembly-plugin</artifactId>
+                    <version>2.2-beta-3</version>
+                    <configuration>
+                        <descriptor>src/main/assembly/execwar.xml</descriptor>
+                        <archive>
+                            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
+                        </archive>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+    <dependencies>
+
+        <!-- Testing Frameworks -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.dbunit</groupId>
+            <artifactId>dbunit</artifactId>
+            <version>2.4.3</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>2.4</version>
+            <scope>test</scope>
+        </dependency>
+
+        <!-- Jetty dependencies -->
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-util</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-management</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-plus</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-naming</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+        </dependency>
+
+        <!-- Embedded Database Dependency -->
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>${derby.version}</version>
+            <type>jar</type>
+        </dependency>
+
+            <!-- Logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+        </dependency>
+    </dependencies>
+    <properties>
+        <jetty.version>6.1.14</jetty.version>
+        <derby.version>10.4.2.0</derby.version>
+    </properties>
+</project>
diff --git a/src/main/resources/archetype-resources/jar/src/main/java/Start.java b/src/main/resources/archetype-resources/jar/src/main/java/Start.java
new file mode 100644 (file)
index 0000000..f90f0de
--- /dev/null
@@ -0,0 +1,109 @@
+
+import java.io.File;
+import java.net.JarURLConnection;
+import java.net.URL;
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.plus.naming.Resource;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+/**
+ * TODO fix or dead!
+ * @author seiji
+ */
+public class Start {
+
+    public static void main(String[] args) {
+        Logger logger = LoggerFactory.getLogger(Start.class);
+
+        try {
+            
+            logger.info("Program starting");
+            logger.info("\tGroup ID : ${groupId}");
+            logger.info("\tArtifact ID : ${artifactId}");
+            logger.info("\tVersion : ${version}");
+
+            logger.info("Starting Jetty server");
+
+            Server server = new Server();
+            logger.info("created server instance");
+
+            int port = 8080;
+            Connector connector = new SelectChannelConnector();
+            connector.setPort(port);
+            logger.info("set port as " + port);
+
+            server.addConnector(connector);
+            logger.info("added connector");
+
+            // DataSourceを登録する
+            logger.info("binding datasource");
+
+            EmbeddedDataSource ds = new EmbeddedDataSource();
+            logger.info("datasource class : " + ds.getClass().getName());
+
+            String createDatabase = "true";
+            String datasourceName = "embedded";
+            String databaseName = System.getProperty("user.home") + "/data/${groupId}/${artifactId}/${version}/db;create=true";
+            String jndiName = "jdbc/${artifactId}ds";
+
+            ds.setCreateDatabase(createDatabase);
+            logger.info("create database : " + createDatabase);
+
+            ds.setDataSourceName(datasourceName);
+            logger.info("datasource name : " + datasourceName);
+
+            ds.setDatabaseName(databaseName);
+            logger.info("database name : " + databaseName);
+
+            Resource resource = new Resource(jndiName, ds);
+            logger.info("data source is bound on " + jndiName);
+
+            // 自分のはいっているWARファイル名を取得する
+            logger.info("getting war file name of itself");
+
+            URL url = Start.class.getClassLoader().getResource("Start.class");
+            File warFile = new File(((JarURLConnection) url.openConnection()).getJarFile().getName());
+            logger.info("war file name : " + warFile.getAbsolutePath());
+
+
+
+            logger.info("mounting web application");
+            
+            WebAppContext context = new WebAppContext(warFile.getAbsolutePath(), "/${artifactId}");
+            logger.info("web application is mounted at /${artifactId}");
+
+            logger.info("setting up web application context");
+            context.setConfigurationClasses(new String[]{
+                    "org.mortbay.jetty.webapp.WebInfConfiguration",
+                    "org.mortbay.jetty.plus.webapp.EnvConfiguration",
+                    "org.mortbay.jetty.plus.webapp.Configuration",
+                    "org.mortbay.jetty.webapp.JettyWebXmlConfiguration",
+                    "org.mortbay.jetty.webapp.TagLibConfiguration"
+                });
+            logger.info("web application context is set up");
+
+            logger.info("set web application context handler");
+            server.setHandler(context);
+
+
+            logger.info("server starting");
+            server.start();
+
+            logger.info("server joining");
+            server.join();
+
+        } catch (Exception ex) {
+            logger.error("exception occurred", ex);
+            ex.printStackTrace();
+        }
+    }
+}
diff --git a/src/main/resources/archetype-resources/jar/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/archetype-resources/jar/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..b3cc4af
--- /dev/null
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Main-Class: Start
diff --git a/src/main/resources/archetype-resources/jar/src/main/resources/log4j.properties b/src/main/resources/archetype-resources/jar/src/main/resources/log4j.properties
new file mode 100644 (file)
index 0000000..23c0414
--- /dev/null
@@ -0,0 +1,10 @@
+log4j.appender.file=org.apache.log4j.ConsoleAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
+
+log4j.rootLogger=INFO,file
+
+log4j.logger.org.apache.wicket=INFO
+log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO
+log4j.logger.org.apache.wicket.version=INFO
+log4j.logger.org.apache.wicket.RequestCycle=INFO
diff --git a/src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/DBUnitUtil.java b/src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/DBUnitUtil.java
new file mode 100644 (file)
index 0000000..d51f30e
--- /dev/null
@@ -0,0 +1,87 @@
+package org.tonouchi.test.util;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.dbunit.DatabaseUnitException;
+import org.dbunit.database.DatabaseConnection;
+import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.dbunit.operation.DatabaseOperation;
+
+/**
+ * DBを利用したテストを作成する時にこのクラスを継承する。
+ * @author tonocchi
+ */
+public abstract class DBUnitUtil {
+
+    /**
+     * DBのドライバ名
+     */
+    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
+    /**
+     * DBのURL
+     *
+     */
+    private String url = "jdbc:derby:" + System.getProperty("user.home") + "/data/${groupId}/${artifactId}/${version}/db_test;create=true";
+    /**
+     * DBUnitが利用するコネクション
+     */
+    private IDatabaseConnection connection = null;
+
+    /**
+     * DBUnit、JPAのコネクションを作成します。
+     * @throws java.sql.SQLException
+     * @throws java.lang.ClassNotFoundException
+     */
+    private void open() throws SQLException, ClassNotFoundException, DatabaseUnitException {
+        Class.forName(driver);
+        Connection con = DriverManager.getConnection(url);
+        connection = new DatabaseConnection(con);
+    }
+
+    /**
+     * DBUnit、JPAのコネクションを解放します
+     * @throws java.sql.SQLException
+     */
+    private void close() throws SQLException {
+        connection.close();
+        connection = null;
+    }
+
+    /**
+     * DBUnitを利用してXMLに定義されたデータをDBのテーブルに挿入します。
+     * @param datasetFileName
+     * @throws java.sql.SQLException
+     * @throws java.io.FileNotFoundException
+     * @throws java.io.IOException
+     * @throws org.dbunit.dataset.DataSetException
+     * @throws org.dbunit.DatabaseUnitException
+     */
+    public void readyData(String datasetFileName) throws SQLException, FileNotFoundException, IOException, DataSetException, DatabaseUnitException {
+        IDataSet dataSet =
+            new FlatXmlDataSet(new FileInputStream(datasetFileName));
+        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
+    }
+
+    /**
+     * DBUnitを利用してXMLに定義されたテーブルからデータをすべて削除します。
+     * @param datasetFileName
+     * @throws java.sql.SQLException
+     * @throws java.io.FileNotFoundException
+     * @throws java.io.IOException
+     * @throws org.dbunit.dataset.DataSetException
+     * @throws org.dbunit.DatabaseUnitException
+     */
+    public void cleanupData(String datasetFileName) throws SQLException, FileNotFoundException, IOException, DataSetException, DatabaseUnitException {
+        IDataSet dataSet =
+            new FlatXmlDataSet(new FileInputStream(datasetFileName));
+        DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
+    }
+}
diff --git a/src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/SQLExecutor.java b/src/main/resources/archetype-resources/jar/src/test/java/org/tonouchi/test/util/SQLExecutor.java
new file mode 100644 (file)
index 0000000..b610946
--- /dev/null
@@ -0,0 +1,49 @@
+package org.tonouchi.test.util;
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * TODO fix or dead!
+ * @author seiji
+ */
+public class SQLExecutor {
+
+    public static void execute(String fileName) throws SQLException, FileNotFoundException, ClassNotFoundException, IOException {
+        Connection con = null;
+        try {
+            LineNumberReader lnr = new LineNumberReader(new FileReader(fileName));
+
+            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+            con =
+                DriverManager.getConnection(
+                "jdbc:derby:" +
+                System.getProperty("user.home") +
+                "/data/${groupId}/${artifactId}/${version}/db_test;create=true");
+
+            Statement stmt = con.createStatement();
+
+            String sql;
+            while ((sql = lnr.readLine()) != null) {
+                System.out.println("executing : " + sql);
+                stmt.execute(sql);
+            }
+
+        } finally {
+            if (con != null && !con.isClosed()) {
+                con.close();
+            }
+        }
+
+    }
+}
diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml
new file mode 100644 (file)
index 0000000..caa240f
--- /dev/null
@@ -0,0 +1,96 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>${groupId}</groupId>
+    <artifactId>${artifactId}</artifactId>
+    <version>${version}</version>
+    <packaging>pom</packaging>
+    <name>${artifactId}</name>
+    <modules>
+        <module>jar</module>
+        <module>war</module>
+    </modules>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.2-beta-3</version>
+                <configuration>
+                    <finalName>${artifactId}</finalName>
+                    <outputDirectory>.</outputDirectory>
+                    <descriptor>src/main/assembly/execwar.xml</descriptor>
+                    <archive>
+                        <manifestFile>jar/src/main/resources/META-INF/MANIFEST.MF</manifestFile>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-util</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-management</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-plus</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-naming</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+        </dependency>
+
+            <!-- Embedded Database Dependency -->
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>${derby.version}</version>
+            <type>jar</type>
+        </dependency>
+
+            <!-- Logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+        </dependency>
+    </dependencies>
+    
+    <!-- Change versions if necessary -->
+    <properties>
+        <jetty.version>6.1.14</jetty.version>
+        <derby.version>10.4.2.0</derby.version>
+    </properties>
+
+
+</project>
diff --git a/src/main/resources/archetype-resources/src/main/assembly/execwar.xml b/src/main/resources/archetype-resources/src/main/assembly/execwar.xml
new file mode 100644 (file)
index 0000000..078c53b
--- /dev/null
@@ -0,0 +1,24 @@
+<assembly>
+    <!--id>${artifactId}</id-->
+  <formats>
+    <format>war</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <dependencySets>
+    <dependencySet>
+      <unpack>true</unpack>
+      <scope>runtime</scope>
+      <outputDirectory>/</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+  <fileSets>
+    <fileSet>
+      <directory>jar/target/classes</directory>
+      <outputDirectory/>
+    </fileSet>
+    <fileSet>
+        <directory>war/target/${artifactId}-war-${version}</directory>
+        <outputDirectory />
+    </fileSet>
+  </fileSets>
+</assembly>
\ No newline at end of file
diff --git a/src/main/resources/archetype-resources/war/pom.xml b/src/main/resources/archetype-resources/war/pom.xml
new file mode 100644 (file)
index 0000000..e8fec9e
--- /dev/null
@@ -0,0 +1,176 @@
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>${groupId}</groupId>
+    <artifactId>${artifactId}-war</artifactId>
+    <version>${version}</version>
+    <packaging>war</packaging>
+    <name>${artifactId}-war</name>
+    <parent>
+        <groupId>${groupId}</groupId>
+        <artifactId>${artifactId}</artifactId>
+        <version>${version}</version>
+    </parent>
+    <repositories>
+        <repository>
+            <id>java.net2</id>
+            <name>java.net Repository</name>
+            <url>http://download.java.net/maven/2/</url>
+        </repository>
+    </repositories>
+
+    <build>
+        <resources>
+            <resource>
+                <filtering>false</filtering>
+                <directory>src/main/resources</directory>
+            </resource>
+            <resource>
+                <filtering>false</filtering>
+                <directory>src/main/java</directory>
+                <includes>
+                    <include>**</include>
+                </includes>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </resource>
+        </resources>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <configuration>
+                        <source>1.5</source>
+                        <target>1.5</target>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-dependency-plugin</artifactId>
+                    <version>2.1</version>
+                    <configuration>
+                        <outputDirectory>src/main/resources/WEB-INF/lib</outputDirectory>
+                        <overWriteSnapshots>false</overWriteSnapshots>
+                        <overWriteIfNewer>true</overWriteIfNewer>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+    <dependencies>
+        <!-- Testing Frameworks -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.dbunit</groupId>
+            <artifactId>dbunit</artifactId>
+            <version>2.4.3</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>2.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javanettasks</groupId>
+            <artifactId>httpunit</artifactId>
+            <version>1.7</version>
+            <scope>test</scope>
+        </dependency>
+
+        <!-- Wicket -->
+        <dependency>
+            <groupId>org.apache.wicket</groupId>
+            <artifactId>wicket</artifactId>
+            <version>${wicket.version}</version>
+        </dependency>
+
+            <!-- JPA -->
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-entitymanager</artifactId>
+            <version>${hibernate.version}</version>
+        </dependency>
+
+            <!-- Logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.4.2</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.14</version>
+        </dependency>
+
+            <!--  Spring  -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+            <version>${spring.version}</version>
+        </dependency>
+
+        <!-- Jetty & Derby for test -->
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-util</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-management</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-plus</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>jetty-naming</artifactId>
+            <version>${jetty.version}</version>
+            <type>jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>${derby.version}</version>
+            <type>jar</type>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <!-- Change versions if necessary -->
+    <properties>
+        <wicket.version>1.4-rc2</wicket.version>
+        <spring.version>2.5.1</spring.version>
+        <hibernate.version>3.3.1.ga</hibernate.version>
+    </properties>
+</project>
diff --git a/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.html b/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.html
new file mode 100644 (file)
index 0000000..5cae08f
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+    <head>
+        <title>Executable WAR Archetype Homepage</title>
+    </head>
+    <body>
+        <span wicket:id="example">message will be here</span>
+    </body>
+</html>
+
diff --git a/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.java b/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/HomePage.java
new file mode 100644 (file)
index 0000000..76d48d0
--- /dev/null
@@ -0,0 +1,20 @@
+package org.tonouchi.example;\r
+\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.WebPage;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class HomePage extends WebPage {\r
+\r
+    private Logger logger = LoggerFactory.getLogger(getClass());\r
+\r
+    private static final long serialVersionUID = 1L;\r
+\r
+    public HomePage(final PageParameters parameters) {\r
+        logger.info("adding label");\r
+        add(new Label("example", "Hello Executable WAR!"));\r
+\r
+    }\r
+}\r
diff --git a/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/WicketApplication.java b/src/main/resources/archetype-resources/war/src/main/java/org/tonouchi/example/WicketApplication.java
new file mode 100644 (file)
index 0000000..19f3ae5
--- /dev/null
@@ -0,0 +1,34 @@
+package org.tonouchi.example;\r
+\r
+import org.apache.wicket.protocol.http.WebApplication;\r
+import javax.persistence.EntityManager;\r
+import javax.persistence.Persistence;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class WicketApplication extends WebApplication {\r
+\r
+    private EntityManager em;\r
+\r
+\r
+\r
+    private Logger logger = LoggerFactory.getLogger(getClass());\r
+\r
+    @Override\r
+    protected void init() {\r
+        super.init();\r
+\r
+        logger.info("creating entity manager");\r
+        em = Persistence.createEntityManagerFactory("${groupId}.${artifactId}PU").createEntityManager();\r
+    }\r
+\r
+    public WicketApplication() {\r
+        logger.info("constructor");\r
+    }\r
+\r
+    public Class getHomePage() {\r
+        logger.info("returning homepage");\r
+        return HomePage.class;\r
+    }\r
+    \r
+}\r
diff --git a/src/main/resources/archetype-resources/war/src/main/resources/META-INF/persistence.xml b/src/main/resources/archetype-resources/war/src/main/resources/META-INF/persistence.xml
new file mode 100644 (file)
index 0000000..fd1e445
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+    <persistence-unit name="${groupId}.${artifactId}PU" transaction-type="RESOURCE_LOCAL">
+        <non-jta-data-source>java:comp/env/jdbc/${artifactId}ds</non-jta-data-source>
+        <properties>
+            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
+        </properties>
+    </persistence-unit>
+</persistence>
diff --git a/src/main/resources/archetype-resources/war/src/main/resources/log4j.properties b/src/main/resources/archetype-resources/war/src/main/resources/log4j.properties
new file mode 100644 (file)
index 0000000..225a435
--- /dev/null
@@ -0,0 +1,5 @@
+log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n
+
+log4j.rootLogger=INFO,Stdout
\ No newline at end of file
diff --git a/src/main/resources/archetype-resources/war/src/main/webapp/WEB-INF/web.xml b/src/main/resources/archetype-resources/war/src/main/webapp/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..bfccb36
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+    <display-name>${artifactId}-war</display-name>
+    <description/>
+    <filter>
+        <filter-name>wicket</filter-name>
+        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+        <init-param>
+            <param-name>applicationClassName</param-name>
+            <param-value>org.tonouchi.example.WicketApplication</param-value>
+        </init-param>
+        <init-param>
+            <param-name>configuration</param-name>
+            <param-value>deployment</param-value>
+        </init-param>
+    </filter>
+
+    <filter-mapping>
+        <filter-name>wicket</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+    <resource-ref>
+        <res-ref-name>jdbc/${artifactId}ds</res-ref-name>
+        <res-type>javax.sql.DataSource</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+</web-app>
\ No newline at end of file
diff --git a/src/main/resources/archetype-resources/war/src/test/java/Start.java b/src/main/resources/archetype-resources/war/src/test/java/Start.java
new file mode 100644 (file)
index 0000000..715dd04
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  Copyright 2009 seiji.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.plus.naming.Resource;
+import org.mortbay.jetty.webapp.WebAppContext;
+/**
+ * TODO fix or dead!
+ * @author seiji
+ */
+public class Start {
+    public static void main(String[] args) throws Exception{
+        try {
+            Server server = new Server();
+            Connector connector = new SelectChannelConnector();
+            connector.setPort(8080);
+            server.addConnector(connector);
+
+            // DataSourceを登録する
+            EmbeddedDataSource ds = new EmbeddedDataSource();
+            ds.setCreateDatabase("true");
+            ds.setDataSourceName("embedded");
+            ds.setDatabaseName(System.getProperty("user.home") + "/data/${groupId}/${artifactId}/${version}/db_test;create=true");
+            Resource resource = new Resource("jdbc/${artifactId}ds", ds);
+
+            WebAppContext context = new WebAppContext("src/main/webapp", "/${artifactId}");
+
+            context.setConfigurationClasses(new String[]{
+                    "org.mortbay.jetty.webapp.WebInfConfiguration",
+                    "org.mortbay.jetty.plus.webapp.EnvConfiguration",
+                    "org.mortbay.jetty.plus.webapp.Configuration",
+                    "org.mortbay.jetty.webapp.JettyWebXmlConfiguration",
+                    "org.mortbay.jetty.webapp.TagLibConfiguration"
+                });
+
+            server.setHandler(context);
+
+
+            server.start();
+            server.join();
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+}
diff --git a/src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/DBUnitUtil.java b/src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/DBUnitUtil.java
new file mode 100644 (file)
index 0000000..d51f30e
--- /dev/null
@@ -0,0 +1,87 @@
+package org.tonouchi.test.util;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.dbunit.DatabaseUnitException;
+import org.dbunit.database.DatabaseConnection;
+import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.dbunit.operation.DatabaseOperation;
+
+/**
+ * DBを利用したテストを作成する時にこのクラスを継承する。
+ * @author tonocchi
+ */
+public abstract class DBUnitUtil {
+
+    /**
+     * DBのドライバ名
+     */
+    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
+    /**
+     * DBのURL
+     *
+     */
+    private String url = "jdbc:derby:" + System.getProperty("user.home") + "/data/${groupId}/${artifactId}/${version}/db_test;create=true";
+    /**
+     * DBUnitが利用するコネクション
+     */
+    private IDatabaseConnection connection = null;
+
+    /**
+     * DBUnit、JPAのコネクションを作成します。
+     * @throws java.sql.SQLException
+     * @throws java.lang.ClassNotFoundException
+     */
+    private void open() throws SQLException, ClassNotFoundException, DatabaseUnitException {
+        Class.forName(driver);
+        Connection con = DriverManager.getConnection(url);
+        connection = new DatabaseConnection(con);
+    }
+
+    /**
+     * DBUnit、JPAのコネクションを解放します
+     * @throws java.sql.SQLException
+     */
+    private void close() throws SQLException {
+        connection.close();
+        connection = null;
+    }
+
+    /**
+     * DBUnitを利用してXMLに定義されたデータをDBのテーブルに挿入します。
+     * @param datasetFileName
+     * @throws java.sql.SQLException
+     * @throws java.io.FileNotFoundException
+     * @throws java.io.IOException
+     * @throws org.dbunit.dataset.DataSetException
+     * @throws org.dbunit.DatabaseUnitException
+     */
+    public void readyData(String datasetFileName) throws SQLException, FileNotFoundException, IOException, DataSetException, DatabaseUnitException {
+        IDataSet dataSet =
+            new FlatXmlDataSet(new FileInputStream(datasetFileName));
+        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
+    }
+
+    /**
+     * DBUnitを利用してXMLに定義されたテーブルからデータをすべて削除します。
+     * @param datasetFileName
+     * @throws java.sql.SQLException
+     * @throws java.io.FileNotFoundException
+     * @throws java.io.IOException
+     * @throws org.dbunit.dataset.DataSetException
+     * @throws org.dbunit.DatabaseUnitException
+     */
+    public void cleanupData(String datasetFileName) throws SQLException, FileNotFoundException, IOException, DataSetException, DatabaseUnitException {
+        IDataSet dataSet =
+            new FlatXmlDataSet(new FileInputStream(datasetFileName));
+        DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
+    }
+}
diff --git a/src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/SQLExecutor.java b/src/main/resources/archetype-resources/war/src/test/java/org/tonouchi/test/util/SQLExecutor.java
new file mode 100644 (file)
index 0000000..b610946
--- /dev/null
@@ -0,0 +1,49 @@
+package org.tonouchi.test.util;
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * TODO fix or dead!
+ * @author seiji
+ */
+public class SQLExecutor {
+
+    public static void execute(String fileName) throws SQLException, FileNotFoundException, ClassNotFoundException, IOException {
+        Connection con = null;
+        try {
+            LineNumberReader lnr = new LineNumberReader(new FileReader(fileName));
+
+            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+            con =
+                DriverManager.getConnection(
+                "jdbc:derby:" +
+                System.getProperty("user.home") +
+                "/data/${groupId}/${artifactId}/${version}/db_test;create=true");
+
+            Statement stmt = con.createStatement();
+
+            String sql;
+            while ((sql = lnr.readLine()) != null) {
+                System.out.println("executing : " + sql);
+                stmt.execute(sql);
+            }
+
+        } finally {
+            if (con != null && !con.isClosed()) {
+                con.close();
+            }
+        }
+
+    }
+}