maven-plugins/faq/plugin.jelly
aheritier 376ee46708 MPFAQ-11 : Questions' font is same size or smaller than answers' one. Xdoc plugin > 1.9.2 required.
Patch submitted by : Lukas Theussl
Patch reviewed by : Arnaud Heritier

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@267498 13f79535-47bb-0310-9956-ffa450edef68
2005-09-03 21:25:38 +00:00

153 lines
5.8 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"
xmlns:util="jelly:util"
xmlns:x="jelly:xml"
xmlns:ant="jelly:ant"
xmlns:define="jelly:define"
xmlns:doc="doc"
xmlns:faq="faq">
<j:if test="${bootstrapping == null}">
<!-- Poor mans version check - plugin dependencies still suck for multiple versions -->
<maven:get plugin="maven-xdoc-plugin" property="plugin" var="xdocPlugin" />
<j:if test="${empty(xdocPlugin) or xdocPlugin.currentVersion.compareTo('1.9.2') lt 0}">
<ant:fail>
Must have XDOC plugin v1.9.2 installed to use this version of the faq plugin.
Try: maven plugin:download -DgroupId=maven -DartifactId=maven-xdoc-plugin -Dversion=1.9.2
You can find the latest version of the XDOC plugin on the Maven Download page at
http://maven.apache.org/start/download.html
</ant:fail>
</j:if>
</j:if>
<define:taglib uri="faq">
<!--
Transforms *.fml files into *.xml xdoc files.
parameters:
srcdir: directory where to find *.fml files under
destdir: directory where to produce output xdoc xml files
-->
<define:tag name="performTransformation">
<!-- NOTE: part of this tag implementation is based on jelly-code from xdoc-plugin -->
<util:available file="${srcdir}">
<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()}"/>
<!-- construct a mapper, which is to help map input files to output path -->
<util:replace var="fromPattern" oldChar="\" newChar="/" value="${srcdir}/*.fml"/>
<util:replace var="toPattern" oldChar="\" newChar="/" value="${destdir}/*.xml"/>
<j:if test="${mapper == null}">
<j:new var="mapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
</j:if>
<j:setProperties object="${mapper}" from="${fromPattern}" to="${toPattern}"/>
<!-- construct a mapper, which is to help map input dirs to output dirs (so we can create output paths) -->
<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}"/>
<!-- scan for all .fml faq source files -->
<ant:fileScanner var="faqFilenames">
<ant:fileset dir="${srcdir}">
<ant:patternset>
<ant:include name="**/*.fml"/>
</ant:patternset>
</ant:fileset>
</ant:fileScanner>
<!-- loop each found .fml file and produce output .xml xdocs file -->
<j:forEach var="faqFile" items="${faqFilenames.iterator()}">
<!-- first, create the relative output-dir into the destdir -->
<!-- e.g.: if source file is "xdocs/faqs/foofaq.fml" we need to create "target/generated-xdocs/faqs" -->
<util:replace var="inDirForward" oldChar="\" newChar="/" value="${faqFile.parent}"/>
<j:set var="outDir" value="${dirMapper.mapFileName(inDirForward).0}"/>
<mkdir dir="${outDir}"/>
<!-- generate output file name -->
<util:replace var="outFileForward" oldChar="\" newChar="/" value="${faqFile.toString()}"/>
<j:set var="outFile" value="${mapper.mapFileName(outFileForward).0}"/>
<echo>Generating ${outFile} from ${faqFile}</echo>
<!-- produce a output xdoc xml file from parsed .fml source -->
<doc:jslFile
input="${faqFile}"
output="${outFile}"
stylesheet="${plugin.resources}/faq.jsl"
outputMode="xml"
omitXmlDeclaration="false"
prettyPrint="false"
/>
</j:forEach>
</util:available>
</define:tag>
</define:taglib>
<goal name="faq:init">
<mkdir dir="${maven.faq.src}" />
<fileScanner var="fmlFiles">
<fileset dir="${maven.faq.src}" includes="**/*.fml"/>
</fileScanner>
</goal>
<goal name="maven-faq-plugin:register" prereqs="faq:init">
<!-- Only register the faq report if there are some fml files in
the project -->
<j:if test="${fmlFiles.iterator().hasNext()}">
<doc:registerReport
name="FAQs"
pluginName="maven-faq-plugin"
description="Frequently Asked Questions."
link="faq"/>
</j:if>
</goal>
<goal name="maven-faq-plugin:deregister" prereqs="faq:init">
<!-- Only deregister the faq report if there are some fml files in
the project -->
<j:if test="${fmlFiles.iterator().hasNext()}">
<doc:deregisterReport name="FAQs"/>
</j:if>
</goal>
<goal name="maven-faq-plugin:report"
description="Generate FAQs">
<attainGoal name="faq"/>
</goal>
<goal name="faq" description="Generates FAQ xdoc files from FAQ XML documents">
<faq:performTransformation srcdir="${maven.faq.src}" destdir="${maven.faq.dest}" />
</goal>
</project>