Add template support in genapp plugin. Thanks to Ryan Hoegg (Maven-426).
We can add now other template like ejb, webapps... git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113874 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
2f85da784e
commit
846c5cf87e
16 files changed
+284
-81
No files matched your search
+127
-41
@@ -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>
|
||||
@@ -0,0 +1,13 @@
|
||||
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
|
||||
@@ -0,0 +1,5 @@
|
||||
# -------------------------------------------------------------------
|
||||
# P R O J E C T P R O P E R T I E S
|
||||
# -------------------------------------------------------------------
|
||||
maven.license.licenseFile=${basedir}/../../../LICENSE.txt
|
||||
|
||||
+41
-25
@@ -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:anoncvs@cvs.apache.org:/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>dion@multitask.com.au</email>
|
||||
<organization>Multitask Consulting</organization>
|
||||
<name>Jason van Zyl</name>
|
||||
<id>jvanzyl</id>
|
||||
<email>jason@zenplex.com</email>
|
||||
<organization>Zenplex</organization>
|
||||
<roles>
|
||||
<role>Architect</role>
|
||||
<role>Release Manager</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Emmanuel Venisse</name>
|
||||
<id>evenisse</id>
|
||||
<email>evenisse@ifrance.com</email>
|
||||
<organization>Fi System</organization>
|
||||
<roles>
|
||||
<role>Java Developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<!-- jar files the project is dependent on -->
|
||||
<developers>
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Ryan Hoegg</name>
|
||||
<email>rhoegg@isisnetworks.net</email>
|
||||
</contributor>
|
||||
</contributors>
|
||||
|
||||
<dependencies/>
|
||||
<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>
|
||||
File renamed without changes.
+4
-14
@@ -5,13 +5,13 @@
|
||||
<pomVersion>3</pomVersion>
|
||||
|
||||
<!-- a unique name for this project -->
|
||||
<id>app</id>
|
||||
<id>@ID@</id>
|
||||
|
||||
<!-- a short but descriptive name for the project -->
|
||||
<name>Maven example projects</name>
|
||||
<name>@NAME@</name>
|
||||
|
||||
<!-- The version of the project under development, e.g.
|
||||
1.1, 1.2, 2.0-dev -->
|
||||
1.1, 1.2, 2.0-SNAPSHOT -->
|
||||
<currentVersion>1.0</currentVersion>
|
||||
|
||||
<!-- details about the organization that 'owns' the project -->
|
||||
@@ -53,17 +53,7 @@
|
||||
<mailingLists/>
|
||||
|
||||
<!-- who the developers are for the project -->
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Jason van Zyl</name>
|
||||
<id>jvanzyl</id>
|
||||
<email>jason@zenplex.com</email>
|
||||
<organization>Zenplex</organization>
|
||||
<roles>
|
||||
<role>Java Developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<developers/>
|
||||
|
||||
<!-- jar files the project is dependent on -->
|
||||
<dependencies/>
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,4 @@
|
||||
maven.genapp.repackage=java,test
|
||||
maven.genapp.filter=project.xml
|
||||
|
||||
maven.genapp.default.package=default.example.app
|
||||
@@ -5,6 +5,27 @@
|
||||
<author email="dion@apache.org">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
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user