Hi,
The attached patch allows the generation of a war task in the generated
build.xml if web sources are present.
The properties to be set follow the same convention as the war plugin.
cheers,
Rainer
--
Rainer Hermanns [EMAIL PROTECTED]
Woperstr. 34 tel: +49 (0)170 - 3432 912
D-52134 Herzogenrath fax: +49 (0)2406 - 7398
Index: plugin.jelly
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/plugins-build/ant/plugin.jelly,v
retrieving revision 1.2
diff -u -r1.2 plugin.jelly
--- plugin.jelly 8 Feb 2003 13:14:17 -0000 1.2
+++ plugin.jelly 10 Feb 2003 18:42:15 -0000
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
-<project
- xmlns:j="jelly:core"
+<project
+ xmlns:j="jelly:core"
xmlns:u="jelly:util"
+ xmlns:license="license"
xmlns:x="jelly:xml">
<!-- ================================================================== -->
@@ -23,17 +24,30 @@
name="ant:generate-build"
description="Generate an Ant build file">
+ <available property="webSourcesPresent" type="dir"
+ file="${maven.war.src}"/>
+
<tstamp />
<j:file name="${maven.ant.generatebuild.file}" prettyPrint="true">
<j:whitespace xmlns="dummy">
+
+
<x:comment>
build.xml generated by maven from project.xml version ${pom.currentVersion}
on date ${TODAY}, time ${TSTAMP}
</x:comment>
<project name="${pom.artifactId}" default="jar" basedir=".">
-
- <property name="defaulttargetdir" value="target"/>
- <property name="libdir" value="target/lib" />
+
+ <!-- ==================== Initialize Property Values =================== -->
+
+ <!-- See "build.properties.sample" in the top level directory for all -->
+ <!-- property values you must customize for successful building!!! -->
+ <property file="build.properties"/>
+ <property file="${user.home}/build.properties"/>
+ <property file="project.properties"/>
+
+ <property name="defaulttargetdir" value="target"/>
+ <property name="libdir" value="${maven.ant.lib.dir}" />
<property name="classesdir" value="target/classes"/>
<property name="testclassesdir" value="target/test-classes"/>
<property name="testreportdir" value="target/test-reports"/>
@@ -41,21 +55,34 @@
<property name="distdir" value="dist"/>
<property name="javadocdir" value="dist/docs/api"/>
<property name="final.name" value="${maven.final.name}"/>
-
- <target
+
+ <j:if test="${webSourcesPresent == 'true'}">
+ <property name="war.name" value="${pom.artifactId}.war"/>
+ <property name="war.src" value="${maven.war.src}"/>
+ </j:if>
+
+
+ <!-- ======================= Init Properties ==================== -->
+ <target
name="init"
- description="o Initializes some properties">
+ description="o Initializes some properties">
+
+ <echo>Initializing ${pom.artifactId}</echo>
+
<mkdir dir="$${libdir}"/>
<condition property="noget">
<equals arg1="$${build.sysclasspath}" arg2="only"/>
- </condition>
+ </condition>
</target>
+ <!-- ======================= Compile Sources ==================== -->
<target
name="compile"
depends="get-deps"
description="o Compile the code">
-
+
+ <echo>Compiling ${pom.artifactId}</echo>
+
<mkdir dir="$${classesdir}"/>
<javac
@@ -73,21 +100,21 @@
</fileset>
</classpath>
</javac>
-
+
<!-- Copy any resources that must be present in the deployed
JAR file.
-->
<j:forEach var="resource" items="${pom.build.resources}">
-
+
<copy todir="$${classesdir}">
-
+
<j:set var="dir" value="${resource.directory}"/>
<j:if test="${empty dir}">
<j:set var="dir" value="."/>
</j:if>
-
+
<fileset dir="${dir}">
-
+
<j:forEach var="res" items="${resource.includes}">
<include name="${res}"/>
</j:forEach>
@@ -96,21 +123,21 @@
</j:forEach>
</fileset>
</copy>
-
+
</j:forEach>
<!-- Copy any resources required for unit testing -->
<j:forEach var="resource" items="${pom.build.unitTest.resources}">
-
+
<copy todir="$${testclassesdir}">
-
+
<j:set var="dir" value="${resource.directory}"/>
<j:if test="${empty dir}">
<j:set var="dir" value="."/>
</j:if>
-
+
<fileset dir="${dir}">
-
+
<j:forEach var="pattern" items="${resource.includes}">
<include name="${pattern}"/>
</j:forEach>
@@ -119,16 +146,19 @@
</j:forEach>
</fileset>
</copy>
-
+
</j:forEach>
</target>
-
+
+ <!-- ========================== Create JAR ====================== -->
<target
name="jar"
depends="compile,test"
description="o Create the jar">
+ <echo>Building JAR ${pom.artifactId}</echo>
+
<jar
jarfile="target/$${final.name}.jar"
basedir="$${classesdir}"
@@ -136,25 +166,93 @@
/>
</target>
-
+
+
+ <!-- ========================== Create WAR ====================== -->
+ <j:if test="${webSourcesPresent == 'true'}">
+ <target
+ name="war"
+ depends="jar">
+
+ <echo>Building WAR ${pom.artifactId}</echo>
+
+ <mkdir dir="$${defaulttargetdir}" />
+ <war warfile="$${defaulttargetdir}/$${war.name}"
+ webxml="${maven.war.webxml}">
+
+ <j:if test="${webSourcesPresent == 'true'}">
+ <fileset dir="$${war.src}">
+ <exclude name="WEB-INF/web.xml"/>
+ </fileset>
+ </j:if>
+
+ <j:forEach var="dep" items="${pom.dependencies}">
+ <j:if test="${dep.getProperty('war.bundle.jar')=='true'}">
+ <lib dir="$${libdir}">
+ <include name="${dep.artifact}"/>
+ </lib>
+ </j:if>
+ </j:forEach>
+
+ <j:if test="${sourcesPresent == 'true'}">
+ <classes dir="$${classesdir}">
+ <include name="${maven.war.classes.includes}" />
+ <exclude name="${maven.war.classes.excludes}" />
+ </classes>
+ </j:if>
+
+ <j:set var="licenseFileName"><license:fileName/></j:set>
+ <u:file name="$${licenseFileName}" var="licenseFile"/>
+ <metainf dir="${licenseFile.canonicalFile.parent}">
+ <include name="${licenseFile.canonicalFile.name}"/>
+ </metainf>
+
+ <manifest>
+ <attribute name="Built-By" value="${user.name}" />
+ <section name="${pom.package}">
+ <attribute name="Specification-Title" value="${pom.artifactId}" />
+ <attribute name="Specification-Version"
+ value="${pom.currentVersion}" />
+ <attribute name="Specification-Vendor"
+ value="${pom.organization.name}" />
+ <attribute name="Implementation-Title"
+ value="${pom.package}" />
+ <attribute name="Implementation-Version"
+ value="${pom.currentVersion}" />
+ <attribute name="Implementation-Vendor"
+ value="${pom.organization.name}" />
+ </section>
+ </manifest>
+
+ </war>
+
+ </target>
+
+ </j:if>
+
+ <!-- ============================ Clean ========================== -->
<target
name="clean"
description="o Clean up the generated directories">
+
<delete dir="$${defaulttargetdir}"/>
<delete dir="$${distdir}"/>
</target>
+ <!-- ====================== Create distribution ================== -->
<target
name="dist"
depends="jar, javadoc"
description="o Create a distribution">
<mkdir dir="dist"/>
<copy todir="dist">
- <fileset dir="$${defaulttargetdir}" includes="*.jar"/>
- <fileset dir="$${basedir}" includes="LICENSE*, README*"/>
+ <fileset dir="$${defaulttargetdir}" includes="*.jar"/>
+ <fileset dir="$${basedir}" includes="LICENSE*, README*"/>
</copy>
</target>
-
+
+
+ <!-- ======================= Test All Components ================= -->
<target
name="test"
depends="internal-test"
@@ -162,6 +260,8 @@
description="o Run the test cases">
<fail message="There were test failures."/>
</target>
+
+ <!-- ======================= Run internal tests ================== -->
<target
name="internal-test"
depends="compile-tests">
@@ -177,7 +277,7 @@
<sysproperty key="basedir" value="${pom.build.unitTestSourceDirectory}"/>
<sysproperty key="basedir" value="${basedir}"/> // this gives a full path
including the C:\ on windows
--->
+-->
<sysproperty key="basedir" value="."/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
@@ -196,7 +296,7 @@
<j:forEach var="pat" items="${pom.build.unitTest.excludes}">
<exclude name="${pat}"/>
</j:forEach>
-
+
<!-- add extra excludes if the property is set -->
<j:if test="${context.getVariable('maven.ant.excludeTests') != null}">
<u:tokenize var="patterns" delim=",">${maven.ant.excludeTests}</u:tokenize>
@@ -210,7 +310,9 @@
</j:if>
</target>
- <target
+
+ <!-- ========================= Compile Tests ==================== -->
+ <target
name="compile-tests"
depends="compile">
<j:if test="${unitTestSourcesPresent}">
@@ -240,9 +342,9 @@
<j:set var="maven.has.test.resource.patterns" value="true"/>
</j:when>
</j:choose>
-
+
<j:if test="${maven.has.test.resource.patterns}">
-
+
<copy todir="$${testclassesdir}">
<fileset dir="${pom.build.unitTestSourceDirectory}">
<j:forEach var="res" items="${pom.build.unitTest.resources.includes}">
@@ -257,29 +359,30 @@
</j:if>
</target>
+ <!-- ======================= Create Javadocs ==================== -->
<target
name="javadoc"
depends="jar"
description="o Generate javadoc">
-
-
+
+
<mkdir dir="$${javadocdir}"/>
-
+
<!-- Get the year to display in the Javadocs -->
<tstamp>
<format property="year" pattern="${pom.inceptionYear}-yyyy"/>
</tstamp>
-
+
<property
- name="copyright"
+ name="copyright"
value="Copyright &copy; ${year} ${pom.organization.name}. All Rights Reserved."
/>
-
+
<property
name="title"
value="${pom.name} ${pom.currentVersion} API"
/>
-
+
<javadoc
sourcepath="${pom.build.sourceDirectory}"
packagenames="${pom.package}.*"
@@ -298,39 +401,42 @@
<pathelement location="target/$${final.name}.jar"/>
</classpath>
</javadoc>
-
+
</target>
+
+ <!-- ====================== Get Dependencies ==================== -->
<target
name="get-deps"
depends="init"
unless="noget">
-
+
<j:forEach var="dep" items="${pom.dependencies}">
- <get
+ <get
src="${maven.repo.remote}/${dep.artifactDirectory}/jars/${dep.artifact}"
dest="$${libdir}/${dep.artifact}"
usetimestamp="true"
ignoreerrors="true"
/></j:forEach>
<!-- force junit for tests -->
- <get
+ <get
src="${maven.repo.remote}/junit/jars/junit-3.8.1.jar"
dest="$${libdir}/junit-3.8.1.jar"
usetimestamp="true"
ignoreerrors="true"/>
- <get
- src="${maven.repo.remote}/ant/jars/ant-1.5.jar"
- dest="$${libdir}/ant-1.5.jar"
+ <get
+ src="${maven.repo.remote}/ant/jars/ant-1.5.1.jar"
+ dest="$${libdir}/ant-1.5.1.jar"
usetimestamp="true"
ignoreerrors="true"/>
- <get
- src="${maven.repo.remote}/ant/jars/ant-optional-1.5.jar"
- dest="$${libdir}/ant-optional-1.5.jar"
+ <get
+ src="${maven.repo.remote}/ant/jars/ant-optional-1.5.1.jar"
+ dest="$${libdir}/ant-optional-1.5.1.jar"
usetimestamp="true"
ignoreerrors="true"/>
</target>
+
<!-- ================================================================== -->
<!-- A N T A U T O I N S T A L L E R -->
<!-- ================================================================== -->
@@ -344,31 +450,31 @@
name="install-maven">
<!--
-
+
Ask the user what they would like to use for
-
+
${maven.home}
${maven.repo.local}
-
+
-->
- <get
+ <get
src="$${maven.repo.remote}/maven/maven-install-latest.jar"
dest="$${user.home}/maven-install-latest.jar"
usetimestamp="true"
/>
-
+
<unjar
src="$${user.home}/maven-install-latest.jar"
dest="$${maven.home}"
/>
-
+
</target>
</project>
</j:whitespace>
</j:file>
-
+
</goal>
-
+
</project>
Index: plugin.properties
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/plugins-build/ant/plugin.properties,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 plugin.properties
--- plugin.properties 24 Jan 2003 03:44:35 -0000 1.1.1.1
+++ plugin.properties 10 Feb 2003 18:42:16 -0000
@@ -6,3 +6,16 @@
# -------------------------------------------------------------------
maven.ant.generatebuild.file = build.xml
+maven.ant.lib.dir = target/lib
+
+# Using same property names as in war plugin as single point of configuration
+maven.war.src=${maven.src.dir}/webapps
+# Location of web.xml file
+maven.war.webxml=${maven.war.src}/WEB-INF/web.xml
+# Classes to include and exclude from WEB-INF/classes
+# Note: Classes are relative to build.dir
+maven.war.classes.includes=**
+maven.war.classes.excludes=**/package.html
+# Location where the webapp or the war will be created. Defaults to
+# ${maven.build.dir}
+maven.war.build.dir = ${maven.build.dir}
Index: xdocs/goals.xml
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/plugins-build/ant/xdocs/goals.xml,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 goals.xml
--- xdocs/goals.xml 24 Jan 2003 03:44:36 -0000 1.1.1.1
+++ xdocs/goals.xml 10 Feb 2003 18:42:16 -0000
@@ -24,6 +24,7 @@
<li>Compile the java source code</li>
<li>Create a jar from the compiled java code</li>
<li>Create a distribution</li>
+ <li>Create a war from the compiled java code, webapp and dependencies</li>
<li>Run unit tests</li>
<li>Generate JavaDoc</li>
<li>Download all required jar files</li>
Index: xdocs/properties.xml
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-maven/src/plugins-build/ant/xdocs/properties.xml,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 properties.xml
--- xdocs/properties.xml 24 Jan 2003 03:44:36 -0000 1.1.1.1
+++ xdocs/properties.xml 10 Feb 2003 18:42:16 -0000
@@ -39,6 +39,60 @@
</td>
</tr>
</table>
+ <table>
+ <tr>
+ <th>Property name</th>
+ <th>Optional?</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td colspan="3">If a webapp is configured, the following properties
+ may be applied as for the maven-war-plugin.</td>
+ <tr>
+ <td>maven.war.src</td>
+ <td>Yes</td>
+ <td>
+ Location of where the webapp is located in the source tree. Your
+ <code>WEB-INF</code> directory must be located right under
+ <code>${maven.war.src}</code>. It defaults to
+ <code>${maven.src.dir}/webapp</code>.
+ </td>
+ </tr>
+ <tr>
+ <td>maven.war.webxml</td>
+ <td>Yes</td>
+ <td>
+ Location of the <code>web.xml</code> file. It defaults to
+ <code>${maven.war.src}/WEB-INF/web.xml</code>.
+ </td>
+ </tr>
+ <tr>
+ <td>maven.war.classes.includes</td>
+ <td>Yes</td>
+ <td>
+ Classes to include from WEB-INF/classes
+ Note: Classes are relative to
+ <code>${maven.build.dir}</code>.
+ </td>
+ </tr>
+ <tr>
+ <td>maven.war.classes.excludes</td>
+ <td>Yes</td>
+ <td>
+ Classes to exclude from WEB-INF/classes
+ Note: Classes are relative to
+ <code>${maven.build.dir}</code>.
+ </td>
+ </tr>
+ <tr>
+ <td>maven.war.build.dir</td>
+ <td>Yes</td>
+ <td>
+ Directory where the webapp and war will be generated. It defaults
+ to <code>${maven.build.dir}</code>.
+ </td>
+ </tr>
+ </table>
</section>
</body>
-</document>
\ No newline at end of file
+</document>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]