maven pdf插件:以pdf显示当地时间

时间:2013-01-19 19:38:08

标签: maven maven-2 timezone maven-pdf-plugin

我正在使用maven 2.2.1和maven-pdf-plugin在“mvn site”期间生成我的万无一失的报告的PDF版本。

我想在PDF本身中显示报告(即PDF)生成时间戳,但是在我的本地时区,而不是UTC。我当地的时区是UTC +5:30(IST)。

这是我的pom.xml中build / plugins部分的一个片段:

<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>

这是我的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>

PDF正在生成。问题是我希望coverdate显示在我当地的时区。我已经尝试了Maven PDF plugin page中提到的一些日期/时间选项,例如:

<coverdate>${dateTime}</coverdate>

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

但结果时间戳始终为UTC。

我也尝试了一些像<coverdate>${dateTime+5:30}</coverdate>这样的尝试,但这不起作用。

我尝试在${maven.build.timestamp}中插入coverdate(如果在我的pom中使用的话确实在我当地时间),但在生成PDF时不会插入。

如何获取当地时区的时间戳?我甚至不需要<cover></cover>部分;如果我能以某种方式在PDF中获得构建时间戳,我可以完全摆脱它。

1 个答案:

答案 0 :(得分:0)

我找到了一种迂回的方法来实现这一目标。

我将时区特定的时间戳放在我的pom的描述标签中,如下所示:

<description>${maven.build.timestamp}</description>

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

现在我可以告诉pdf插件将其插入封面日期。我的pdf.xml有这个:

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

我现在可以在PDF封面上按照我想要的格式在当地时间获得所需的时间戳。

不可否认,将时间戳插入到pom的description标签中并不是那么好,但由于我没有将description标签用于其他任何内容,我可以忍受。

不幸的是,我无法访问pdf.xml中的任意$ {project.X}属性...只有少数属性如$ {project.name}和$ {project.description}似乎有效。