mavenmaven-2timezonemaven-pdf-plugin

maven pdf plugin: show local time in pdf


I am using maven 2.2.1 and the maven-pdf-plugin to generate a PDF version of my surefire report during "mvn site".

I want to display the report (i.e. PDF) generation timestamp in the PDF itself, but in my local timezone, not in UTC. My local timezone is UTC +5:30 (IST).

Here's a snippet from the build/plugins section in my pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pdf-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <id>pdf</id>
            <phase>site</phase>
            <goals>
                <goal>pdf</goal>
            </goals>
            <configuration>
                <aggregate>true</aggregate>
                <generateTOC>none</generateTOC>
                <outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Here's my pdf.xml:

<document xmlns="http://maven.apache.org/DOCUMENT/1.0.1"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/DOCUMENT/1.0.1 http://maven.apache.org/xsd/document-1.0.1.xsd"
          outputName="${artifactId}_surefire-report">

    <meta>
        <title>${artifactId} - Surefire Report</title>
        <author>QA Team</author>
    </meta>

    <toc></toc>

    <cover>
        <coverTitle>TNT:${artifactId}</coverTitle>
        <coverdate>${dateTime}</coverdate>
        <coverSubTitle>Surefire Test Report</coverSubTitle>
        <projectName>${project.name}</projectName>
    </cover>
</document>

The PDF is generating fine. The problem is I want the coverdate to be displayed in my local timezone. I've tried some of the date/time options mentioned on the Maven PDF plugin page, such as:

<coverdate>${dateTime}</coverdate>

and

<coverdate>${day}/${month}/${year} - ${hour}:${minute}:${second}</coverdate>

but the resultant timestamp is always UTC.

I also tried a few attempts like <coverdate>${dateTime+5:30}</coverdate> but this doesn't work.

I tried to insert ${maven.build.timestamp} (which if used in my pom is indeed in my local time) in coverdate but this doesn't get interpolated when the PDF is generated.

How can I get the timestamp in my local time zone? I don't even need the <cover></cover> section; I can get rid of it altogether if I can somehow get a build timestamp into the PDF.


Solution

  • I found a roundabout way to accomplish this.

    I put my timezone-specific timestamp in my pom's description tag like this:

    <description>${maven.build.timestamp}</description>
    
    <properties>
        <maven.build.timestamp.format>E dd-MMM-yyyy HH:mm z</maven.build.timestamp.format>
    </properties>
    

    Now I can tell the pdf plugin to insert this into the coverdate. My pdf.xml has this:

    <cover>
        <coverTitle>My Cover Title</coverTitle>
        <coverdate>${project.description}</coverdate>
    ...
    </cover>
    

    I now get the desired timestamp, in my local time, formatted as I want, on the PDF cover.

    Admittedly, it's not so great to insert the timestamp into the description tag of the pom, but since I don't use the description tag for anything else, I can live with that.

    Unfortunately, I can't access arbitrary ${project.X} properties in the pdf.xml... only a few properties like ${project.name} and ${project.description} seem to work.