2007-04-16 08:31:26 +00:00

239 lines
9.6 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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:x="jelly:xml"
xmlns:define="jelly:define"
xmlns:util="jelly:util"
xmlns:doc="doc"
xmlns:maven="jelly:maven"
xmlns:ant="jelly:ant"
xmlns:jsl="jelly:jsl"
xmlns:announcement="announcement">
<goal name="announcement" prereqs="announcement:generate"
description="Generate release announcement"/>
<goal name="announcement:init">
<maven:property var="versionVariable" name="maven.announcement.version"
defaultValue="${pom.currentVersion}"/>
<maven:property var="announcementFile" name="maven.announcement.file"
defaultValue="${maven.gen.docs}/announcements/announcement-${versionVariable}.txt"/>
<!-- If from email address is empty, find the first non empty email
address from the POM. -->
<j:if test="${context.getVariable('maven.announcement.mail.from') == null}">
<j:forEach var="developer" items="${pom.developers}">
<j:if test="${not empty(developer.email)}">
<j:set var="maven.announcement.mail.from" value="${developer.email}"/>
<j:break/>
</j:if>
</j:forEach>
</j:if>
<!-- Ensure the directory where the announcement will be created exists -->
<ant:dirname property="announcementDir" file="${announcementFile}"/>
<ant:mkdir dir="${announcementDir}"/>
<ant:basename property="announcementFileName" file="${announcementFile}"/>
<util:file var="inputFile" name="${maven.docs.src}/changes.xml"/>
<j:useBean var="stringUtils" class="org.apache.commons.lang.StringUtils"/>
<j:set var="isLenient" value="${maven.announcement.lenient}"/>
</goal>
<goal name="announcement:check-version" prereqs="announcement:init">
<j:set var="changesXmlAvailable" value="false"/>
<util:available file="${inputFile}">
<j:set var="changesXmlAvailable" value="true"/>
</util:available>
<j:if test="${changesXmlAvailable}">
<x:parse var="doc" xml="${inputFile}"/>
<jsl:stylesheet select="$doc">
<jsl:template match="document/body/release">
<x:set var="version" select="string(@version)"/>
<j:if test="${versionVariable.equals(version)}">
<x:set var="versionFound" select="string(@version)"/>
</j:if>
</jsl:template>
<jsl:template match="@*"/>
<jsl:template match="text()"/>
</jsl:stylesheet>
</j:if>
<j:if test="${!isLenient}">
<j:if test="${versionFound == null}">
<ant:fail>The ${versionVariable} release could not be found in the changes.xml file.</ant:fail>
</j:if>
<!-- Check if a <version> tag is defined in the POM for the current release to be announced -->
<j:if test="${size(pom.versions)!=0}">
<j:set var="foundTag" value="false"/>
<j:forEach var="version" items="${pom.versions}">
<j:if test="${version.id==versionVariable}">
<j:set var="foundTag" value="true"/>
<j:break/>
</j:if>
</j:forEach>
<j:if test="${!foundTag}">
<ant:fail>Missing "version" element in the POM for release ${versionVariable}.</ant:fail>
</j:if>
</j:if>
</j:if>
<j:if test="${!changesXmlAvailable or versionFound == null}">
<!-- creates an empty changes.xml file -->
<j:set var="emptyChangesXml" value="${maven.build.dir}/empty-changes.xml"/>
<j:file
name="${emptyChangesXml}"
encoding="${maven.announcement.encoding}"
outputMode="xml"
omitXmlDeclaration="true"
prettyPrint="false">
<document>
<properties>
<title>Release Notes</title>
</properties>
<body>
<release version="${pom.currentVersion}" description="No description"/>
</body>
</document>
</j:file>
<util:file var="emptyChangesXmlFile" name="${emptyChangesXml}"/>
<x:parse var="doc" xml="${emptyChangesXmlFile}"/>
</j:if>
</goal>
<goal name="announcement:generate" prereqs="announcement:check-version"
description="Generate release announcement">
<announcement:generate file="${announcementFile}"/>
</goal>
<goal name="announcement:generate-all" prereqs="announcement:check-version"
description="Generate release announcement for all releases">
<j:choose>
<j:when test="${changesXmlAvailable}">
<x:parse var="doc" xml="${inputFile}"/>
<jsl:stylesheet select="$doc">
<jsl:template match="document/body/release">
<x:set var="versionVariable" select="string(@version)"/>
<j:set var="announcementFile"
value="${maven.gen.docs}/announcements/announcement-${versionVariable}.txt"/>
<announcement:generate file="${announcementFile}"/>
</jsl:template>
<jsl:template match="@*"/>
<jsl:template match="text()"/>
</jsl:stylesheet>
</j:when>
<j:when test="${!changesXmlAvailable and isLenient}">
<ant:echo>File ${inputFile} not found, but maven.announcement.lenient set to true: calling announcement!</ant:echo>
<attainGoal name="announcement"/>
</j:when>
<j:when test="${!changesXmlAvailable and !isLenient}">
<ant:fail>File ${inputFile} not available</ant:fail>
</j:when>
</j:choose>
</goal>
<goal name="announcement:mail" prereqs="announcement:generate"
description="Send an email containing the release announcement">
<announcement:mail file="${announcementFile}"/>
</goal>
<!-- Define common jelly script used by different goals as a jelly tag -->
<define:taglib uri="announcement">
<define:tag name="generate">
<!-- @file: Announcement file location -->
<!-- @versionVariable: version for which to generate the announcement -->
<echo>Generating announcement for release ${versionVariable} in ${file}...</echo>
<j:set var="stylesheetURI" value="file:${maven.announcement.stylesheet.path}"/>
<echo>Using stylesheet located at ${stylesheetURI} and ${maven.announcement.encoding} encoding</echo>
<j:file
name="${file}"
encoding="${maven.announcement.encoding}"
outputMode="xml"
omitXmlDeclaration="true"
prettyPrint="false">
<j:include uri="${stylesheetURI.toString()}"/>
</j:file>
<!-- FIXME: Hack for MPANNOUNCEMENT-10 -->
<ant:replace file="${file}" token="&amp;amp;amp;" value="&amp;"/>
<ant:replace file="${file}" token="&amp;amp;gt;" value="&gt;"/>
<ant:replace file="${file}" token="&amp;amp;lt;" value="&lt;"/>
<ant:fixcrlf
srcdir="${announcementDir}"
tab="remove"
tablength="4"
includes="${announcementFileName}"/>
</define:tag>
<define:tag name="mail">
<!-- @file: Announcement file location -->
<maven:param-check value="${maven.announcement.mail.server}" fail="true">The SMTP server name must be specified using the maven.announcement.mail.server property</maven:param-check>
<maven:param-check value="${maven.announcement.mail.from}" fail="true">The From address must be specified using the maven.announcement.mail.from property or by ensuring that at least one developer in the POM has an email address specified</maven:param-check>
<maven:param-check value="${maven.announcement.mail.to}" fail="true">The To address must be specified using the maven.announcement.mail.to property</maven:param-check>
<!-- Resolve dynamic %% templates from maven.announcement.mail.subject -->
<j:set var="maven.announcement.mail.subject"
value="${stringUtils.replace(context.getVariable('maven.announcement.mail.subject'), '%VERSION%', versionVariable)}"/>
<echo>Sending mail using SMTP server "${maven.announcement.mail.server}", client ${maven.announcement.mail.client} and subject "${maven.announcement.mail.subject}"...</echo>
<echo>Sending from "${maven.announcement.mail.from}" to "${maven.announcement.mail.to}"...</echo>
<util:loadText uri="file:${file}" var="announcementContent"/>
<j:invokeStatic className="org.apache.maven.announcement.MailUtils" method="sendMail" var="result">
<j:arg type="java.lang.String" value="${maven.announcement.mail.server}"/>
<j:arg type="java.lang.String" value="${maven.announcement.mail.client}"/>
<j:arg type="java.lang.String" value="${maven.announcement.mail.from}"/>
<j:arg type="java.lang.String" value="${maven.announcement.mail.to}"/>
<j:arg type="java.lang.String" value="${maven.announcement.mail.subject}"/>
<j:arg type="java.lang.String" value="${announcementContent}"/>
</j:invokeStatic>
<j:if test="${result != 'ok'}">
<fail>Could not send message. Reason: ${result}</fail>
</j:if>
</define:tag>
</define:taglib>
</project>