Files
maven-plugins/ant/src/plugin-resources/templates/build.jelly
T

500 lines
17 KiB
XML

<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* 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.
*/
-->
<j:jelly
xmlns:ant="jelly:ant"
xmlns:j="jelly:core"
xmlns:u="jelly:util"
xmlns:x="jelly:xml"
xmlns:maven="jelly:maven"
xmlns:test="test"
xmlns="dummy">
<ant:tstamp />
<j:set var="antComp" value="${maven.ant.compatibility}"/>
<ant:echo>Compatibility : Ant ${antComp}</ant:echo>
<!-- set up relative paths -->
<j:set var="baseDirFile" value="${pom.file.canonicalFile.parentFile}"/>
<maven:makeRelativePath var="srcDirRP" basedir="${baseDirFile}" path="${pom.build.sourceDirectory}" separator="/"/>
<j:if test="${unitTestSourcesPresent == 'true'}">
<maven:makeRelativePath var="testSrcDirRP" basedir="${baseDirFile}" path="${pom.build.unitTestSourceDirectory}" separator="/"/>
<maven:pluginVar plugin="maven-test-plugin" property="maven.test.dest" var="abstestclassesdir" />
<maven:makeRelativePath var="testclassesdirRP" basedir="${baseDirFile}" path="${abstestclassesdir}" separator="/"/>
<maven:pluginVar plugin="maven-test-plugin" property="maven.test.reportsDirectory" var="abstestreportdir" />
<maven:makeRelativePath var="testreportdirRP" basedir="${baseDirFile}" path="${abstestreportdir}" separator="/"/>
</j:if>
<maven:makeRelativePath var="defaulttargetdirRP" basedir="${baseDirFile}" path="${maven.build.dir}" separator="/"/>
<maven:makeRelativePath var="classesdirRP" basedir="${baseDirFile}" path="${maven.build.dest}" separator="/"/>
<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=".">
<j:if test="${maven.ant.use.properties}">
<x:comment>Load local and user build preferences</x:comment>
<property file="build.properties"/>
<property file="$${user.home}/build.properties"/>
</j:if>
<x:comment>Build properties</x:comment>
<property name="defaulttargetdir" value="$${basedir}/${defaulttargetdirRP}"/>
<property name="libdir" value="$${user.home}/.maven/repository" />
<property name="classesdir" value="$${basedir}/${classesdirRP}" />
<j:if test="${unitTestSourcesPresent == 'true'}">
<property name="testclassesdir" value="$${basedir}/${testclassesdirRP}" />
<property name="testreportdir" value="$${basedir}/${testreportdirRP}" />
</j:if>
<property name="distdir" value="$${basedir}/dist"/>
<property name="javadocdir" value="$${basedir}/dist/docs/api"/>
<property name="final.name" value="${maven.final.name}"/>
<property name="proxy.host" value=""/>
<property name="proxy.port" value=""/>
<property name="proxy.username" value=""/>
<property name="proxy.password" value=""/>
<path id="build.classpath">
<j:forEach var="lib" items="${pom.artifacts}">
<j:set var="dep" value="${lib.dependency}"/>
<pathelement location="$${libdir}/${dep.artifactDirectory}/${dep.type}s/${dep.artifact}"/>
</j:forEach>
</path>
<target
name="init"
description="o Initializes some properties">
<mkdir dir="$${libdir}"/>
<condition property="noget">
<equals arg1="$${build.sysclasspath}" arg2="only"/>
</condition>
<x:comment> Test if JUNIT is present in ANT classpath</x:comment>
<available classname="junit.framework.Test" property="Junit.present"/>
<x:comment> Test if user defined a proxy</x:comment>
<condition property="useProxy">
<and>
<isset property="proxy.host"/>
<not>
<equals arg1="$${proxy.host}" arg2="" trim="true"/>
</not>
</and>
</condition>
</target>
<target
name="compile"
depends="get-deps"
description="o Compile the code">
<mkdir dir="$${classesdir}"/>
<j:if test="${sourcesPresent}">
<javac
destdir="$${classesdir}"
excludes="**/package.html"
debug="true"
deprecation="true"
optimize="false">
<src>
<pathelement location="$${basedir}/${srcDirRP}"/>
</src>
<classpath refid="build.classpath" />
</javac>
</j:if>
<!--
| Copy any resources that must be present in the deployed
| JAR file.
-->
<j:forEach var="resource" items="${pom.build.resources}">
<j:choose trim="true">
<j:when test="${(resource.targetPath != null) and (!resource.targetPath.equals(''))}">
<j:set var="outputDir" value="$${classesdir}/${resource.targetPath}"/>
<mkdir dir="$${classesdir}/${resource.targetPath}"/>
</j:when>
<j:otherwise>
<j:set var="outputDir" value="$${classesdir}"/>
</j:otherwise>
</j:choose>
<copy todir="${outputDir}">
<maven:makeRelativePath var="dirRP" basedir="${baseDirFile}" path="${resource.directory}" separator="/"/>
<j:if test="${empty dirRP}">
<j:set var="dirRP" value="."/>
</j:if>
<fileset dir="$${basedir}/${dirRP}">
<j:forEach var="res" items="${resource.includes}">
<include name="${res}"/>
</j:forEach>
<j:forEach var="res" items="${resource.excludes}">
<exclude name="${res}"/>
</j:forEach>
</fileset>
</copy>
</j:forEach>
<!-- Copy license -->
<j:set var="licenseFile" value="${maven.license.licenseFile}"/>
<j:if test="${licenseFile != null and not licenseFile.trim().equals('')}">
<maven:makeRelativePath var="licensePathRP" basedir="${baseDirFile}" path="${licenseFile}" separator="/"/>
<copy todir="$${classesdir}/META-INF" file="$${basedir}/${licensePathRP}"/>
</j:if>
</target>
<target
name="jar"
depends="compile,test"
description="o Create the jar">
<jar
jarfile="$${defaulttargetdir}/$${final.name}.jar"
basedir="$${classesdir}"
excludes="**/package.html"
/>
</target>
<target
name="clean"
description="o Clean up the generated directories">
<delete dir="$${defaulttargetdir}"/>
<delete dir="$${distdir}"/>
</target>
<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*"/>
</copy>
</target>
<target
name="test"
depends="internal-test"
if="test.failure"
description="o Run the test cases">
<fail message="There were test failures."/>
</target>
<target
name="internal-test"
depends="junit-present,compile-tests"
if="Junit.present">
<j:if test="${unitTestSourcesPresent}">
<mkdir dir="$${testreportdir}"/>
<junit printSummary="yes"
haltonerror="true"
failureproperty="test.failure"
fork="true"
dir="$${basedir}">
<sysproperty key="basedir" value="."/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
<classpath>
<path refid="build.classpath" />
<pathelement path="$${testclassesdir}"/>
<pathelement path="$${classesdir}"/>
</classpath>
<batchtest todir="$${testreportdir}">
<fileset dir="$${basedir}/${testSrcDirRP}">
<j:forEach var="pat" items="${pom.build.unitTest.includes}">
<include name="${pat}"/>
</j:forEach>
<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>
<j:forEach var="pattern" items="${patterns}">
<exclude name="${pattern}" />
</j:forEach>
</j:if>
</fileset>
</batchtest>
</junit>
</j:if>
</target>
<target
name="junit-present"
depends="init"
unless="Junit.present">
<echo>================================= WARNING ================================</echo>
<echo>Junit isn't present in your $${ANT_HOME}/lib directory. Tests not executed.</echo>
<echo>==========================================================================</echo>
</target>
<target
name="compile-tests"
depends="junit-present,compile"
if="Junit.present">
<j:if test="${unitTestSourcesPresent}">
<mkdir dir="$${testclassesdir}"/>
<javac
destdir="$${testclassesdir}"
excludes="**/package.html"
debug="true"
deprecation="true"
optimize="false">
<src>
<pathelement location="$${basedir}/${testSrcDirRP}"/>
</src>
<classpath>
<path refid="build.classpath" />
<pathelement path="$${classesdir}"/>
</classpath>
</javac>
<!-- Copy any resources required for unit testing -->
<j:if test="${!pom.build.unitTest.resources.isEmpty()}">
<j:forEach var="resource" items="${pom.build.unitTest.resources}">
<j:choose trim="true">
<j:when test="${!resource.includes.isEmpty()}">
<j:set var="maven.has.test.resource.patterns" value="true"/>
</j:when>
<j:when test="${!resource.excludes.isEmpty()}">
<j:set var="maven.has.test.resource.patterns" value="true"/>
</j:when>
</j:choose>
</j:forEach>
</j:if>
<j:if test="${maven.has.test.resource.patterns}">
<j:forEach var="resource" items="${pom.build.unitTest.resources}">
<j:choose trim="true">
<j:when test="${(resource.targetPath != null) and (!resource.targetPath.equals(''))}">
<j:set var="outputDir" value="$${testclassesdir}/${resource.targetPath}"/>
<mkdir dir="$${testclassesdir}/${resource.targetPath}"/>
</j:when>
<j:otherwise>
<j:set var="outputDir" value="$${testclassesdir}"/>
</j:otherwise>
</j:choose>
<copy todir="${outputDir}">
<fileset dir="$${basedir}/${testSrcDirRP}">
<j:forEach var="res" items="${resource.includes}">
<include name="${res}"/>
</j:forEach>
<j:forEach var="res" items="${resource.excludes}">
<exclude name="${res}"/>
</j:forEach>
</fileset>
</copy>
</j:forEach>
</j:if>
</j:if>
</target>
<target
name="javadoc"
description="o Generate javadoc"
depends="get-deps">
<mkdir dir="$${javadocdir}"/>
<!-- Get the year to display in the Javadocs -->
<tstamp>
<format property="year" pattern="${pom.inceptionYear}-yyyy"/>
</tstamp>
<property
name="copyright"
value="Copyright &amp;copy; ${year} ${pom.organization.name}. All Rights Reserved."
/>
<property
name="title"
value="${pom.name} ${pom.currentVersion} API"
/>
<javadoc
sourcepath="$${basedir}/${srcDirRP}"
packagenames="${pom.package}.*"
destdir="$${javadocdir}"
author="true"
private="true"
version="true"
use="true"
windowtitle="${title}"
doctitle="${title}"
bottom="${copyright}">
<classpath>
<path refid="build.classpath" />
</classpath>
</javadoc>
</target>
<j:forEach var="lib" items="${pom.artifacts}">
<j:set var="dep" value="${lib.dependency}"/>
<maven:makeRelativePath var="depRP" basedir="${maven.repo.local}" path="${lib.path}" separator="/"/>
<u:file var="checkExist" name="${maven.repo.local}/${depRP}" />
<j:if test="${dependencies != null}">
<j:set var="dependencies" value="${dependencies},get-dep-${dep.artifactId}.jar"/>
</j:if>
<j:if test="${dependencies == null}">
<j:set var="dependencies" value="get-dep-${dep.artifactId}.jar"/>
</j:if>
<target
name="get-dep-${dep.artifactId}.jar"
depends="init,setProxy,noProxy,get-custom-dep-${dep.artifactId}.jar"
unless="${dep.artifactId}.jar"
description="o Download the dependency : ${dep.artifactId}.jar">
<mkdir dir="$${libdir}/${dep.artifactDirectory}/${dep.type}s/"/>
<j:choose>
<j:when test="${checkExist.exists()}">
<u:tokenize var="repos" delim=",">${maven.repo.remote}</u:tokenize>
<j:forEach var="repo" items="${repos}">
<!-- note: this is a valid use of artifactDirectory -->
<j:set var="url" value="${repo}/${dep.artifactDirectory}/${dep.type}s/${dep.artifact}"/>
<get
src="${url}"
dest="$${libdir}/${dep.artifactDirectory}/${dep.type}s/${dep.artifact}"
usetimestamp="true"
ignoreerrors="true"
/>
<j:set var="multiRepo" value="${maven.ant.use.multirepo}"/>
<j:if test="${not multiRepo}">
<j:break/>
</j:if>
</j:forEach>
</j:when>
<j:otherwise>
<x:comment>This dependency is overriden in maven project.</x:comment>
<maven:makeRelativePath var="depRP" basedir="${baseDirFile}" path="${lib.path}" separator="/"/>
<copy tofile="$${libdir}/${dep.artifactDirectory}/${dep.type}s/${dep.artifact}" file="$${basedir}/${depRP}"/>
</j:otherwise>
</j:choose>
</target>
<target
name="get-custom-dep-${dep.artifactId}.jar"
depends="init,setProxy,noProxy"
if="${dep.artifactId}.jar">
<mkdir dir="$${libdir}/${dep.artifactDirectory}/${dep.type}s/"/>
<get
src="$${${dep.artifactId}.jar}"
dest="$${libdir}/${dep.artifactDirectory}/${dep.type}s/${dep.artifact}"
usetimestamp="true"
ignoreerrors="true"
/>
</target>
</j:forEach>
<target
name="get-deps"
depends="${dependencies}"
unless="noget"/>
<target
name="setProxy"
depends="init"
if="useProxy">
<x:comment>Proxy settings works only with a JDK 1.2 and higher.</x:comment>
<echo>Proxy used :</echo>
<j:choose>
<j:when test="${antComp == '1.5'}">
<echo>Proxy host [$${proxy.host}]</echo>
<echo>Proxy port [$${proxy.port}]</echo>
<setproxy
proxyhost="$${proxy.host}"
proxyport="$${proxy.port}"/>
</j:when>
<j:when test="${antComp == '1.6'}">
<echo>Proxy host [$${proxy.host}]</echo>
<echo>Proxy port [$${proxy.port}]</echo>
<echo>Proxy user [$${proxy.username}]</echo>
<setproxy
proxyhost="$${proxy.host}"
proxyport="$${proxy.port}"
proxyuser="$${proxy.username}"
proxypassword="$${proxy.password}"/>
</j:when>
<j:otherwise>
<ant:fail>maven.ant.compatibility property must be setted to 1.5 or 1.6.</ant:fail>
</j:otherwise>
</j:choose>
</target>
<target
name="noProxy"
depends="init"
unless="useProxy">
<echo>Proxy not used.</echo>
</target>
<!-- ================================================================== -->
<!-- A N T A U T O I N S T A L L E R -->
<!-- ================================================================== -->
<!-- For users that have Ant installed Maven can be automatically -->
<!-- installed by answering a few simple questions. We only need to -->
<!-- know what the user wants for ${maven.home} and ${maven.repo.local} -->
<!-- and we're set. -->
<!-- ================================================================== -->
<target
name="install-maven">
<!-- get first repo in the list -->
<u:tokenize var="repos" delim=",">${maven.repo.remote}</u:tokenize>
<j:set var="repo">${repos[0]}</j:set>
<!--
Ask the user what they would like to use for
${maven.home}
${maven.repo.local}
-->
<get
src="$${repo}/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:jelly>