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

michaelo pushed a commit to branch DOXIASITETOOLS-257
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git

commit ab961430ee7969535511e3b5525b0eae00c04995
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Sat Jun 11 21:37:38 2022 +0200

    [DOXIASITETOOLS-257] Require a skin if a site descriptor (site.xml) has 
been provided
    
    This closes #47
---
 doxia-decoration-model/src/main/mdo/decoration.mdo | 22 +-----
 .../apache/maven/doxia/tools/DefaultSiteTool.java  | 78 +++++++++++-----------
 .../src/main/resources/default-site.xml            |  5 ++
 3 files changed, 45 insertions(+), 60 deletions(-)

diff --git a/doxia-decoration-model/src/main/mdo/decoration.mdo 
b/doxia-decoration-model/src/main/mdo/decoration.mdo
index 752a9b5..691a953 100644
--- a/doxia-decoration-model/src/main/mdo/decoration.mdo
+++ b/doxia-decoration-model/src/main/mdo/decoration.mdo
@@ -127,7 +127,7 @@ under the License.
           <name>edit</name>
           <description><![CDATA[
             The base url to edit Doxia document sources.
-            In general, <code>${project.scm.url}</code> value should do the 
job. 
+            In general, <code>${project.scm.url}</code> value should do the 
job.
           ]]></description>
           <version>1.8.0+</version>
           <type>String</type>
@@ -759,26 +759,6 @@ under the License.
           <identifier>true</identifier>
         </field>
       </fields>
-      <codeSegments>
-        <codeSegment>
-          <version>1.0.0+</version>
-          <code>
-            <![CDATA[
-    /**
-     * @return the default skin 
<code>org.apache.maven.skins:maven-default-skin:1.3</code>.
-     */
-    public static Skin getDefaultSkin()
-    {
-        Skin skin = new Skin();
-        skin.setGroupId( "org.apache.maven.skins" );
-        skin.setArtifactId( "maven-default-skin" );
-        skin.setVersion( "1.3" );
-        return skin;
-    }
-            ]]>
-          </code>
-        </codeSegment>
-      </codeSegments>
     </class>
   </classes>
 </model>
