This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MSITE-921
in repository https://gitbox.apache.org/repos/asf/maven-site-plugin.git

commit c288465016b015fe08e3024718f24037045f2861
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Sun Jan 15 01:02:51 2023 +0100

    [MSITE-921] Populate SiteRenderingContext#getPublishDate() with 
${project.build.outputTimestamp}
    
    This closes #123
---
 src/it/projects/publishDate/pom.xml                | 64 ++++++++++++++++++++++
 src/it/projects/publishDate/verify.groovy          | 24 ++++++++
 .../site/render/AbstractSiteRenderingMojo.java     | 12 ++++
 3 files changed, 100 insertions(+)

diff --git a/src/it/projects/publishDate/pom.xml 
b/src/it/projects/publishDate/pom.xml
new file mode 100644
index 00000000..ee953711
--- /dev/null
+++ b/src/it/projects/publishDate/pom.xml
@@ -0,0 +1,64 @@
+<?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="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.site.its</groupId>
+  <artifactId>publishDate</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>maven-site-plugin IT: publish date</name>
+  <description>check that publish date is populated from 
'project.build.outputTimestamp'</description>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    
<projectInfoReportsPluginVersion>@projectInfoReportsPluginVersion@</projectInfoReportsPluginVersion>
+    
<project.build.outputTimestamp>2000-01-01T00:00:00Z</project.build.outputTimestamp>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <version>@projectInfoReportsPluginVersion@</version>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>index</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
diff --git a/src/it/projects/publishDate/verify.groovy 
b/src/it/projects/publishDate/verify.groovy
new file mode 100644
index 00000000..af6a09b0
--- /dev/null
+++ b/src/it/projects/publishDate/verify.groovy
@@ -0,0 +1,24 @@
+
+/*
+ * 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.
+ */
+
+sitedir = new File( basedir, 'target/site' );
+index = new File( sitedir, 'index.html' );
+assert index.exists();
+assert index.getText().contains( '<li id="publishDate">Last Published: 
2000-01-01' );
diff --git 
a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
 
b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
index 921ac25f..bb02ffe3 100644
--- 
a/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
@@ -19,6 +19,7 @@ package org.apache.maven.plugins.site.render;
  * under the License.
  */
 
+import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.Menu;
@@ -39,6 +40,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.site.descriptor.AbstractSiteDescriptorMojo;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.reporting.exec.MavenReportExecution;
 import org.apache.maven.reporting.exec.MavenReportExecutor;
@@ -50,6 +52,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -313,6 +316,15 @@ public abstract class AbstractSiteRenderingMojo extends 
AbstractSiteDescriptorMo
                 + e.getMessage(), e );
         }
 
+        // Add publish date
+        MavenProject p = attributes.get( "project" ) != null ? (MavenProject) 
attributes.get( "project" ) : project;
+        String outputTimestamp = p.getProperties().getProperty( 
"project.build.outputTimestamp" );
+        MavenArchiver.parseBuildOutputTimestamp( outputTimestamp ).ifPresent( 
v ->
+            {
+                context.setPublishDate( Date.from( v ) );
+            }
+        );
+
         // Generate static site
         context.setRootDirectory( project.getBasedir() );
         if ( !locale.equals( SiteTool.DEFAULT_LOCALE ) )

Reply via email to