evenisse 2003/08/25 02:43:14
Modified: src/plugins-build/genapp plugin.jelly project.xml
src/plugins-build/genapp/xdocs changes.xml navigation.xml
properties.xml
Added: src/plugins-build/genapp plugin.properties
project.properties
src/plugins-build/genapp/xdocs faq.fml
src/plugins-build/genapp/src/plugin-resources/default/template-resources
project.properties project.xml
src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/conf
app.properties
src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/java
App.java
src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/test
AbstractTestCase.java AppTest.java NaughtyTest.java
src/plugins-build/genapp/src/plugin-resources/default
template.properties
Removed: src/plugins-build/genapp/src/plugin-resources/src/conf
app.properties
src/plugins-build/genapp/src/plugin-resources/src/java
App.java
src/plugins-build/genapp/src/plugin-resources/src/pom
project.properties project.xml
src/plugins-build/genapp/src/plugin-resources/src/test
AbstractTestCase.java AppTest.java NaughtyTest.java
Log:
Add template support in genapp plugin. Thanks to Ryan Hoegg (Maven-426).
We can add now other template like ejb, webapps...
Revision Changes Path
1.3 +127 -41 maven/src/plugins-build/genapp/plugin.jelly
Index: plugin.jelly
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/genapp/plugin.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- plugin.jelly 29 Mar 2003 11:33:21 -0000 1.2
+++ plugin.jelly 25 Aug 2003 09:43:14 -0000 1.3
@@ -1,52 +1,138 @@
<?xml version="1.0"?>
<project
- xmlns:ant="jelly:ant"
xmlns:j="jelly:core"
- xmlns:u="jelly:util">
+ xmlns:i="jelly:interaction"
+ xmlns:ant="jelly:ant"
+ xmlns:define="jelly:define"
+ xmlns:u="jelly:util"
+ xmlns:genapp="genapp">
+ <define:taglib uri="genapp">
+ <!--
+ |
+ | @template
+ |
+ -->
+ <define:tag name="generate">
+ <!-- Get the template -->
+ <!-- create a temporary variable with no dots in the name to get around a
jexl bug -->
+ <j:set var="presettemplate" value="${template}"/>
+ <j:if test="${empty(presettemplate)}">
+ <i:ask question="${maven.genapp.prompt.template}" answer="template"
default="${maven.genapp.default.template}"/>
+ </j:if>
+
+ <!-- If template is in the user's home directory, use it -->
+ <u:available file="${user.home}/.maven/template/${template}">
+ <j:set var="maven.genapp.template.dir"
value="${user.home}/.maven/template/${template}"/>
+ </u:available>
+
+ <j:set var="currenttemplatedir" value="${maven.genapp.template.dir}"/>
+ <j:if test="${empty(currenttemplatedir)}">
+ <!-- The template was not found in user.home, check in the plugin resources
-->
+ <u:available file="${plugin.resources}/${template}">
+ <j:set var="maven.genapp.template.dir"
value="${plugin.resources}/${template}"/>
+ </u:available>
+ </j:if>
+
+ <j:set var="currenttemplatedir" value="${maven.genapp.template.dir}"/>
+ <j:if test="${empty(currenttemplatedir)}">
+ <fail>
+ Unable to locate a template named ${template}
+ </fail>
+ </j:if>
+
+ <!-- Ensure that the template has a template-resources directory and use it
-->
+ <u:available file="${maven.genapp.template.dir}/template-resources">
+ <!-- Set resources dir to the template resources directory -->
+ <j:set var="maven.genapp.resources"
value="${maven.genapp.template.dir}/template-resources"/>
+ </u:available>
+
+ <!-- Check that we have a template-resources directory, if not the template
is broken -->
+ <j:set var="currenttemplateresources" value="${maven.genapp.resources}"/>
+ <j:if test="${empty(currenttemplateresources)}">
+ <fail>
+ Found a template in ${maven.genapp.template.dir}, but it was broken.
+ </fail>
+ </j:if>
+
+ <!-- Load template properties if available -->
+ <u:available file="${maven.genapp.template.dir}/template.properties">
+ <u:properties file="${maven.genapp.template.dir}/template.properties"/>
+ </u:available>
+
+ <!-- Ensure we have a project id, name, and package -->
+
+ <j:set var="presetid" value="${maven.genapp.template.id}"/>
+ <j:if test="${empty(presetid)}">
+ <i:ask question="${maven.genapp.prompt.id}"
answer="maven.genapp.template.id" default="${maven.genapp.default.id}"/>
+ </j:if>
+
+ <j:set var="presetname" value="${maven.genapp.template.name}"/>
+ <j:if test="${empty(presetname)}">
+ <i:ask question="${maven.genapp.prompt.name}"
answer="maven.genapp.template.name" default="${maven.genapp.default.name}"/>
+ </j:if>
+
+ <j:set var="presetpackage" value="${maven.genapp.template.package}"/>
+ <j:if test="${empty(presetpackage)}">
+ <i:ask question="${maven.genapp.prompt.package}"
answer="maven.genapp.template.package" default="${maven.genapp.default.package}"/>
+ </j:if>
+
+ <!-- Turn the specified package into a path -->
+ <u:replace var="appPath" oldChar="." newChar="/"
value="${maven.genapp.template.package}"/>
+
+ <!-- We want to substitute in the id, name, and package name. -->
+ <filter token="ID" value="${maven.genapp.template.id}"/>
+ <filter token="NAME" value="${maven.genapp.template.name}"/>
+ <filter token="PACKAGE" value="${maven.genapp.template.package}"/>
+
+ <!-- split the list of dirs that need repackaged -->
+ <u:tokenize var="maven.genapp.repackage.split"
delim=",">${maven.genapp.repackage}</u:tokenize>
+
+ <!-- copy resources that need repackaged, eg java files -->
+ <j:forEach var="res" items="${maven.genapp.repackage.split}">
+ <ant:copy todir="${basedir}/src/${res}/${appPath}"
+ filtering="true">
+ <ant:fileset dir="${maven.genapp.resources}/src/${res}" />
+ </ant:copy>
+ </j:forEach>
+
+ <!-- copy resources that just need filtered, eg project.xml -->
+ <ant:copy todir="${basedir}" filtering="true">
+ <ant:fileset dir="${maven.genapp.resources}">
+ <j:forEach var="res" items="${maven.genapp.filter}">
+ <include name="${res}"/>
+ </j:forEach>
+ </ant:fileset>
+ </ant:copy>
+
+ <!-- copy rest of app unfiltered -->
+ <ant:copy todir="${basedir}">
+ <ant:fileset dir="${maven.genapp.resources}">
+ <ant:exclude name="src/java"/>
+ <ant:exclude name="src/test"/>
+ <j:forEach var="res" items="${maven.genapp.filter}">
+ <exclude name="${res}"/>
+ </j:forEach>
+ <j:forEach var="res" items="${maven.genapp.repackage.split}">
+ <exclude name="src/${res}/**"/>
+ </j:forEach>
+ </ant:fileset>
+ </ant:copy>
+
+ <!-- Run the specific jelly script for the template -->
+ <u:available file="${maven.genapp.template.dir}/template.jelly">
+ <echo>Use template.jelly file present in
${maven.genapp.template.dir}.</echo>
+ <j:import file="${maven.genapp.template.dir}/template.jelly"
inherit="true"/>
+ </u:available>
+ </define:tag>
+ </define:taglib>
+
<goal
name="genapp"
- description="Generate Application using 'maven -Dpackage=org.mycompany.project
genapp'">
-
- <j:if test="${package == null}">
- <ant:fail message="">
-
- You must specifiy a package for your application!
-
- </ant:fail>
- </j:if>
-
- <!-- Turn the specified package into a path -->
- <u:replace var="appPath" oldChar="." newChar="/" value="${package}"/>
-
- <!-- We want to substitute in the package name. -->
- <ant:filter token="PACKAGE" value="${package}"/>
-
- <!-- Make Java source directory and populate. -->
- <j:set var="appDirectory" value="${basedir}/src/java/${appPath}"/>
- <ant:mkdir dir="${appDirectory}"/>
- <ant:copy todir="${appDirectory}" filtering="true">
- <ant:fileset dir="${plugin.resources}/src/java"/>
- </ant:copy>
-
- <!-- Make Java unit test source directory and populate. -->
- <j:set var="appTestDirectory" value="${basedir}/src/test/${appPath}"/>
- <ant:mkdir dir="${appTestDirectory}"/>
- <ant:copy todir="${appTestDirectory}" filtering="true">
- <ant:fileset dir="${plugin.resources}/src/test"/>
- </ant:copy>
-
- <!-- Starter POM and POM properties. -->
- <ant:copy todir="${basedir}" filtering="true">
- <ant:fileset dir="${plugin.resources}/src/pom"/>
- </ant:copy>
-
- <!-- Starter conf files to be placed in the JAR. -->
- <ant:copy todir="${basedir}/src/conf">
- <ant:fileset dir="${plugin.resources}/src/conf"/>
- </ant:copy>
+ description="Generate Application based on a template">
+ <genapp:generate template="${maven.genapp.template}"/>
</goal>
</project>
1.9 +42 -26 maven/src/plugins-build/genapp/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/genapp/project.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- project.xml 9 Apr 2003 01:06:45 -0000 1.8
+++ project.xml 25 Aug 2003 09:43:14 -0000 1.9
@@ -2,47 +2,63 @@
<project>
<extend>${basedir}/../project.xml</extend>
- <!-- the version of maven's project object model -->
-
<pomVersion>3</pomVersion>
- <!-- a unique name for this project -->
-
<id>maven-genapp-plugin</id>
- <!-- a short but descriptive name for the project -->
-
<name>Maven Genapp Plugin</name>
- <!-- The version of the project under development, e.g.
- 1.1, 1.2, 2.0-dev -->
-
- <currentVersion>1.0</currentVersion>
- <!-- a short description of what the project does -->
-
+ <currentVersion>2.0-SNAPSHOT</currentVersion>
<shortDescription>A collection of example projects showing how to use maven in
different situations</shortDescription>
- <!-- the project home page -->
-
<url>http://maven.apache.org/reference/plugins/genapp/</url>
<siteDirectory>/www/maven.apache.org/reference/plugins/genapp/</siteDirectory>
<repository>
<connection>scm:cvs:pserver:[EMAIL
PROTECTED]:/home/cvspublic:maven/src/plugins-build/genapp/</connection>
<url>http://cvs.apache.org/viewcvs/maven/src/plugins-build/genapp/</url>
</repository>
- <!-- any mailing lists for the project -->
-
- <mailingLists/>
- <!-- who the developers are for the project -->
<developers>
<developer>
- <name>dIon Gillard</name>
- <id>dion</id>
- <email>[EMAIL PROTECTED]</email>
- <organization>Multitask Consulting</organization>
+ <name>Jason van Zyl</name>
+ <id>jvanzyl</id>
+ <email>[EMAIL PROTECTED]</email>
+ <organization>Zenplex</organization>
+ <roles>
+ <role>Architect</role>
+ <role>Release Manager</role>
+ </roles>
+ </developer>
+ <developer>
+ <name>Emmanuel Venisse</name>
+ <id>evenisse</id>
+ <email>[EMAIL PROTECTED]</email>
+ <organization>Fi System</organization>
<roles>
<role>Java Developer</role>
</roles>
</developer>
- </developers>
- <!-- jar files the project is dependent on -->
-
- <dependencies/>
+ <developers>
+ <contributors>
+ <contributor>
+ <name>Ryan Hoegg</name>
+ <email>[EMAIL PROTECTED]</email>
+ </contributor>
+ </contributors>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-jelly</groupId>
+ <artifactId>commons-jelly-tags-interaction</artifactId>
+ <version>20030211.143817</version>
+ <properties>
+ <classloader>root.maven</classloader>
+ </properties>
+ </dependency>
+ </dependencies>
+
+ <reports>
+ <report>maven-changes-plugin</report>
+ <report>maven-changelog-plugin</report>
+ <report>maven-file-activity-plugin</report>
+ <report>maven-developer-activity-plugin</report>
+ <report>maven-license-plugin</report>
+ <report>maven-faq-plugin</report>
+ </reports>
</project>
1.1 maven/src/plugins-build/genapp/plugin.properties
Index: plugin.properties
===================================================================
maven.genapp.resources=${plugin.resources}/default
maven.genapp.prompt.template=Enter a project template to use:
maven.genapp.prompt.id=Please specify an id for your application:
maven.genapp.prompt.name=Please specify a name for your application:
maven.genapp.prompt.package=Please specify the package for your application:
maven.genapp.default.template=default
maven.genapp.default.id=app
maven.genapp.default.name=Example Application
maven.genapp.default.package=example.app
1.1 maven/src/plugins-build/genapp/project.properties
Index: project.properties
===================================================================
# -------------------------------------------------------------------
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
maven.license.licenseFile=${basedir}/../../../LICENSE.txt
1.2 +21 -0 maven/src/plugins-build/genapp/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/genapp/xdocs/changes.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- changes.xml 24 Jan 2003 03:45:11 -0000 1.1
+++ changes.xml 25 Aug 2003 09:43:14 -0000 1.2
@@ -5,6 +5,27 @@
<author email="[EMAIL PROTECTED]">dIon Gillard</author>
</properties>
<body>
+ <release version="2.0" date="in CVS">
+ <action dev="evenisse" type="update">
+ Add a taglib for use the generation in other plugins.
+ </action>
+ <action dev="rhoegg" type="update">
+ Changed property names to maven.genapp.* syntax
+ </action>
+ <action dev="rhoegg" type="update">
+ Prompt the user for project id, name, and package.
+ Don't require command line package specification.
+ This change added a dependency on jelly:interaction.
+ </action>
+ <action dev="rhoegg" type="add">
+ Added initial application template capability.
+ Original idea and implementation was submitted
+ by Brian Ewins in jira(MAVEN-426). Modified his jelly to
+ use template directories inside plugin-resources.
+ Added capability for templates to define their
+ own properties.
+ </action>
+ </release>
<release version="1.0" date="2002-12-08">
<action dev="jvanzyl" type="add">
Initial plugin created
1.3 +1 -0 maven/src/plugins-build/genapp/xdocs/navigation.xml
Index: navigation.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/genapp/xdocs/navigation.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- navigation.xml 19 Mar 2003 05:54:16 -0000 1.2
+++ navigation.xml 25 Aug 2003 09:43:14 -0000 1.3
@@ -10,6 +10,7 @@
<menu name="Overview">
<item name="Goals" href="/goals.html" />
<item name="Properties" href="/properties.html" />
+ <item name="Faqs" href="/faq.html" />
</menu>
</body>
</project>
1.2 +53 -1 maven/src/plugins-build/genapp/xdocs/properties.xml
Index: properties.xml
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/genapp/xdocs/properties.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- properties.xml 24 Jan 2003 03:45:11 -0000 1.1
+++ properties.xml 25 Aug 2003 09:43:14 -0000 1.2
@@ -8,14 +8,66 @@
<body>
<section name="Application Generation Settings">
+ <div>Some of these properties are prompted for when the plugin runs, if not
already specified.</div>
<table>
<tr><th>Property</th><th>Optional?</th><th>Description</th><th>Default</th></tr>
<tr>
- <td>package</td>
+ <td>maven.genapp.template</td>
+ <td>Yes</td>
+ <td>
+ Specifies the template to use when generating the application.
+ If this property is not defined, the user will be prompted.
+ </td>
+ <td>
+ default
+ </td>
+ </tr>
+ <tr>
+ <td>maven.genapp.template.dir</td>
<td>No</td>
<td>
+ Specifies the template directory to use when generating the application.
+ Usually set based on the maven.genapp.template chosen. Users can
override
+ this property and maven.genapp.template (which will then go unused)
+ in order to use a custom template directory. This can be useful for
other
+ plugins.
+ </td>
+ <td>
+ Specified by the template.
+ </td>
+ </tr>
+ <tr>
+ <td>maven.genapp.template.id</td>
+ <td>Yes</td>
+ <td>
+ Specifies the id of the application to be generated
+ If this property is not defined, the user will be prompted.
+ </td>
+ <td>
+ app
+ </td>
+ </tr>
+ <tr>
+ <td>maven.genapp.template.name</td>
+ <td>Yes</td>
+ <td>
+ Specifies the name of the application to be generated
+ If this property is not defined, the user will be prompted.
+ </td>
+ <td>
+ Example Application
+ </td>
+ </tr>
+ <tr>
+ <td>maven.genapp.template.package</td>
+ <td>Yes</td>
+ <td>
Specifies the name of the Java package that code will be
generated for.
+ If this property is not defined, the user will be prompted.
+ </td>
+ <td>
+ example.app
</td>
</tr>
</table>
1.1 maven/src/plugins-build/genapp/xdocs/faq.fml
Index: faq.fml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<faqs title="Frequently Asked Questions">
<part id="general">
<title>General</title>
<faq id="specific-script">
<question>How to add a specific script for my template?</question>
<answer>
For add a specific script to your template, you should create a
template.jelly
file at your template root directory.
</answer>
</faq>
</part>
</faqs>
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/project.properties
Index: project.properties
===================================================================
maven.xdoc.date=left
maven.xdoc.version=${pom.currentVersion}
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<!-- the version of maven's project object model -->
<pomVersion>3</pomVersion>
<!-- a unique name for this project -->
<id>@ID@</id>
<!-- a short but descriptive name for the project -->
<name>@NAME@</name>
<!-- The version of the project under development, e.g.
1.1, 1.2, 2.0-SNAPSHOT -->
<currentVersion>1.0</currentVersion>
<!-- details about the organization that 'owns' the project -->
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
<logo>http://maven.apache.org/images/jakarta-logo-blue.gif</logo>
</organization>
<!-- the year the project started -->
<inceptionYear>2002</inceptionYear>
<package>@PACKAGE@</package>
<logo>http://maven.apache.org/images/maven.jpg</logo>
<description>
A collection of example projects showing how to use maven in different
situations
</description>
<!-- a short description of what the project does -->
<shortDescription>
How to use maven in different situations
</shortDescription>
<!-- the project home page -->
<url>http://maven.apache.org/reference/plugins/examples/</url>
<issueTrackingUrl>http://nagoya.apache.org/scarab/servlet/scarab/</issueTrackingUrl>
<siteAddress>jakarta.apache.org</siteAddress>
<siteDirectory>/www/maven.apache.org/reference/plugins/examples/</siteDirectory>
<distributionDirectory>/www/maven.apache.org/builds/</distributionDirectory>
<!-- the version control repository and http url for online access
the connection element has the form:
scm:<system>:<system specific connection string> -->
<repository>
<connection>scm:cvs:pserver:[EMAIL
PROTECTED]:/home/cvspublic:maven/src/plugins-build/examples</connection>
<url>http://cvs.apache.org/viewcvs/maven/src/plugins-build/examples/</url>
</repository>
<!-- any mailing lists for the project -->
<mailingLists/>
<!-- who the developers are for the project -->
<developers/>
<!-- jar files the project is dependent on -->
<dependencies/>
<!-- build information for the project -->
<build>
<nagEmailAddress>[EMAIL PROTECTED]</nagEmailAddress>
<sourceDirectory>${basedir}/src/java</sourceDirectory>
<unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/NaughtyTest.java</exclude>
</excludes>
</unitTest>
<resources>
<resource>
<directory>${basedir}/src/conf</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</build>
</project>
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/conf/app.properties
Index: app.properties
===================================================================
# Sample app properties.
foo=bar
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/java/App.java
Index: App.java
===================================================================
package @PACKAGE@;
/**
* Hello world!
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/test/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
package @PACKAGE@;
import java.io.File;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Abstract base class for test cases.
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public abstract class AbstractTestCase
extends TestCase
{
/**
* Basedir for all file I/O. Important when running tests from
* the reactor.
*/
public String basedir = System.getProperty("basedir");
/**
* Constructor.
*/
public AbstractTestCase(String testName)
{
super(testName);
}
/**
* Get test input file.
*
* @param path Path to test input file.
*/
public String getTestFile(String path)
{
return new File(basedir,path).getAbsolutePath();
}
}
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/test/AppTest.java
Index: AppTest.java
===================================================================
package @PACKAGE@;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class AppTest
extends AbstractTestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertEquals( "maven kicks ass", "maven kicks ass" );
}
}
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template-resources/src/test/NaughtyTest.java
Index: NaughtyTest.java
===================================================================
package @PACKAGE@;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
*/
public class NaughtyTest
extends AbstractTestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public NaughtyTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( NaughtyTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
// Crash and burn!
}
}
1.1
maven/src/plugins-build/genapp/src/plugin-resources/default/template.properties
Index: template.properties
===================================================================
maven.genapp.repackage=java,test
maven.genapp.filter=project.xml
maven.genapp.default.package=default.example.app
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]