This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch feature/lastmodified in repository https://gitbox.apache.org/repos/asf/maven-fluido-skin.git
commit 702d79ba623bd523a588e85a5133e3adaed21b78 Author: Konrad Windszus <[email protected]> AuthorDate: Fri Mar 20 17:31:42 2026 +0100 Support exposing SCM last modified date (instead of publish date) --- pom.xml | 62 ++++++++++++++- src/main/resources/META-INF/maven/site-macros.vm | 12 +-- .../maven/skins/fluido/ScmLastModifiedIT.java | 90 ++++++++++++++++++++++ src/test/resources/modificationDate/pom.xml | 72 +++++++++++++++++ .../modificationDate/src/site/apt/index.apt.vm | 36 +++++++++ .../resources/modificationDate/src/site/site.xml | 42 ++++++++++ src/test/resources/modificationDate/verify.groovy | 22 ++++++ 7 files changed, 328 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1dc5a48..49427ec 100644 --- a/pom.xml +++ b/pom.xml @@ -99,15 +99,53 @@ under the License. <anchorjs.version>4.3.1</anchorjs.version> <bootstrap.version>2.3.2</bootstrap.version> <jquery.version>1.11.2</jquery.version> - <version.maven-site-plugin>3.21.0</version.maven-site-plugin> + <version.maven-site-plugin>4.0.0-M17-SNAPSHOT</version.maven-site-plugin> <project.build.outputTimestamp>2025-03-08T23:27:09Z</project.build.outputTimestamp> <!-- the following properties are used in ITs (which do not inherit anything from a common parent) --> <sitePluginVersion>${version.maven-site-plugin}</sitePluginVersion> <projectInfoReportsPluginVersion>3.8.0</projectInfoReportsPluginVersion> <version.maven-invoker-plugin>3.9.1</version.maven-invoker-plugin> + <version.maven-api>3.9.13</version.maven-api> </properties> + <dependencies> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-invoker</artifactId> + <version>3.3.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${version.maven-api}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>${version.maven-api}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>${version.maven-api}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-xml</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> <resources> <resource> @@ -237,7 +275,6 @@ under the License. </plugin> </plugins> </build> - <profiles> <profile> <id>run-its</id> @@ -252,7 +289,6 @@ under the License. <configuration> <debug>true</debug> <projectsDirectory>src/it</projectsDirectory> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> <preBuildHookScript>setup</preBuildHookScript> <postBuildHookScript>verify</postBuildHookScript> <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> @@ -280,6 +316,26 @@ under the License. </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemPropertyVariables> + <!-- pass maven.home property to maven-verifier --> + <maven.home>${maven.home}</maven.home> + <skin.version>${project.version}</skin.version> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> </plugins> </build> </profile> diff --git a/src/main/resources/META-INF/maven/site-macros.vm b/src/main/resources/META-INF/maven/site-macros.vm index ef880af..ce55f51 100644 --- a/src/main/resources/META-INF/maven/site-macros.vm +++ b/src/main/resources/META-INF/maven/site-macros.vm @@ -280,8 +280,10 @@ $indent </ul>## #end ## #macro( publishDate $position $sitePublishDate $version ) -#**##if( $publishDate ) -#* *##set( $dateValue = $date.format( $publishDate ) ) +## Retrieve the relevant date to display (despite the macro name not always publish date) +#**##set( $documentDate = $context.get($sitePublishDate.value) ) +#**##if( $documentDate ) +#* *##set( $dateValue = $date.format( $documentDate ) ) #**##else #* *##set( $dateValue = $date ) #**##end @@ -303,7 +305,7 @@ $indent </ul>## #**##if( $datePosition.equalsIgnoreCase( $position ) ) #* *##if( $datePosition.equalsIgnoreCase( "right" ) || $datePosition.equalsIgnoreCase( "bottom" ) ) ## FIXME In some languages like French a space must preceed the colon - <li id="publishDate" class="pull-right">$prefix$text.get( "template.lastpublished" ): $dateValue</li> + <li id="publishDate" class="pull-right">$prefix$text.get( $sitePublishDate.prefix ): $dateValue</li> #* *##if( $versionPosition.equalsIgnoreCase( $position ) ) <li id="projectVersion" class="pull-right">## #* *##if( !$topBarEnabled @@ -318,7 +320,7 @@ $indent </ul>## #* *##elseif( $datePosition.equalsIgnoreCase( "navigation-bottom" ) || $datePosition.equalsIgnoreCase( "navigation-top" ) ) <div id="lastPublished"> ## FIXME In some languages like French a space must preceed the colon - <span id="publishDate">$text.get( "template.lastpublished" ): $dateValue</span> + <span id="publishDate">$text.get( $sitePublishDate.prefix ): $dateValue</span> #* *##if( $versionPosition.equalsIgnoreCase( $position ) ) ## FIXME In some languages like French a space must preceed the colon <span class="divider">|</span> <span id="projectVersion">$text.get( "template.version" ): ${project.version}</span> @@ -326,7 +328,7 @@ $indent </ul>## </div> #* *##elseif( $datePosition.equalsIgnoreCase("left") ) ## FIXME In some languages like French a space must preceed the colon - <li id="publishDate">$text.get( "template.lastpublished" ): $dateValue## + <li id="publishDate">$text.get( $sitePublishDate.prefix ): $dateValue## #* *##if( $versionPosition.equalsIgnoreCase( $position ) || $breadcrumbs && $breadcrumbs.size() > 0 ) #* *#<span class="divider">|</span> #* *##end diff --git a/src/test/java/org/apache/maven/skins/fluido/ScmLastModifiedIT.java b/src/test/java/org/apache/maven/skins/fluido/ScmLastModifiedIT.java new file mode 100644 index 0000000..9d7025e --- /dev/null +++ b/src/test/java/org/apache/maven/skins/fluido/ScmLastModifiedIT.java @@ -0,0 +1,90 @@ +/* + * 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. + */ +package org.apache.maven.skins.fluido; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.shared.invoker.DefaultInvocationRequest; +import org.apache.maven.shared.invoker.DefaultInvoker; +import org.apache.maven.shared.invoker.InvocationRequest; +import org.apache.maven.shared.invoker.InvocationResult; +import org.apache.maven.shared.invoker.Invoker; +import org.apache.maven.shared.invoker.MavenInvocationException; +import org.apache.maven.shared.invoker.SystemOutLogger; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.jupiter.api.Test; + +/** + * Cannot use maven-invoker-plugin for this test because it needs to be run in a SCM repository + * and the invoker always clones the project into target (see <a href="https://github.com/apache/maven-invoker-plugin/issues/712">m-invoker-plugin issue #712</a>). + */ +class ScmLastModifiedIT { + + @Test + void test() throws MavenInvocationException { + InvocationRequest request = new DefaultInvocationRequest(); + request.setPomFile(new File("src/test/resources/modificationDate")); + configure(request); + Invoker invoker = new DefaultInvoker(); + request.addArgs(Arrays.asList("clean", "site")); + //request.addArg("-X"); + invoker.setLogger(new SystemOutLogger()); + InvocationResult result = invoker.execute(request); + if (result.getExitCode() != 0) { + throw new IllegalStateException("Build failed.", result.getExecutionException()); + } + // fail("Not yet implemented"); + } + + /** + * Retrieves the version of the fluido-skin. The version is used in the + * test poms so that the cli build uses the current plugin. Usually the version is set via the system property + * {@code plugin.version} via the failsafe plugin. If the property is missing the method tries to read it from the + * {@code pom.xml} of the project. This is useful when running the tests in an IDE. + * + * @return the version of the current {@code filevault-package-maven-plugin} + * @throws IllegalArgumentException if the version cannot be determined. + */ + public static String getSkinArtifactVersion() { + String pluginVersion = System.getProperty("skin.version"); + if (pluginVersion == null) { + try (FileReader fileReader = new FileReader("pom.xml")) { + // try to read from project + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(fileReader); + pluginVersion = model.getVersion(); + } catch (IOException | XmlPullParserException e) { + System.err.println("Unable to read skin version from pom.xml" + e.getMessage()); + } + } + if (pluginVersion == null) { + throw new IllegalArgumentException("Unable to detect skin version"); + } + return pluginVersion; + } + + private static void configure(InvocationRequest request) { + request.addArg("-DskinVersion=\"" + getSkinArtifactVersion() + "\""); + } +} diff --git a/src/test/resources/modificationDate/pom.xml b/src/test/resources/modificationDate/pom.xml new file mode 100644 index 0000000..9c6e0ad --- /dev/null +++ b/src/test/resources/modificationDate/pom.xml @@ -0,0 +1,72 @@ +<?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> + <parent> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-skins</artifactId> + <version>46</version> + </parent> + + <groupId>org.apache.maven.skins.its</groupId> + <artifactId>fluido-modification-date-it</artifactId> + <version>1.0.0-SNAPSHOT</version> + + <name>IT, Verify rendering of modification date</name> + <url>https://maven.apache.org/skins/fluido-modification-date-it/modificationDate/</url> + + <properties> + <!-- START SNIPPET: skin-custom-config --> + <project.build.outputTimestamp>1990-01-01T00:00:00Z</project.build.outputTimestamp> + <!-- END SNIPPET: skin-custom-config --> + <doxiaSitetoolsVersion>2.1.0-SNAPSHOT</doxiaSitetoolsVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-site-model</artifactId> + <version>${doxiaSitetoolsVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-site-renderer</artifactId> + <version>${doxiaSitetoolsVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-integration-tools</artifactId> + <version>${doxiaSitetoolsVersion}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.doxia</groupId> + <artifactId>doxia-site-scm-context</artifactId> + <version>${doxiaSitetoolsVersion}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + +</project> diff --git a/src/test/resources/modificationDate/src/site/apt/index.apt.vm b/src/test/resources/modificationDate/src/site/apt/index.apt.vm new file mode 100644 index 0000000..468d7ae --- /dev/null +++ b/src/test/resources/modificationDate/src/site/apt/index.apt.vm @@ -0,0 +1,36 @@ + ------ + ${project.name} + ------ + Hervé Boutemy + ------ + 2011-10-15 + ------ + +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + +${project.name} - ${scmModifiedDate} + + This is a test for ${skinName} with sidebar enabled and Google Search. + ${skinDescription} + +* Actual configuration + +%{snippet|id=skin-custom-config|file=${project.basedir}/pom.xml} diff --git a/src/test/resources/modificationDate/src/site/site.xml b/src/test/resources/modificationDate/src/site/site.xml new file mode 100644 index 0000000..bf44a0f --- /dev/null +++ b/src/test/resources/modificationDate/src/site/site.xml @@ -0,0 +1,42 @@ +<?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. + */ + --> + +<site xmlns="http://maven.apache.org/SITE/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/SITE/2.1.0 https://maven.apache.org/xsd/site-2.1.0.xsd" + name="${skinName}"> + + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>2.1.1-SNAPSHOT</version> + </skin> + + <publishDate format="yyyy-MM-dd" position="right" value="scmModifiedDate" prefix="template.lastmodified"/> + + <body> + <breadcrumbs> + <item name="Apache Maven Fluido Skin" href="https://maven.apache.org/skins/maven-fluido-skin/index.html" /> + <item name="Maven Fluido Skin ITs" href="https://maven.apache.org/skins/maven-fluido-skin/ITs.html" /> + </breadcrumbs> + </body> +</site> diff --git a/src/test/resources/modificationDate/verify.groovy b/src/test/resources/modificationDate/verify.groovy new file mode 100644 index 0000000..5eef511 --- /dev/null +++ b/src/test/resources/modificationDate/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ + +File index = new File( basedir, "target/site/index.html" ) +assert index.exists() +assert index.text.contains( '<li id="publishDate" class="pull-right"><span class="divider">|</span> Last Modified: 1990-01-01</li>' )
