maven-plugins/xdoc/plugin.jelly
2003-07-29 02:03:08 +00:00

663 lines
24 KiB
XML

<?xml version="1.0"?>
<project xmlns:define="jelly:define"
xmlns:j="jelly:core"
xmlns:jsl="jelly:jsl"
xmlns:log="jelly:log"
xmlns:pom="pom"
xmlns:util="jelly:util"
xmlns:x="jelly:xml"
xmlns:velocity="jelly:velocity"
xmlns:doc="doc">
<j:new var="reports" className="java.util.ArrayList"/>
<define:taglib uri="doc">
<define:tag name="deregisterReport">
<!-- @name : Report to deregister, must be same as name used to register -->
<j:set
var="reports"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('reports')}"/>
<j:set var="removeRpt" value="null"/>
<j:forEach var="rpt" items="${reports}">
<j:if test="${rpt.get('name').equals(name)}">
<j:set var="removeRpt" value="${rpt}"/>
</j:if>
</j:forEach>
<j:if test="${removeRpt != null}">
<j:set var="dummy" value="${reports.remove(removeRpt)}"/>
</j:if>
</define:tag>
<define:tag name="registerReport">
<!--
@name the name of this report. Used for navigation items
@pluginName the name of the plugin. @plugin:report goal must exist
@description text description of report
@link the nav-bar link for this report
-->
<j:set
var="reports"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('reports')}"/>
<!-- check if the given name is in the list already -->
<j:set var="add" value="true"/>
<j:forEach var="rpt" items="${reports}">
<j:if test="${rpt.get('name').equals(name)}">
<j:set var="add" value="false"/>
</j:if>
</j:forEach>
<j:if test="${add.equals('true')}">
<j:new var="report" className="java.util.HashMap"/>
<j:set var="dummy" value="${report.put('name', name)}"/>
<j:set var="dummy" value="${report.put('pluginName', pluginName)}"/>
<j:set var="dummy" value="${report.put('description', description)}"/>
<j:set var="dummy" value="${report.put('link', link)}"/>
<j:set var="dummy" value="${reports.add(report)}"/>
</j:if>
</define:tag>
<define:tag name="formatAsNumber">
<!--
| @string
| @pattern
-->
<!-- This appears to need to be here which is no good. Need
more of a global tool box.
-->
<j:useBean var="formatter" class="org.apache.maven.DVSLFormatter"/>
${formatter.formatNumber(string,pattern)}
</define:tag>
<define:tag name="jslFile">
<!--
| Basic tag for performing arbitrary jsl transformations
| on arbitrary jsl inputs.
| @input
| @output
| @stylesheet
| @encoding
| @omitXmlDeclaration
| @outputMode
| @prettyPrint
-->
<!-- Set default encoding if not set. -->
<j:if test="${encoding == null}">
<j:set var="encoding"
value="${plugin.getVariable('maven.docs.outputencoding')}"/>
</j:if>
<util:file name="${input}" var="inputFile" />
<x:parse var="doc" xml="${inputFile}"/>
<j:set var="stylesheetURI" value="file:${stylesheet}"/>
<j:file
name="${output}"
encoding="${encoding}"
omitXmlDeclaration="${omitXmlDeclaration}"
outputMode="${outputMode}"
prettyPrint="${prettyPrint}">
<j:include uri="${stylesheetURI.toString()}"/>
</j:file>
</define:tag>
<define:tag name="jsl">
<!--
| This tag has a lot of defaults suitable for transforming
| documents easily. See jslCore for a tag suitable for
| transforming documents how you want.
| @input
| @output - Will be placed under ${maven.gen.docs}
| @stylesheet
| @encoding
| @omitXmlDeclaration
| @outputMode
| @prettyPrint
-->
<!--
@todo make sure the output directory exists.
-->
<!-- Set default outputDirectory if not set. -->
<!--
These do not work to evaluate to what you would expect
<j:if test="!${outputDirectory}">
why doesn't this give the same as comparing to null?
why not use empty()?
-->
<j:if test="${outputDirectory == null}">
<j:set
var="outputDirectory"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.gen.docs')}"
/>
</j:if>
<!-- Set default encoding if not set. -->
<j:if test="${encoding == null}">
<j:set
var="encoding"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.outputencoding')}"
/>
</j:if>
<j:if test="${omitXmlDeclaration == null}">
<j:set var="omitXmlDeclaration"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.omitXmlDeclaration')}"/>
</j:if>
<mkdir dir="${outputDirectory}"/>
<doc:jslFile
input="${input}"
output="${outputDirectory}/${output}"
stylesheet="${stylesheet}"
encoding="${encoding}"
omitXmlDeclaration="${omitXmlDeclaration}"
outputMode="${outputMode}"
prettyPrint="${prettyPrint}"/>
</define:tag>
<define:tag name="itemLink">
<!--
@link
@relativePath
@name
@img
@state - expanded / collapsed / none
-->
<a href="${pathTool.calculateLink(link,relativePath)}">
<img class="handle" src="${relativePath}/images/${state}.png" alt=""/>
<j:if test="${empty(img)}">${name}</j:if>
<j:if test="${!empty(img)}"><img style="border: 1px" src="${img}" title="${name}" alt="${name}"/></j:if>
</a>
</define:tag>
<define:tag name="text-xdoc">
<!--
@output - The output file
@title - Title for page
@section - Section heading
@encoding - The XML encoding
@preamble - Placed in paragraph block prior to text
@inputText - Will be wrapped in a CDATA, will not escape CDATA tags (as yet)
@inputFile - Will be read in and wrapped in CDATA. Overrides inputText if set
-->
<j:set var="inputFile">${inputFile}</j:set>
<j:if test="${inputFile != ''}">
<util:file name="${inputFile}" var="inputFileObject"/>
<util:loadText var="inputText" file="${inputFileObject}"/>
</j:if>
<!-- Set default encoding if not set. -->
<j:if test="${encoding == null}">
<j:set var="encoding"
value="${plugin.getVariable('maven.docs.outputencoding')}"/>
</j:if>
<j:file name="${output}" prettyPrint="false" encoding="${encoding}">
<document>
<properties><title>${title}</title></properties>
<body>
<section name="${section}">
<p>${preamble}</p>
<source>
<![CDATA[${inputText}]]>
</source>
</section>
</body>
</document>
</j:file>
</define:tag>
<!-- Alternator for row style in a table -->
<define:tag name="printRow">
<j:if test="${(count % 2) gt 0}">
<x:element name="tr">
<x:attribute name="class">a</x:attribute>
</x:element>
</j:if>
<j:if test="${(count % 2) le 0}">
<x:element name="tr">
<x:attribute name="class">b</x:attribute>
</x:element>
</j:if>
</define:tag>
<!-- Generates the JSL files on the given srcdir attribute -->
<define:tag name="performJSL">
<util:file var="srcdirFile" name="${srcdir}"/>
<j:set var="srcdir" value="${srcdirFile.getCanonicalPath()}"/>
<util:file var="destdirFile" name="${destdir}"/>
<j:set var="destdir" value="${destdirFile.getCanonicalPath()}"/>
<util:replace var="fromPattern" oldChar="\" newChar="/" value="${srcdir}/*.xml"/>
<util:replace var="toPattern" oldChar="\" newChar="/" value="${destdir}/*.html"/>
<j:setProperties object="${mapper}" from="${fromPattern}" to="${toPattern}"/>
<util:replace var="fromDirPattern" oldChar="\" newChar="/" value="${srcdir}*"/>
<util:replace var="toDirPattern" oldChar="\" newChar="/" value="${destdir}*"/>
<j:new var="dirMapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
<j:setProperties object="${dirMapper}" from="${fromDirPattern}" to="${toDirPattern}"/>
<fileScanner var="docFiles">
<fileset dir="${srcdir}">
<patternset>
<exclude name="**/project.xml"/>
<exclude name="**/template.xml"/>
<exclude name="**/navigation.xml"/>
<exclude name="changes.xml"/>
<include name="**/*.xml"/>
</patternset>
</fileset>
</fileScanner>
<!-- determine nav file to be used:- 1. check for sitewide nav files -->
<!-- supplied nav file as project.xml in stylesheets dir -->
<util:available file="${maven.docs.src}/stylesheets/project.xml">
<util:file var="siteNavFile" name="${maven.docs.src}/stylesheets/project.xml"/>
</util:available>
<!-- supplied nav file as project.xml in root of xdocs source tree -->
<util:available file="${maven.docs.src}/project.xml">
<util:file var="siteNavFile" name="${maven.docs.src}/project.xml"/>
</util:available>
<!-- supplied navigation file in root of xdocs source tree -->
<util:available file="${maven.docs.src}/navigation.xml">
<util:file var="siteNavFile" name="${maven.docs.src}/navigation.xml"/>
</util:available>
<!-- navigation file that was generated -->
<util:available file="${maven.gen.docs}/navigation.xml">
<util:file var="siteNavFile" name="${maven.gen.docs}/navigation.xml"/>
</util:available>
<!-- parse the project nav. Someone jellier than me can remove the temp file requirement -->
<j:set var="reports"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('reports')}"/>
<util:file var="tempnav" name="${maven.build.dir}/project-nav.xml"/>
<j:file name="${tempnav.toString()}" outputMode="xml">
<j:import file="${plugin.resources}/navigation.jelly" inherit="true"/>
</j:file>
<x:parse var="projectNavRoot" xml="${tempnav}"/>
<x:set var="projectNav" select="$projectNavRoot/project"/>
<j:forEach var="file" items="${docFiles.iterator()}">
<util:replace var="inDirForward" oldChar="\" newChar="/" value="${file.parent}"/>
<j:set var="outDir" value="${dirMapper.mapFileName(inDirForward).0}"/>
<mkdir dir="${outDir}"/>
<!-- generate output file name -->
<util:replace var="outFileForward" oldChar="\" newChar="/" value="${file.toString()}"/>
<j:set var="outFile" value="${mapper.mapFileName(outFileForward).0}"/>
<echo>Generating ${outFile} from ${file}</echo>
<!-- work out relative path -->
<util:replace var="docsForward" oldChar="\" newChar="/" value="${srcdir}"/>
<j:set var="relativePath" value="${pathTool.getRelativePath(docsForward, outFileForward)}"/>
<!-- determine nav file to be used: 2. check for nav file -->
<!-- in the same directory as xml file being processed -->
<!-- if no such nav file available use sitewide nav file -->
<j:set var="navFile" value="${siteNavFile}" />
<util:available file="${file.parentFile.absoluteFile}/navigation.xml">
<util:file var="navFile" name="${file.parentFile.absoluteFile}/navigation.xml"/>
</util:available>
<!-- parse nav and make it available to the stylesheet -->
<x:parse var="navXML" xml="${navFile}"/>
<x:set var="nav" select="$navXML/project"/>
<!-- parse the doc and pass it to the stylesheet -->
<x:parse var="doc" xml="${file}"/>
<j:file name="${outFile}" encoding="${outputencoding}"
omitXmlDeclaration="true" outputMode="xml"
prettyPrint="no">
<j:include uri="${stylesheet.toString()}"/>
</j:file>
</j:forEach>
</define:tag>
</define:taglib>
<!-- ================================================================== -->
<!-- P R O J E C T D O C U M E N T A T I O N -->
<!-- ================================================================== -->
<goal name="xdoc"
prereqs="xdoc:generate-from-pom, xdoc:transform"
description="Generate html project documentation xdoc sources"/>
<goal name="xdoc:init"
description="Generates the directory structure required for xdocs">
<mkdir dir="${maven.gen.docs}"/>
<mkdir dir="${maven.docs.dest}"/>
</goal>
<goal
name="xdoc:generate-from-pom"
prereqs="xdoc:init, xdoc:register-reports"
description="Generates xdocs for site based on project descriptor">
<echo>Generating xdocs from POM ... </echo>
<util:tokenize var="pomDocuments" delim=",">${maven.xdoc.pomDocuments}</util:tokenize>
<!-- All the templates use $project for now. -->
<j:set var="project" value="${pom}"/>
<j:set
var="reports"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('reports')}"/>
<!-- Does the user want the maven-generated docs on their site? -->
<j:set
var="includeProjectDocumentation"
value="${maven.xdoc.includeProjectDocumentation}"/>
<!-- Need the escaper to html output. -->
<j:useBean var="escape" class="org.apache.velocity.anakia.Escape"/>
<j:useBean var="files" class="org.apache.velocity.texen.util.FileUtil"/>
<!-- Need to enrich information about dependency by taking some information from its POM. -->
<j:useBean var="dependencyDescriber" class="org.apache.maven.DependencyDescriberBean"/>
${dependencyDescriber.build(pom)}
<j:if test="${encoding == null}">
<j:set
var="encoding"
value="${maven.docs.outputencoding}"
/>
</j:if>
<j:forEach var="pomDocument" items="${pomDocuments}">
<velocity:merge
name="${maven.gen.docs}/${pomDocument}"
basedir="${plugin.resources}/templates"
template="${pomDocument}"
inputEncoding="${encoding}"
outputEncoding="${encoding}"
/>
</j:forEach>
</goal>
<!-- ================================================================== -->
<!-- V A L I D A T E X D O C S -->
<!-- ================================================================== -->
<!-- validate xdocs -->
<goal name="xdoc:validate" prereqs="pom:taglib"
description="Validate xdocs match the schema">
<available file="${maven.docs.src}" type="dir"
property="maven.docs.src.available"/>
<j:if test="${maven.docs.src.available}">
<fileScanner var="navFiles">
<fileset dir="${maven.docs.src}">
<patternset>
<include name="**/navigation.xml"/>
</patternset>
</fileset>
</fileScanner>
<j:forEach var="file" items="${navFiles.iterator()}">
<echo>Validating ${file}</echo>
<pom:validate validator="${maven.home}/maven-navigation-1.0.xsd"
projectDescriptor="${file}"/>
</j:forEach>
</j:if>
</goal>
<!-- ================================================================== -->
<!-- C O P Y R E S O U R C E S -->
<!-- ================================================================== -->
<!-- copy resources needed for xdocs -->
<goal name="xdoc:copy-resources"
prereqs="xdoc:init"
description="copy static resources for use in xdocs generated html">
<!-- Read in the ui properties. -->
<util:properties uri="file:${plugin.resources}/ui.properties" var="uiProperties"/>
<!-- Copy maven supplied stylesheets. -->
<copy todir="${maven.docs.dest}/style" overwrite="yes" filtering="yes">
<fileset dir="${plugin.resources}/css">
<include name="**/*.css"/>
</fileset>
<filterset>
<j:forEach var="uiProperty" items="${uiProperties.keys()}">
<util:replace var="token" oldChar="." newChar="_" value="${uiProperty}"/>
<j:set var="token" value="${token.substring(6).toUpperCase()}"/>
<!-- Check if User has overidden this property -->
<j:set var="propertyName" value="${uiProperty}" />
<j:set var="propertyValue" value="${context.getVariable(propertyName)}"/>
<j:choose>
<j:when test="${propertyValue != null}">
<!-- Use user's properties -->
<filter token="${token}" value="${propertyValue}"/>
</j:when>
<j:otherwise>
<!-- Use plugin's default properties -->
<filter token="${token}" value="${uiProperties.getProperty(uiProperty)}"/>
</j:otherwise>
</j:choose>
</j:forEach>
</filterset>
</copy>
<!-- Copy maven supplied images. -->
<copy todir="${maven.docs.dest}/images" overwrite="yes" filtering="no">
<fileset dir="${plugin.resources}/images">
<include name="**/*.gif"/>
<include name="**/*.jpeg"/>
<include name="**/*.jpg"/>
<include name="**/*.png"/>
</fileset>
</copy>
</goal>
<!-- ================================================================== -->
<!-- C O P Y U S E R S U P P L I E D R E S O U R C E S -->
<!-- ================================================================== -->
<!-- copy user resources -->
<goal name="xdoc:copy-user-resources"
prereqs="xdoc:init"
description="Copy user provided resources to docs destination">
<j:if test="${maven.docs.src.available}">
<!-- Copy user supplied resources -->
<copy todir="${maven.docs.dest}" filtering="no">
<fileset dir="${maven.docs.src}">
<exclude name="**/*.xml"/>
<exclude name="**/CVS/*"/>
<exclude name="stylesheets/*"/>
</fileset>
</copy>
<util:available file="${maven.docs.src}/stylesheets">
<!-- Copy user supplied stylesheets, can override maven -->
<copy todir="${maven.docs.dest}/style" overwrite="true" filtering="no">
<fileset dir="${maven.docs.src}/stylesheets">
<include name="**/*.css"/>
</fileset>
</copy>
</util:available>
</j:if>
</goal>
<!-- ================================================================== -->
<!-- D V S L D O C U M E N T A T I O N -->
<!-- ================================================================== -->
<goal name="xdoc:transform"
prereqs="xdoc:init"
description="Generate html project documentation xdoc sources">
<tstamp>
<format property="mavenCurrentYear" pattern="yyyy"/>
</tstamp>
<!-- Use jelly utils here -->
<available
file="${maven.gen.docs}"
type="dir"
property="maven.gen.docs.available"
/>
<available
file="${maven.docs.src}"
type="dir"
property="maven.docs.src.available"
/>
<!-- use JSL in Jelly to build the documenation -->
<attainGoal name="xdoc:copy-resources"/>
<attainGoal name="xdoc:copy-user-resources"/>
<attainGoal name="xdoc:jelly-transform"/>
</goal>
<!-- ================================================================== -->
<!-- J E L L Y D O C U M E N T A T I O N -->
<!-- ================================================================== -->
<goal name="xdoc:jelly-init" description="Set up jelly xdoc requirements">
<!-- moving here temporarily -->
<tstamp>
<format property="mavenCurrentYear" pattern="yyyy"/>
</tstamp>
<tstamp>
<format property="build.date" pattern="${maven.xdoc.date.format}"
locale="${maven.xdoc.date.locale}"/>
</tstamp>
</goal>
<goal name="xdoc:register-reports">
<!--
| We need to have each <report> register itself with us so we can
| build up our navbar. To do this, we call the plugin:register
| goal on each report plugin.
|-->
<j:if test="${!pom.reports.isEmpty()}">
<j:forEach var="report" items="${pom.reports}">
<attainGoal name="${report}:register"/>
</j:forEach>
</j:if>
<!-- If the descriptor is empty, use these as defaults -->
<j:if test="${pom.reports.isEmpty()}">
<attainGoal name="maven-jdepend-plugin:register"/>
<attainGoal name="maven-checkstyle-plugin:register"/>
<attainGoal name="maven-changes-plugin:register"/>
<attainGoal name="maven-changelog-plugin:register"/>
<attainGoal name="maven-developer-activity-plugin:register"/>
<attainGoal name="maven-file-activity-plugin:register"/>
<attainGoal name="maven-license-plugin:register"/>
<attainGoal name="maven-javadoc-plugin:register"/>
<attainGoal name="maven-jxr-plugin:register"/>
<attainGoal name="maven-junit-report-plugin:register"/>
<attainGoal name="maven-linkcheck-plugin:register"/>
<attainGoal name="maven-tasklist-plugin:register"/>
</j:if>
</goal>
<goal name="xdoc:jelly-transform"
prereqs="xdoc:init, xdoc:jelly-init, xdoc:register-reports"
description="transform xdocs using jelly/jsl rather than dvsl">
<j:set var="destdir" value="${maven.docs.dest}"/>
<j:set var="outputencoding" value="${maven.docs.outputencoding}"/>
<!-- need to parse navigation into $nav -->
<!-- mapper for determining output file name -->
<j:new var="mapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
<!-- path tool for relative processing -->
<j:useBean var="pathTool" class="org.apache.maven.DVSLPathTool"/>
<!-- tool for loading resources from the class loader -->
<j:useBean class="org.apache.maven.util.ResourceBean" var="resourceTool"/>
<!-- determine which stylesheet to use -->
<j:set var="stylesheet" value="${maven.xdoc.jsl}"/>
<j:if test="${empty(stylesheet)}">
<j:set var="stylesheet" value="${resourceTool.findResource('plugin-resources/site.jsl')}"/>
<j:if test="${empty(stylesheet)}">
<log:warn>Could not load the JSL stylesheet 'site.jsl' on the classpath</log:warn>
<j:set var="stylesheet" value="./site.jsl"/>
</j:if>
</j:if>
<util:available file="${maven.gen.docs}">
<log:info>About to use JSL stylesheet ${stylesheet}</log:info>
<!-- perform JSL on generated docs -->
<doc:performJSL srcdir="${maven.gen.docs}" destdir="${maven.docs.dest}"/>
</util:available>
<!-- perform JSL on user provided docs -->
<j:if test="${maven.docs.src.available}">
<log:info>
Transforming user supplied documentation.
</log:info>
<doc:performJSL srcdir="${maven.docs.src}" destdir="${maven.docs.dest}"/>
</j:if>
</goal>
<!-- This is required as the linkchecker runs as a final pass over the generated
document tree -->
<goal name="xdoc:performJSL"
description="Allows the LinkCheck plugin to xdoc a single directory">
<j:set var="maven.xdoc.src" value="${pom.getPluginContext('maven-linkcheck-plugin').getVariable('maven.xdoc.src')}"/>
<doc:performJSL
srcdir="${maven.xdoc.src}"
destdir="${maven.docs.dest}"/>
</goal>
<goal name="xdoc:dump-report-settings">
<echo>Dumping report settings</echo>
<j:set
var="reports"
value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('reports')}"/>
<j:forEach var="report" items="${reports}">
<echo>Report: ${report}</echo>
</j:forEach>
</goal>
</project>