maven-plugins/pdf/plugin.jelly

389 lines
18 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* 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:u="jelly:util"
xmlns:ant="jelly:ant"
xmlns:maven="jelly:maven"
xmlns:doc="doc"
xmlns:plugin="plugin">
<goal name="maven-pdf-plugin:register" description="Register the pdf generation during site goal." prereqs="pdf:init">
<!-- We register it but we need to specify the extension -->
<doc:registerReport name="PDF Documentation" pluginName="maven-pdf-plugin" target="_blank" description="Documentation in PDF format." link="${maven.pdf.pdfName.substring(0,maven.pdf.pdfName.length()-4)}" fileSuffix=".pdf" image="/images/pdf.gif"/>
</goal>
<goal name="maven-pdf-plugin:deregister" description="Deregister the pdf generation.">
<doc:deregisterReport name="PDF"/>
</goal>
<goal name="maven-pdf-plugin:report" description="Called by xdoc to execute the pdf goal.">
<!--
using a postgoal so that maven generated reports are on place
(xdoc:generate-from-pom is called after report generation)
-->
<postGoal name="xdoc:generate-from-pom">
<attainGoal name="pdf"/>
</postGoal>
</goal>
<goal name="pdf:init" prereqs="xdoc:init">
<!-- xdoc plugin properties -->
<maven:get var="maven.xdoc.src" plugin="maven-xdoc-plugin" property="maven.docs.src"/>
<maven:get var="maven.xdoc.dest" plugin="maven-xdoc-plugin" property="maven.docs.dest"/>
<maven:get var="maven.xdoc.gen" plugin="maven-xdoc-plugin" property="maven.gen.docs"/>
<maven:get var="maven.xdoc.date.format" plugin="maven-xdoc-plugin" property="maven.xdoc.date.format"/>
<maven:get var="maven.xdoc.date.locale" plugin="maven-xdoc-plugin" property="maven.xdoc.date.locale"/>
<tstamp>
<format property="maven.pdf.cover.date" pattern="${maven.xdoc.date.format}" locale="${maven.xdoc.date.locale}"/>
<format property="mavenCurrentYear" pattern="yyyy"/>
</tstamp>
<j:set var="image" value="${maven.pdf.projectLogo}"/>
<j:if test="${!image.startsWith('http://') and !image.startsWith('https://')}">
<j:if test="${image.startsWith('/')}" trim="yes">
<j:set var="image" value="${image.substring(1)}"/>
</j:if>
<j:set var="maven.pdf.projectLogo" value="${image}"/>
</j:if>
<j:set var="image" value="${maven.pdf.companyLogo}"/>
<j:if test="${!image.startsWith('http://') and !image.startsWith('https://')}">
<j:if test="${image.startsWith('/')}" trim="yes">
<j:set var="image" value="${image.substring(1)}"/>
</j:if>
<j:set var="maven.pdf.companyLogo" value="${image}"/>
</j:if>
<!-- internal variables -->
<j:set var="internal_pdf_workingDir" value="${maven.build.dir}/pdf"/>
<j:if test="${maven.pdf.debug}">
<ant:echo>
### Debug mode is on ###
==============================
=== xdoc plugin properties ===
==============================
maven.docs.src = [${maven.xdoc.src}]
maven.docs.dest = [${maven.xdoc.dest}]
maven.gen.docs = [${maven.xdoc.gen}]
maven.xdoc.date.format = [${maven.xdoc.date.format}]
maven.xdoc.date.locale = [${maven.xdoc.date.locale}]
==============================
=== pdf plugin properties ===
==============================
maven.pdf.confidential = [${maven.pdf.confidential}]
maven.pdf.paperType = [${maven.pdf.paperType}]
maven.pdf.companyIncName = [${maven.pdf.companyIncName}]
maven.pdf.copyrightYear = [${maven.pdf.copyrightYear}]
maven.pdf.imageDpi = [${maven.pdf.imageDpi}]
maven.pdf.debug = [${maven.pdf.debug}]
maven.pdf.navigationFile = [${maven.pdf.navigationFile}]
maven.pdf.navigationFilePath = [${maven.pdf.navigationFilePath}]
maven.pdf.pdfName = [${maven.pdf.pdfName}]
maven.pdf.cover.projectCompany = [${maven.pdf.cover.projectCompany}]
maven.pdf.cover.projectName = [${maven.pdf.cover.projectName}]
maven.pdf.cover.type = [${maven.pdf.cover.type}]
maven.pdf.cover.version = [${maven.pdf.cover.version}]
maven.pdf.cover.date = [${maven.pdf.cover.date}]
maven.pdf.projectLogo = [${maven.pdf.projectLogo}]
maven.pdf.companyLogo = [${maven.pdf.companyLogo}]
maven.pdf.createBookmarks = [${maven.pdf.createBookmarks}]
maven.pdf.generateTOC = [${maven.pdf.generateTOC}]
maven.jar.jimi = [${maven.jar.jimi}]
maven.jar.jaicore = [${maven.jar.jaicore}]
maven.jar.jaicodec = [${maven.jar.jaicodec}]
==============================
=== pdf internal variables ===
==============================
internal_pdf_workingDir = [${internal_pdf_workingDir}]
maven.application.version = [${maven.application.version}]
plugin.currentVersion = [${plugin.currentVersion}]
</ant:echo>
</j:if>
<j:if test="not ${maven.pdf.debug}">
<ant:echo>
### Debug mode is off ###
</ant:echo>
</j:if>
<!-- Create working directory -->
<mkdir dir="${internal_pdf_workingDir}"/>
<maven:get plugin="maven-xdoc-plugin" property="plugin.resources" var="xdoc.plugin.resources" />
<copy todir="${maven.docs.dest}/images/" overwrite="yes" filtering="no">
<fileset dir="${plugin.resources}/images/">
<include name="**/*"/>
</fileset>
<fileset dir="${xdoc.plugin.resources}/images/">
<include name="**/*"/>
</fileset>
</copy>
</goal>
<goal name="fo" prereqs="fo:fo" description="This simply pre-requisites the fo:fo goal. "/>
<goal name="fo:fo" prereqs="pdf:prepare" description="Generates an fo xml document from the ${maven.pdf.navigationFile} file supplied as part of the documentation.">
<echo>Generating ${internal_pdf_workingDir}/project.fo from ${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile} ...</echo>
<available file="${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile}" property="maven.fo.navigation.available"/>
<fail message="PDF generation cannot complete as ${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile} is missing" unless="maven.fo.navigation.available"/>
<j:set var="_copyrightYear" value="${maven.pdf.copyrightYear}"/>
<j:if test="${empty(_copyrightYear)}">
<j:set var="_copyrightYear">
<j:set var="_organizationName" value="${pom.organization.name}"/>
<j:if test="${!empty(_organizationName)}">
<j:set var="_inceptionYear" value="${pom.inceptionYear}"/>
<j:if test="${!empty(_inceptionYear)}">
<j:if test="${_inceptionYear == mavenCurrentYear}">${mavenCurrentYear}</j:if>
<j:if test="${_inceptionYear != mavenCurrentYear}">${_inceptionYear}-${mavenCurrentYear}</j:if>
</j:if>
<j:if test="${empty(_inceptionYear)}">${mavenCurrentYear}</j:if>
</j:if>
</j:set>
</j:if>
<java classname="org.apache.xalan.xslt.Process" dir="${internal_pdf_workingDir}" fork="true" failonerror="true">
<arg value="-IN"/>
<arg value="${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile}"/>
<arg value="-XSL"/>
<arg value="${plugin.resources}/project2fo.xslt"/>
<arg value="-OUT"/>
<arg value="${internal_pdf_workingDir}/project.fo"/>
<j:set var="_basePath" value="${internal_pdf_workingDir}"/>
<j:if test="${not empty(_basePath)}">
<arg value="-PARAM"/>
<arg value="basePath"/>
<arg value="${_basePath}"/>
</j:if>
<j:set var="_confidential" value="${maven.pdf.confidential}"/>
<j:if test="${not empty(_confidential)}">
<arg value="-PARAM"/>
<arg value="confidential"/>
<arg value="${_confidential}"/>
</j:if>
<j:set var="_generateTOC" value="${maven.pdf.generateTOC}"/>
<j:if test="${not empty(_generateTOC)}">
<arg value="-PARAM"/>
<arg value="generateTOC"/>
<arg value="${_generateTOC}"/>
</j:if>
<j:set var="_paperType" value="${maven.pdf.paperType}"/>
<j:if test="${not empty(_paperType)}">
<arg value="-PARAM"/>
<arg value="paperType"/>
<arg value="${_paperType}"/>
</j:if>
<j:set var="_companyIncName" value="${maven.pdf.companyIncName}"/>
<j:if test="${not empty(_companyIncName)}">
<arg value="-PARAM"/>
<arg value="companyIncName"/>
<arg value="${_companyIncName}"/>
</j:if>
<!-- copyrightYear is always set above -->
<arg value="-PARAM"/>
<arg value="publicationYear"/>
<arg value="${_copyrightYear}"/>
<j:set var="_projectCompany" value="${maven.pdf.cover.projectCompany}"/>
<j:if test="${not empty(_projectCompany)}">
<arg value="-PARAM"/>
<arg value="coverProjectCompany"/>
<arg value="${_projectCompany}"/>
</j:if>
<j:set var="_projectName" value="${maven.pdf.cover.projectName}"/>
<j:if test="${not empty(_projectName)}">
<arg value="-PARAM"/>
<arg value="coverProjectName"/>
<arg value="${_projectName}"/>
</j:if>
<j:set var="_coverType" value="${maven.pdf.cover.type}"/>
<j:if test="${not empty(_coverType)}">
<arg value="-PARAM"/>
<arg value="coverType"/>
<arg value="${_coverType}"/>
</j:if>
<j:set var="_coverVersion" value="${maven.pdf.cover.version}"/>
<j:if test="${not empty(_coverVersion)}">
<arg value="-PARAM"/>
<arg value="coverVersion"/>
<arg value="${_coverVersion}"/>
</j:if>
<j:set var="_coverDate" value="${maven.pdf.cover.date}"/>
<j:if test="${not empty(_coverDate)}">
<arg value="-PARAM"/>
<arg value="coverDate"/>
<arg value="${_coverDate}"/>
</j:if>
<j:set var="_companyLogo" value="${maven.pdf.companyLogo}"/>
<j:if test="${not empty(_companyLogo)}">
<arg value="-PARAM"/>
<arg value="companyLogo"/>
<arg value="${_companyLogo}"/>
</j:if>
<j:set var="_projectLogo" value="${maven.pdf.projectLogo}"/>
<j:if test="${not empty(_projectLogo)}">
<arg value="-PARAM"/>
<arg value="projectLogo"/>
<arg value="${_projectLogo}"/>
</j:if>
<j:set var="_imageDpi" value="${maven.pdf.imageDpi}"/>
<j:if test="${not empty(_imageDpi)}">
<arg value="-PARAM"/>
<arg value="imageDpi"/>
<arg value="${_imageDpi}"/>
</j:if>
<j:set var="_debug" value="${maven.pdf.debug}"/>
<j:if test="${not empty(_debug)}">
<arg value="-PARAM"/>
<arg value="debug"/>
<arg value="${_debug}"/>
</j:if>
<j:set var="_createBookmarks" value="${maven.pdf.createBookmarks}"/>
<j:if test="${not empty(_createBookmarks)}">
<arg value="-PARAM"/>
<arg value="createBookmarks"/>
<arg value="${_createBookmarks}"/>
</j:if>
<j:set var="_header_Height" value="${maven.pdf.cover.headerHeight}"/>
<j:if test="${not empty(_header_Height)}">
<arg value="-PARAM"/>
<arg value="header_Height"/>
<arg value="${_header_Height}"/>
</j:if>
<j:set var="_footer_Height" value="${maven.pdf.cover.footerHeight}"/>
<j:if test="${not empty(_footer_Height)}">
<arg value="-PARAM"/>
<arg value="footer_Height"/>
<arg value="${_footer_Height}"/>
</j:if>
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="org.apache.xerces.jaxp.DocumentBuilderFactoryImp"/>
<sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<sysproperty key="java.endorsed.dirs" path="${java.home}/lib/endorsed;${maven.home}/lib/endorsed}"/>
<classpath>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xalan')}"/>
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
</classpath>
</java>
</goal>
<goal name="pdf" prereqs="fo:fo,pdf:pdf" description="This is the default goal of the plugin and simply pre-requisites the pdf:pdf goal. "/>
<goal name="pdf:prepare" prereqs="pdf:init" description="Stages all files needed to generate the PDF">
<!-- First, copy all of the generated xdocs -->
<copy todir="${internal_pdf_workingDir}" force="true" overwrite="true">
<fileset dir="${maven.xdoc.gen}">
<include name="**/*.*"/>
</fileset>
</copy>
<!-- Copy all of the user-supplied xdocs -->
<copy todir="${internal_pdf_workingDir}" force="true" overwrite="true">
<fileset dir="${maven.xdoc.src}">
<include name="**/*.*"/>
</fileset>
</copy>
<!-- Then, copy all of images generated -->
<copy todir="${internal_pdf_workingDir}" force="true" overwrite="true">
<fileset dir="${maven.xdoc.dest}">
<include name="**/*.gif"/>
<include name="**/*.jpg"/>
<include name="**/*.png"/>
</fileset>
</copy>
<!-- Finally, copy the FOP config file and all of the fonts -->
<copy todir="${internal_pdf_workingDir}" force="true" overwrite="true">
<fileset dir="${plugin.resources}">
<include name="userconfig.xml"/>
<include name="fonts/*.*"/>
</fileset>
</copy>
</goal>
<goal name="pdf:pdf" description="Generates a PDF document containing all project documentation. The PDF is generated from the .fo file generated in the fo:fo goal." prereqs="pdf:prepare">
<echo>Generating ${internal_pdf_workingDir}/${maven.pdf.pdfName} ...</echo>
<echo>Config file: ${internal_pdf_workingDir}/userconfig.xml</echo>
<java classname="org.apache.fop.apps.Fop" fork="true" failonerror="true">
<sysproperty key="javax.xml.transform.TransformerFactory" value="org.apache.xalan.processor.TransformerFactoryImpl"/>
<!-- System proxies for jdk 1.5+ -->
<sysproperty key="java.net.useSystemProxies" value="true"/>
<!-- Proxy settings -->
<j:if test="${!empty(maven.proxy.host)}">
<jvmarg value="-DproxySet=true"/>
<jvmarg value="-DproxyHost=${maven.proxy.host}"/>
<jvmarg value="-DproxyPort=${maven.proxy.port}"/>
<jvmarg value="-Dhttp.proxyHost=${maven.proxy.host}"/>
<jvmarg value="-Dhttp.proxyPort=${maven.proxy.port}"/>
<jvmarg value="-Dhttp.proxyUser=${maven.proxy.username}"/>
<jvmarg value="-Dhttp.proxyPassword=${maven.proxy.password}"/>
<jvmarg value="-Dhttps.proxyHost=${maven.proxy.host}"/>
<jvmarg value="-Dhttps.proxyPort=${maven.proxy.port}"/>
<jvmarg value="-Dftp.proxyHost=${maven.proxy.host}"/>
<jvmarg value="-Dftp.proxyPort=${maven.proxy.port}"/>
</j:if>
<arg value="-c"/>
<arg value="${internal_pdf_workingDir}/userconfig.xml"/>
<j:if test="${maven.pdf.debug}">
<arg value="-d"/>
</j:if>
<arg value="-fo"/>
<arg value="${internal_pdf_workingDir}/project.fo"/>
<arg value="-pdf"/>
<arg value="${internal_pdf_workingDir}/${maven.pdf.pdfName}"/>
<sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="org.apache.xerces.jaxp.DocumentBuilderFactoryImp"/>
<sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<sysproperty key="java.endorsed.dirs" path="${java.home}/lib/endorsed;${maven.home}/lib/endorsed}"/>
<classpath>
<pathelement location="${plugin.getDependencyPath('fop')}"/>
<pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
<pathelement location="${plugin.getDependencyPath('xml-resolver:xml-resolver')}"/>
<pathelement location="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
<pathelement location="${plugin.getDependencyPath('xalan')}"/>
<pathelement location="${plugin.getDependencyPath('batik')}"/>
<pathelement location="${plugin.getDependencyPath('avalon-framework')}"/>
<pathelement location="${maven.jar.jimi}"/>
<pathelement location="${maven.jar.jaicore}"/>
<pathelement location="${maven.jar.jaicodec}"/>
</classpath>
</java>
<copy todir="${maven.xdoc.dest}" file="${internal_pdf_workingDir}/${maven.pdf.pdfName}"/>
</goal>
<goal name="pdf:navigation-validate"
description="Validates the pdf navigation file"
prereqs="pdf:init">
<available
file="${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile}"
property="navigationFile.available"/>
<j:if test="${navigationFile.available}">
<maven:get plugin="maven-xdoc-plugin" property="plugin" var="installedPlugin" />
<maven:get plugin="maven-xdoc-plugin" property="plugin.resources" var="plugin.resources" />
<!-- Remove SNAPSHOT -->
<j:choose>
<j:when test="${installedPlugin.currentVersion.endsWith('-SNAPSHOT')}">
<j:set var="currentRelease" value="${installedPlugin.currentVersion.substring(0,installedPlugin.currentVersion.length()-9)}"/>
</j:when>
<j:otherwise>
<j:set var="currentRelease" value="${installedPlugin.currentVersion}"/>
</j:otherwise>
</j:choose>
<plugin:validate-xml
schema="${plugin.resources}/xsd/maven-navigation-${currentRelease}.xsd"
file="${maven.pdf.navigationFilePath}/${maven.pdf.navigationFile}"/>
</j:if>
</goal>
</project>