Apply MAVEN-904 with some changes for reporting.

Add a test project to test new functionality.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114180 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
dion 2003-10-10 00:04:08 +00:00
parent f0ce20ec34
commit a7badd88b1
7 changed files with 242 additions and 46 deletions

View File

@ -5,58 +5,71 @@
xmlns:util="jelly:util" xmlns:util="jelly:util"
xmlns:x="jelly:xml" xmlns:x="jelly:xml"
xmlns:ant="jelly:ant" xmlns:ant="jelly:ant"
xmlns:doc="doc"> xmlns:define="jelly:define"
xmlns:doc="doc"
xmlns:faq="faq">
<goal name="maven-faq-plugin:register"> <define:taglib uri="faq">
<doc:registerReport
name="FAQs"
pluginName="faq"
description="Frequently Asked Questions."
link="faq"/>
</goal>
<goal name="maven-faq-plugin:deregister">
<doc:deregisterReport name="FAQs"/>
</goal>
<goal name="faq:report"
description="Generate FAQs">
<attainGoal name="faq"/>
</goal>
<!-- <!--
| @TODO: Make this a tag and transform multiple *.fml files 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
--> -->
<goal name="faq" <define:tag name="performTransformation">
description="Generates an FAQ xdoc file from an FAQ XML document"> <!-- NOTE: part of this tag implementation is based on jelly-code from xdoc-plugin -->
<j:set var="destfile" value="${maven.faq.dest.file}"/> <util:file var="srcdirFile" name="${srcdir}"/>
<j:if test="${empty(destfile)}"> <j:set var="srcdir" value="${srcdirFile.getCanonicalPath()}"/>
<j:set var="destfile" value="${maven.build.dir}/generated-xdocs/faq.xml"/> <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:if>
<j:setProperties object="${mapper}" from="${fromPattern}" to="${toPattern}"/>
<ant:mkdir dir="${maven.build.dir}/generated-xdocs"/> <!-- 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}"/>
<j:set var="srcfile" value="${maven.faq.src.file}"/> <!-- scan for all .fml faq source files -->
<j:if test="${empty(srcfile)}"> <ant:fileScanner var="faqFilenames">
<j:set var="srcfile" value="${basedir}/xdocs/faq.fml"/> <ant:fileset dir="${srcdir}">
</j:if> <ant:patternset>
<ant:include name="**/*.fml"/>
<util:file var="srcfileFile" name="${srcfile}"/> </ant:patternset>
<j:set var="srcfile" value="${srcfileFile.canonicalPath}"/> </ant:fileset>
<util:file var="destfileFile" name="${destfile}"/> </ant:fileScanner>
<j:set var="destfile" value="${destfileFile.canonicalPath}"/>
<j:set var="outputencoding" value="${maven.docs.outputencoding}"/> <j:set var="outputencoding" value="${maven.docs.outputencoding}"/>
<util:available file="${srcfile}"> <!-- loop each found .fml file and produce output .xml xdocs file -->
<j:set var="srcFileExists" value="true" /> <j:forEach var="faqFile" items="${faqFilenames.iterator()}">
</util:available> <!-- first, create the relative output-dir into the destdir -->
<j:if test="${srcFileExists == 'true'}"> <!-- e.g.: if source file is "xdocs/faqs/foofaq.fml" we need to create "target/generated-xdocs/faqs" -->
<x:parse var="doc" xml="${srcfileFile}"/> <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>
<!-- xml-parse .fml faq file -->
<x:parse var="doc" xml="${faqFile}"/>
<x:set var="root" select="$doc/*"/> <x:set var="root" select="$doc/*"/>
<j:file name="${destfile}" encoding="${outputencoding}" outputMode="xml"> <!-- produce a output xdoc xml file from parsed .fml source -->
<j:file name="${outFile}" encoding="${outputencoding}" outputMode="xml">
<document> <document>
<properties> <properties>
@ -103,7 +116,30 @@
</body> </body>
</document> </document>
</j:file> </j:file>
</j:if> </j:forEach>
</define:tag>
</define:taglib>
<goal name="maven-faq-plugin:register">
<doc:registerReport
name="FAQs"
pluginName="maven-faq-plugin"
description="Frequently Asked Questions."
link="faq"/>
</goal>
<goal name="maven-faq-plugin:deregister">
<doc:deregisterReport name="FAQs"/>
</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> </goal>
</project> </project>

