You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/04/06 22:18:35 UTC

[maven-site-plugin] 01/03: [MSITE-941] sitemap.xml is overwritten when multiple locales are defined

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

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

commit 8ced42b19a1b3db59a7c54b337be3adca112b0f7
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Apr 6 22:49:29 2023 +0200

    [MSITE-941] sitemap.xml is overwritten when multiple locales are defined
---
 src/it/projects/MSITE-856/pom.xml                  |  1 +
 src/it/projects/MSITE-856/src/site/site_de.xml     | 36 ++++++++++++++++++++++
 src/it/projects/MSITE-856/verify.bsh               | 29 ++++++++++++++---
 .../apache/maven/plugins/site/render/SiteMap.java  | 12 ++++++--
 4 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/src/it/projects/MSITE-856/pom.xml b/src/it/projects/MSITE-856/pom.xml
index de20b4d6..a66c8158 100644
--- a/src/it/projects/MSITE-856/pom.xml
+++ b/src/it/projects/MSITE-856/pom.xml
@@ -41,6 +41,7 @@ under the License.
           <version>@project.version@</version>
           <configuration>
             <generateSitemap>true</generateSitemap>
+            <locales>default,de</locales>
           </configuration>
         </plugin>
       </plugins>
diff --git a/src/it/projects/MSITE-856/src/site/site_de.xml b/src/it/projects/MSITE-856/src/site/site_de.xml
new file mode 100644
index 00000000..783290f0
--- /dev/null
+++ b/src/it/projects/MSITE-856/src/site/site_de.xml
@@ -0,0 +1,36 @@
+<?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/DECORATION/1.6.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/DECORATION/1.6.0 http://maven.apache.org/xsd/decoration-1.6.0.xsd">
+  <skin>
+    <groupId>org.apache.maven.skins</groupId>
+    <artifactId>maven-fluido-skin</artifactId>
+    <version>${fluidoSkinVersion}</version>
+  </skin>
+
+  <body>
+    <menu name="Mein MenĂ¼">
+      <item name="Mein erstes Element"/>
+    </menu>
+  </body>
+</project>
diff --git a/src/it/projects/MSITE-856/verify.bsh b/src/it/projects/MSITE-856/verify.bsh
index 802eae94..5e14f23f 100644
--- a/src/it/projects/MSITE-856/verify.bsh
+++ b/src/it/projects/MSITE-856/verify.bsh
@@ -22,19 +22,40 @@ import org.codehaus.plexus.util.*;
 
 try
 {
-    final File siteDirectory = new File( basedir, "target/generated-site" );
-    if ( !siteDirectory.exists() || !siteDirectory.isDirectory() )
+    final File generatedSiteDirectory = new File( basedir, "target/generated-site" );
+    if ( !generatedSiteDirectory.isDirectory() )
     {
         System.err.println( "generated-site is missing or not a directory." );
         return false;
     }
 
-    File index = new File( siteDirectory, "xdoc/sitemap.xml" );
-    if ( !index.exists() || index.isDirectory() )
+    File sitemapXdocFile = new File( generatedSiteDirectory, "xdoc/sitemap.xml" );
+    if ( !sitemapXdocFile.isFile() )
     {
         System.err.println( "no sitemap.xml!" );
         return false;
     }
+
+    String content = FileUtils.fileRead( sitemapXdocFile, "UTF-8" );
+    if ( !content.contains( "<li>My first item</li>" ) )
+    {
+        System.err.println( "\"<li>My first item</li>\" not found in sitemap.xml!" );
+        return false;
+    }
+
+    File sitemapGermanXdocFile = new File( generatedSiteDirectory, "de/xdoc/sitemap.xml" );
+    if ( !sitemapGermanXdocFile.isFile() )
+    {
+        System.err.println( "no German sitemap.xml!" );
+        return false;
+    }
+
+    content = FileUtils.fileRead( sitemapGermanXdocFile, "UTF-8" );
+    if ( !content.contains( "<li>Mein erstes Element</li>" ) )
+    {
+        System.err.println( "\"<li>Mein erstes Element</li>\" not found in German sitemap.xml!" );
+        return false;
+    }
 }
 catch ( IOException e )
 {
diff --git a/src/main/java/org/apache/maven/plugins/site/render/SiteMap.java b/src/main/java/org/apache/maven/plugins/site/render/SiteMap.java
index adeacb1f..afcce6bd 100644
--- a/src/main/java/org/apache/maven/plugins/site/render/SiteMap.java
+++ b/src/main/java/org/apache/maven/plugins/site/render/SiteMap.java
@@ -28,6 +28,7 @@ import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.site.Menu;
 import org.apache.maven.doxia.site.MenuItem;
 import org.apache.maven.doxia.site.SiteModel;
+import org.apache.maven.doxia.tools.SiteTool;
 import org.codehaus.plexus.i18n.I18N;
 
 /**
@@ -90,18 +91,23 @@ public class SiteMap {
     }
 
     /**
-     * Generates a sitemap.xml in targetDir/xdoc/.
+     * Generates a sitemap.xml in targetDir/(locale/)?xdoc/.
      * This is a valid xdoc document that can be processed by a Doxia parser.
      * The file lists all the menus and menu items of the SiteModel in expanded form.
      *
      * @param siteModel the SiteModel to extract the menus from.
-     * @param targetDir the target output directory. The file will be created in targetDir/xdoc/.
+     * @param targetDir the target output directory. The file will be created in targetDir/(locale/)?xdoc/.
      * @param locale the Locale for the result.
      *
      * @throws IOException if the file cannot be ceated.
      */
     public void generate(SiteModel siteModel, File targetDir, Locale locale) throws IOException {
-        File outputDir = new File(targetDir, "xdoc");
+        File outputDir;
+        if (!locale.equals(SiteTool.DEFAULT_LOCALE)) {
+            outputDir = new File(new File(targetDir, locale.toString()), "xdoc");
+        } else {
+            outputDir = new File(targetDir, "xdoc");
+        }
         Sink sink = new XdocSinkFactory().createSink(outputDir, "sitemap.xml", encoding);
 
         try {