You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2009/05/17 15:55:53 UTC

svn commit: r775652 - in /maven/plugins/trunk/maven-pdf-plugin/src: main/java/org/apache/maven/plugins/pdf/ site/apt/examples/ test/java/org/apache/maven/plugins/pdf/ test/resources/unit/pdf/src/site/

Author: vsiveton
Date: Sun May 17 13:55:53 2009
New Revision: 775652

URL: http://svn.apache.org/viewvc?rev=775652&view=rev
Log:
o added date support for interpolation
o updated test case and doc

Modified:
    maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
    maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml

Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=775652&r1=775651&r2=775652&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java Sun May 17 13:55:53 2009
@@ -24,13 +24,16 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.Writer;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+import java.util.TimeZone;
 
 import org.apache.maven.doxia.docrenderer.DocumentRenderer;
 import org.apache.maven.doxia.docrenderer.DocumentRendererException;
@@ -481,6 +484,8 @@
                     return null;
                 }
             } );
+            final DateBean bean = new DateBean();
+            interpolator.addValueSource( new ObjectBasedValueSource( bean ) );
 
             reader = ReaderFactory.newXmlReader( docDescriptor );
 
@@ -509,4 +514,100 @@
             IOUtil.close( reader );
         }
     }
+
+    /**
+     * Simple bean to allow date interpolation in the document descriptor, i.e.
+     * <pre>
+     * ${year}  = 2009
+     * ${date}  = 2009-05-17
+     * </pre>
+     */
+    public static class DateBean
+    {
+        private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
+
+        /**
+         * @return the current year.
+         */
+        public String getYear()
+        {
+            return new SimpleDateFormat( "yyyy", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current month.
+         */
+        public String getMonth()
+        {
+            return new SimpleDateFormat( "MM", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current day.
+         */
+        public String getDay()
+        {
+            return new SimpleDateFormat( "dd", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current hour.
+         */
+        public String getHour()
+        {
+            return new SimpleDateFormat( "HH", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current minute.
+         */
+        public String getMinute()
+        {
+            return new SimpleDateFormat( "mm", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current second.
+         */
+        public String getSecond()
+        {
+            return new SimpleDateFormat( "ss", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current millisecond.
+         */
+        public String getMillisecond()
+        {
+            return new SimpleDateFormat( "SSS", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current date using the ISO 8601 format, i.e. <code>yyyy-MM-dd</code>.
+         */
+        public String getDate()
+        {
+            return new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).format( new Date() );
+        }
+
+        /**
+         * @return the current time using the ISO 8601 format and UTC time zone, i.e. <code>HH:mm:ss'Z'</code>.
+         */
+        public String getTime()
+        {
+            SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss'Z'", Locale.US );
+            sdf.setTimeZone( UTC_TIME_ZONE );
+            return sdf.format( new Date() );
+        }
+
+        /**
+         * @return the current datetime using the ISO 8601 format, i.e. <code>yyyy-MM-dd'T'HH:mm:ss'Z'</code>.
+         */
+        public String getDateTime()
+        {
+            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US );
+            sdf.setTimeZone( UTC_TIME_ZONE );
+            return sdf.format( new Date() );
+        }
+    }
 }

Modified: maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt?rev=775652&r1=775651&r2=775652&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/site/apt/examples/filtering.apt Sun May 17 13:55:53 2009
@@ -3,7 +3,7 @@
  ------
  Vincent Siveton
  ------
- 2009-05-16
+ 2009-05-17
  ------
 
 ~~ Licensed to the Apache Software Foundation (ASF) under one
@@ -28,7 +28,24 @@
 
 Filtering Document Descriptor
 
-  The document descriptor (aka src/site/pdf.xml) could be filtered by System properties or POM properties.
+  The document descriptor (aka src/site/pdf.xml) could be filtered by System properties, Maven project properties and
+  some date properties.
+
+*----------------------------------+--------------+
+|| Expression Samples              || Description
+*----------------------------------+--------------+
+| $\{JAVA_HOME\}                   | The JAVA_HOME environment value.
+*----------------------------------+--------------+
+| $\{project.name\}                | The project name defined in \<name/\> tag in the pom.xml.
+*----------------------------------+--------------+
+| $\{project.developers[0].email\} | The email of the first developed defined in \<developers/\> tag in the pom.xml.
+*----------------------------------+--------------+
+| $\{date} $\{time\} $\{dateTime\} | The current date/time/dateTime displayed in ISO-8601 format, i.e. yyyy-MM-dd.
+*----------------------------------+--------------+
+| $\{year} $\{month\} $\{hour\}... | The single date or time informations.
+*----------------------------------+--------------+
+
+Example
 
   For instance, if you have defined the following pom.xml and pdf.xml:
 

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java?rev=775652&r1=775651&r2=775652&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java Sun May 17 13:55:53 2009
@@ -140,6 +140,8 @@
         }
         // ${project.developers[0].email}
         assertTrue( foContent.indexOf( "vsiveton@apache.org ltheussl@apache.org" ) > 0 );
+        // ${date}
+        assertTrue( foContent.indexOf( new PdfMojo.DateBean().getDate() ) > 0 );
     }
 
 }
\ No newline at end of file

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml?rev=775652&r1=775651&r2=775652&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/src/site/pdf_filtering.xml Sun May 17 13:55:53 2009
@@ -27,7 +27,7 @@
   outputName="maven-pdf-plugin-doc-${project.version}">
 
   <meta>
-    <title>User guide in ${pdf.language} of ${pom.name} version ${pom.version} for ${M2_HOME}</title>
+    <title>User guide in ${pdf.language} of ${pom.name} version ${pom.version} for ${M2_HOME} ${date}</title>
     <author>${project.developers[0].email} ${project.developers[1].email}</author>
   </meta>