5
faq/plugin.properties Normal file
View File

@ -0,0 +1,5 @@
# Where source *.fml files are looked for
maven.faq.src=${basedir}/xdocs
# Destination directory where output xdocs file are produced
maven.faq.dest=${maven.build.dir}/generated-xdocs

View File

@ -0,0 +1,2 @@
*.log
target

View File

@ -0,0 +1,26 @@
<project xmlns:util="jelly:util"
xmlns:j="jelly:core">
<goal name="testPlugin" prereqs="clean,test-faq">
<!-- bad xdoc leaves files open <attainGoal name="clean"/> -->
</goal>
<goal name="test-faq">
<attainGoal name="site"/>
<j:set var="expectedFile"
value="${maven.docs.dest}/faq.html"/>
<util:file var="file" name="${expectedFile}" />
<j:if test="${!(file.exists())}">
<fail>${expectedFile} not generated</fail>
</j:if>
<j:set var="expectedFile"
value="${maven.docs.dest}/faq2.html"/>
<util:file var="file" name="${expectedFile}" />
<j:if test="${!(file.exists())}">
<fail>${expectedFile} not generated</fail>
</j:if>
</goal>
</project>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<pomVersion>3</pomVersion>
<id>test-maven-faq-plugin</id>
<name>Test project for Maven Faq Plugin</name>
<groupId>maven</groupId>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
<logo>http://maven.apache.org/images/jakarta-logo-blue.gif</logo>
</organization>
<inceptionYear>2001</inceptionYear>
<package>org.apache.maven</package>
<logo>http://maven.apache.org/images/maven.jpg</logo>
<description>Test for Maven Faq plugin</description>
<shortDescription>Test for Maven Faq plugin</shortDescription>
<url>http://maven.apache.org/reference/plugins/faq/</url>
<siteDirectory>/www/maven.apache.org/reference/plugins/faq/</siteDirectory>
<repository>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/faq/</connection>
<url>http://cvs.apache.org/viewcvs/maven/src/plugins-build/faq/</url>
</repository>
<developers>
<developer>
<name>dIon Gillard</name>
<id>dion</id>
<email>dion@multitask.com.au</email>
<organization>Multitask Consulting</organization>
<roles>
<role>Documentation</role>
</roles>
</developer>
</developers>
<build>
</build>
<reports>
<report>maven-faq-plugin</report>
</reports>
</project>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<faqs title="Frequently Asked Questions">
<part id="general">
<title>General</title>
<faq id="whats-foo">
<question>
What is Foo?
</question>
<answer>
<p>some markup goes here</p>
<source>some source code</source>
<p>some markup goes here</p>
</answer>
</faq>
<faq id="whats-bar">
<question>
What is Bar?
</question>
<answer>
<p>some markup goes here</p>
</answer>
</faq>
</part>
<part id="install">
<title>Installation</title>
<faq id="how-install">
<question>
How do I install Foo?
</question>
<answer>
<p>some markup goes here</p>
</answer>
</faq>
</part>
</faqs>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<faqs title="Frequently Asked Questions">
<part id="general">
<title>General</title>
<faq id="whats-foo">
<question>
What is Foo?
</question>
<answer>
<p>some markup goes here</p>
<source>some source code</source>
<p>some markup goes here</p>
</answer>
</faq>
<faq id="whats-bar">
<question>
What is Bar?
</question>
<answer>
<p>some markup goes here</p>
</answer>
</faq>
</part>
<part id="install">
<title>Installation</title>
<faq id="how-install">
<question>
How do I install Foo?
</question>
<answer>
<p>some markup goes here</p>
</answer>
</faq>
</part>
</faqs>