maven-plugins/site/plugin.jelly
2006-02-02 19:20:59 +00:00

344 lines
14 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Copyright 2001-2004 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.
*/
-->
<project
xmlns:j="jelly:core"
xmlns:maven="jelly:maven">
<!-- ================================================================== -->
<!-- S I T E G E N E R A T I O N -->
<!-- ================================================================== -->
<goal name="site:generate" prereqs="site"/>
<goal name="site:site" prereqs="site" description="Generate the web site" />
<goal name="site:init" prereqs="xdoc:init">
<j:set var="docsDest" value="${maven.docs.dest}"/>
</goal>
<goal name="site">
<attainGoal name="site:run-reports"/>
<attainGoal name="xdoc"/>
</goal>
<goal name="site:run-reports" prereqs="xdoc:register-reports">
<maven:get var="reports" plugin="maven-xdoc-plugin" property="reports" />
<j:forEach var="report" items="${reports}">
<j:set var="reportName" value="${report.get('pluginName')}"/>
<j:if test="${!empty(reportName)}">
<echo>Generating the ${report.get('name')}...</echo>
<attainGoal name="${reportName}:report"/>
</j:if>
</j:forEach>
</goal>
<!-- ================================================================== -->
<!-- S I T E D E P L O Y -->
<!-- ================================================================== -->
<goal
name="site:deploy"
description="deploy the generated site docs">
<!--
|
| Generate the site documentation if it has not already been generated.
| We need some markers or timestamps for this so we don't repeat work
| if it's not necessary.
|
-->
<attainGoal name="site"/>
<!--
|
| Deploy the site using the maven.site.deploy.method property (right
| now possible variants are 'fs' and 'ssh')
|
-->
<attainGoal name="site:${maven.site.deploy.method}deploy"/>
</goal>
<goal name="site:local-deploy-init">
<j:set var="deployToLive" value="${maven.site.deploy.live}"/>
<j:set var="siteDirectory" value="${maven.site.stage.directory}" />
<j:if test="${empty(siteDirectory) or deployToLive}">
<j:set var="siteDirectory" value="${pom.siteDirectory}" />
</j:if>
<j:set var="siteClean" value="${maven.site.deploy.clean}" />
<echo>
site clean = ${siteClean}
siteDirectory = ${siteDirectory}
</echo>
</goal>
<goal name="site:remote-deploy-init" prereqs="site:local-deploy-init">
<j:set var="siteUsername" value="${maven.site.stage.username}" />
<j:if test="${empty(siteUsername) or deployToLive}">
<j:set var="siteUsername" value="${maven.username}" />
</j:if>
<maven:user-check user="${siteUsername}"/>
<j:set var="siteAddress" value="${maven.site.stage.address}" />
<j:if test="${empty(siteAddress) or deployToLive}">
<j:set var="siteAddress" value="${pom.siteAddress}" />
</j:if>
<echo>
siteAddress = ${siteAddress}
siteUsername = ${siteUsername}
</echo>
</goal>
<!-- ================================================================== -->
<!-- S I T E F T P D E P L O Y -->
<!-- Deploys the site using FTP -->
<!-- ================================================================== -->
<goal name="site:ftpdeploy"
prereqs="site:init,site:remote-deploy-init"
description="Deploy the generated site docs using ftp">
<!-- FTP to the server -->
<taskdef
name="ftp"
classname="org.apache.tools.ant.taskdefs.optional.net.FTP"
>
<classpath>
<pathelement path="${plugin.getDependencyPath('ant')}"/>
<pathelement path="${plugin.getDependencyPath('ant-commons-net')}"/>
<pathelement path="${plugin.getDependencyPath('commons-net')}"/>
<pathelement path="${plugin.getDependencyPath('oro')}"/>
</classpath>
</taskdef>
<ftp action="mkdir"
server="${siteAddress}"
depends="true"
userid="${siteUsername}"
password="${maven.password}"
remotedir="${siteDirectory}"/>
<ftp server="${siteAddress}"
depends="true"
userid="${siteUsername}"
password="${maven.password}"
remotedir="${siteDirectory}"
chmod="${maven.site.chmod.mode}">
<fileset dir="${docsDest}" includes="**/*.*"/>
</ftp>
</goal>
<!-- ================================================================== -->
<!-- S I T E S S H D E P L O Y -->
<!-- Deploys the site using SSH -->
<!-- ================================================================== -->
<goal name="site:sshdeploy"
prereqs="site:init,site:remote-deploy-init"
description="Deploy the generated site docs using ssh">
<!-- This needs to taken from the project properties -->
<property name="maven.homepage" value="${siteDirectory}"/>
<echo>Creating site archive</echo>
<tar tarfile="${maven.build.dir}/${maven.final.name}-site.tar" basedir="${docsDest}"/>
<gzip zipfile="${maven.build.dir}/${maven.final.name}-site.tar.gz" src="${maven.build.dir}/${maven.final.name}-site.tar"/>
<delete file="${maven.build.dir}/${maven.final.name}-site.tar"/>
<j:if test="${siteClean}">
<echo>Cleaning destination first</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'rm -r ${siteDirectory}'" />
</exec>
</j:if>
<echo>Creating remote site directory</echo>
<!-- Make sure the destination directory exists before trying to copy -->
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'mkdir -p ${maven.homepage}'"/>
</exec>
<echo>Copying site archive to the remote host</echo>
<exec dir="${maven.build.dir}" executable="${maven.scp.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.scp.args} ${maven.final.name}-site.tar.gz ${siteUsername}@${siteAddress}:${maven.homepage}"/>
</exec>
<echo>Unzipping site archive on the remote host</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'cd ${maven.homepage} &amp;&amp; ${maven.site.gunzip.executable} ${maven.site.gunzip.options} ${maven.final.name}-site.tar.gz'"/>
</exec>
<echo>Untarring site archive on the remote host</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'cd ${maven.homepage} &amp;&amp; ${maven.site.tar.executable} ${maven.site.tar.options} ${maven.final.name}-site.tar'"/>
</exec>
<echo>Updating files modes on the remote host</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'cd ${maven.homepage} &amp;&amp; chmod ${maven.site.chmod.options} ${maven.site.chmod.mode} * ./*'"/>
</exec>
<echo>Deleting remote archive</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'cd ${maven.homepage} &amp;&amp; rm ${maven.final.name}-site.tar'"/>
</exec>
<echo>Deleting local archive</echo>
<delete file="${maven.build.dir}/${maven.final.name}-site.tar.gz"/>
</goal>
<!-- ================================================================== -->
<!-- S I T E F S D E P L O Y -->
<!-- Deploys the site by copying to another file system -->
<!-- ================================================================== -->
<goal name="site:fsdeploy"
prereqs="site:init,site:local-deploy-init"
description="Deploy the generated site by copying to the site directory">
<j:if test="${siteClean}">
<echo>Cleaning destination first</echo>
<delete dir="${siteDirectory}" />
</j:if>
<mkdir dir="${siteDirectory}" />
<copy todir="${siteDirectory}">
<fileset dir="${docsDest}" />
</copy>
</goal>
<goal name="site:war" description="Create a WAR File from the generated site"
prereqs="site:init, site">
<mkdir dir="${docsDest}/WEB-INF" />
<war destfile="${maven.build.dir}/${maven.final.name}-site.war"
webxml="${plugin.resources}/web.xml">
<fileset dir="${docsDest}" />
</war>
</goal>
<goal name="site:ear" prereqs="site:war"
description="Create an EAR File from the generated site">
<j:set var="docType1" value="&lt;" />
<j:set var="docType2">!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com/j2ee/dtds/application_1_2.dtd'</j:set>
<j:set var="docType3" value="&gt;" />
<mkdir dir="${maven.build.dir}/${plugin.artifactId}" />
<j:set var="warName" value="${maven.final.name}-site.war" />
<copy file="${plugin.resources}/application.xml"
tofile="${maven.build.dir}/${plugin.artifactId}/application.xml"/>
<replace file="${maven.build.dir}/${plugin.artifactId}/application.xml">
<replacefilter token="@name@" value="${pom.artifactId}"/>
<replacefilter token="@shortDescription@"
value="${pom.shortDescription}"/>
<replacefilter token="@warName@" value="${warName}" />
<replacefilter token="@contextRoot@" value="${maven.final.name}" />
</replace>
<ear destfile="${maven.build.dir}/${maven.final.name}-site.ear"
appxml="${maven.build.dir}/${plugin.artifactId}/application.xml">
<fileset dir="${maven.build.dir}" includes="${maven.final.name}-site.war" />
</ear>
</goal>
<goal name="site:publish" description="Synchronize the staged site to the live site" prereqs="site:remote-deploy-init">
<j:set var="destSiteAddress" value="${pom.siteAddress}" />
<j:set var="destSiteDirectory" value="${pom.siteDirectory}" />
<j:set var="destSiteUsername" value="${maven.username}" />
<j:set var="publishClean" value="${maven.site.publish.clean}" />
<echo>
source site address: ${siteAddress}
source site directory: ${siteDirectory}
source site username: ${siteUsername}
destination site address: ${destSiteAddress}
destination site directory: ${destSiteDirectory}
destination site username: ${destSiteUsername}
publish clean: ${publishClean}
</echo>
<j:if test="${siteAddress == destSiteAddress and
siteDirectory == destSiteDirectory and
siteUsername == destSiteUsername}">
<fail>Source and destination is identical</fail>
</j:if>
<j:set var="deployMethod" value="${maven.site.deploy.method}" />
<j:choose>
<j:when test="${deployMethod == 'fs'}">
<echo>Executing filesystem copy on local server to publish</echo>
<j:if test="${publishClean}">
<echo>Cleaning destination first</echo>
<delete dir="${destSiteDirectory}" />
</j:if>
<mkdir dir="${destSiteDirectory}" />
<copy todir="${destSiteDirectory}">
<fileset dir="${siteDirectory}" />
</copy>
</j:when>
<j:when test="${siteAddress == destSiteAddress}">
<echo>Executing filesystem copy on remote server to publish</echo>
<j:if test="${publishClean}">
<echo>Cleaning destination first</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'rm -r ${destSiteDirectory}'" />
</exec>
</j:if>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} 'mkdir -p ${destSiteDirectory} &amp;&amp; cp -r ${siteDirectory}/* ${destSiteDirectory}'" />
</exec>
</j:when>
<j:otherwise>
<echo>Executing rsync on stage server to publish to live server</echo>
<j:set var="rsyncArgs" value="${maven.rsync.args}" />
<j:if test="${publishClean}">
<echo>Cleaning destination</echo>
<j:set var="rsyncArgs" value="${rsyncArgs} --delete" />
</j:if>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${maven.ssh.args} -l ${siteUsername} ${siteAddress} '${maven.rsync.executable} ${rsyncArgs} -az ${siteDirectory}/* ${destSiteUsername}@${destSiteAddress}:${destSiteDirectory}'" />
</exec>
</j:otherwise>
</j:choose>
</goal>
<goal name="site:rsyncdeploy"
description="Deploy the generated site using rsync"
prereqs="site:init,site:remote-deploy-init">
<echo>rsyncing...</echo>
<exec dir="." executable="${maven.ssh.executable}" failonerror="${maven.site.failonerror}">
<arg line="${siteUsername}@${siteAddress} 'mkdir -p ${siteDirectory}'" />
</exec>
<maven:makeRelativePath var="relativeDocsDest" path="${docsDest}" separator="/" basedir="${basedir}" />
<j:if test="${siteClean}">
<echo>Cleaning destination</echo>
<j:set var="rsyncArgs" value="${rsyncArgs} --delete" />
</j:if>
<!-- Note: trailing slash is important! -->
<exec dir="." executable="${maven.rsync.executable}" failonerror="${maven.site.failonerror}">
<arg line="-az ${rsyncArgs} ${relativeDocsDest}/ ${siteUsername}@${siteAddress}:${siteDirectory}" />
</exec>
</goal>
</project>