diff --git 
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
 
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
index c51c1d7..6bbf388 100644
--- 
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
+++ 
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
@@ -138,13 +138,7 @@ public class DefaultSiteTool
         Objects.requireNonNull( localRepository, "localRepository cannot be 
null" );
         Objects.requireNonNull( remoteArtifactRepositories, 
"remoteArtifactRepositories cannot be null" );
         Objects.requireNonNull( decoration, "decoration cannot be null" );
-
-        Skin skin = decoration.getSkin();
-
-        if ( skin == null )
-        {
-            skin = Skin.getDefaultSkin();
-        }
+        Skin skin = Objects.requireNonNull( decoration.getSkin(), 
"decoration.skin cannot be null" );
 
         String version = skin.getVersion();
         Artifact artifact;
@@ -180,7 +174,8 @@ public class DefaultSiteTool
                                             List<ArtifactRepository> 
remoteArtifactRepositories )
         throws SiteToolException
     {
-        return getSkinArtifactFromRepository( localRepository, 
remoteArtifactRepositories, new DecorationModel() );
+        DecorationModel decorationModel = getDefaultDecorationModel();
+        return getSkinArtifactFromRepository( localRepository, 
remoteArtifactRepositories, decorationModel );
     }
 
     /**
@@ -424,26 +419,7 @@ public class DefaultSiteTool
         if ( decorationModel == null )
         {
             LOGGER.debug( "Using default site descriptor" );
-
-            String siteDescriptorContent;
-
-            Reader reader = null;
-            try
-            {
-                // Note the default is not a super class - it is used when 
nothing else is found
-                reader = ReaderFactory.newXmlReader( 
getClass().getResourceAsStream( "/default-site.xml" ) );
-                siteDescriptorContent = IOUtil.toString( reader );
-            }
-            catch ( IOException e )
-            {
-                throw new SiteToolException( "Error reading default site 
descriptor", e );
-            }
-            finally
-            {
-                IOUtil.close( reader );
-            }
-
-            decorationModel = readDecorationModel( siteDescriptorContent );
+            decorationModel = getDefaultDecorationModel();
         }
 
         // DecorationModel back to String to interpolate, then go back to 
DecorationModel
@@ -1043,7 +1019,7 @@ public class DefaultSiteTool
         }
 
         // 2. read DecorationModel from site descriptor File and do early 
interpolation (${this.*})
-        DecorationModel decoration = null;
+        DecorationModel decorationModel = null;
         Reader siteDescriptorReader = null;
         try
         {
@@ -1059,8 +1035,8 @@ public class DefaultSiteTool
                 // interpolate ${this.*} = early interpolation
                 siteDescriptorContent = getInterpolatedSiteDescriptorContent( 
project, siteDescriptorContent, true );
 
-                decoration = readDecorationModel( siteDescriptorContent );
-                decoration.setLastModified( siteDescriptor.lastModified() );
+                decorationModel = readDecorationModel( siteDescriptorContent );
+                decorationModel.setLastModified( siteDescriptor.lastModified() 
);
             }
             else
             {
@@ -1081,7 +1057,7 @@ public class DefaultSiteTool
         MavenProject parentProject = getParentProject( project, 
reactorProjects, localRepository );
 
         // 4. merge with parent project DecorationModel
-        if ( parentProject != null && ( decoration == null || 
decoration.isMergeParent() ) )
+        if ( parentProject != null && ( decorationModel == null || 
decorationModel.isMergeParent() ) )
         {
             depth++;
             LOGGER.debug( "Looking for site descriptor of level " + depth + " 
parent project: "
@@ -1099,22 +1075,23 @@ public class DefaultSiteTool
                 // has different configuration. But this is a rare case (this 
only has impact if parent is from reactor)
             }
 
-            DecorationModel parentDecoration =
+            DecorationModel parentDecorationModel =
                 getDecorationModel( depth, parentSiteDirectory, locale, 
parentProject, reactorProjects, localRepository,
                                     repositories ).getKey();
 
             // MSHARED-116 requires an empty decoration model (instead of a 
null one)
             // MSHARED-145 requires us to do this only if there is a parent to 
merge it with
-            if ( decoration == null && parentDecoration != null )
+            if ( decorationModel == null && parentDecorationModel != null )
             {
                 // we have no site descriptor: merge the parent into an empty 
one
-                decoration = new DecorationModel();
+                LOGGER.debug( "Using default site descriptor" );
+                decorationModel = getDefaultDecorationModel();
             }
 
             String name = project.getName();
-            if ( decoration != null && StringUtils.isNotEmpty( 
decoration.getName() ) )
+            if ( decorationModel != null && StringUtils.isNotEmpty( 
decorationModel.getName() ) )
             {
-                name = decoration.getName();
+                name = decorationModel.getName();
             }
 
             // Merge the parent and child DecorationModels
@@ -1126,11 +1103,11 @@ public class DefaultSiteTool
                     + " parent: distributionManagement.site.url child = " + 
projectDistMgmnt + " and parent = "
                     + parentDistMgmnt );
             }
-            assembler.assembleModelInheritance( name, decoration, 
parentDecoration, projectDistMgmnt,
+            assembler.assembleModelInheritance( name, decorationModel, 
parentDecorationModel, projectDistMgmnt,
                                                 parentDistMgmnt == null ? 
projectDistMgmnt : parentDistMgmnt );
         }
 
-        return new AbstractMap.SimpleEntry<DecorationModel, MavenProject>( 
decoration, parentProject );
+        return new AbstractMap.SimpleEntry<DecorationModel, MavenProject>( 
decorationModel, parentProject );
     }
 
     /**
@@ -1155,6 +1132,29 @@ public class DefaultSiteTool
         }
     }
 
+    private DecorationModel getDefaultDecorationModel()
+        throws SiteToolException
+    {
+        String siteDescriptorContent;
+
+        Reader reader = null;
+        try
+        {
+            reader = ReaderFactory.newXmlReader( 
getClass().getResourceAsStream( "/default-site.xml" ) );
+            siteDescriptorContent = IOUtil.toString( reader );
+        }
+        catch ( IOException e )
+        {
+            throw new SiteToolException( "Error reading default site 
descriptor", e );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+
+        return readDecorationModel( siteDescriptorContent );
+    }
+
     private String decorationModelToString( DecorationModel decoration )
         throws SiteToolException
     {
diff --git a/doxia-integration-tools/src/main/resources/default-site.xml 
b/doxia-integration-tools/src/main/resources/default-site.xml
index 5ba93bf..c04d78e 100644
--- a/doxia-integration-tools/src/main/resources/default-site.xml
+++ b/doxia-integration-tools/src/main/resources/default-site.xml
@@ -22,6 +22,11 @@ under the License.
   <bannerLeft>
     <name>${project.name}</name>
   </bannerLeft>
+  <skin>
+    <groupId>org.apache.maven.skins</groupId>
+    <artifactId>maven-default-skin</artifactId>
+    <version>1.3</version>
+  </skin>
   <body>
     <links>
       <item name="${project.name}" href="${project.url}"/>

Reply via email to