Author: rfscholte
Date: Wed Dec 14 21:13:54 2011
New Revision: 1214470

URL: http://svn.apache.org/viewvc?rev=1214470&view=rev
Log:
Fix MSHARED-217: Separate inheritance and interpolation 

Added:
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/pom.xml
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/site.xml
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/
    
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/pom.xml
Modified:
    
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
    
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java

Modified: 
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=1214470&r1=1214469&r2=1214470&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
 (original)
+++ 
maven/shared/trunk/maven-doxia-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
 Wed Dec 14 21:13:54 2011
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.io.StringWriter;
 
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -54,6 +55,7 @@ import org.apache.maven.doxia.site.decor
 import org.apache.maven.doxia.site.decoration.Skin;
 import 
org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
+import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
 import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Site;
@@ -459,10 +461,9 @@ public class DefaultSiteTool
             getDecorationModel( project, parentProject, reactorProjects, 
localRepository, repositories, siteDirectory,
                                 llocale, props, inputEncoding, outputEncoding 
);
 
+        String siteDescriptorContent;
         if ( decorationModel == null )
         {
-            String siteDescriptorContent;
-
             try
             {
                 // Note the default is not a super class - it is used when 
nothing else is found
@@ -473,12 +474,24 @@ public class DefaultSiteTool
             {
                 throw new SiteToolException( "Error reading default site 
descriptor: " + e.getMessage(), e );
             }
-
-            siteDescriptorContent = getInterpolatedSiteDescriptorContent( 
props, project, siteDescriptorContent,
-                                                                          
inputEncoding, outputEncoding );
-
-            decorationModel = readDecorationModel( siteDescriptorContent );
         }
+        else
+        {
+            try
+            {
+                StringWriter writer = new StringWriter();
+                new DecorationXpp3Writer().write( writer, decorationModel );
+                siteDescriptorContent = writer.toString();
+            }
+            catch ( IOException e )
+            {
+                throw new SiteToolException( "The site descriptor cannot be 
parsed!", e );
+            }
+        }
+        
+        siteDescriptorContent = getInterpolatedSiteDescriptorContent( props, 
project, siteDescriptorContent,
+                                                                      
inputEncoding, outputEncoding );
+        decorationModel = readDecorationModel( siteDescriptorContent );
 
         if ( parentProject != null )
         {
@@ -1160,16 +1173,15 @@ public class DefaultSiteTool
             siteDescriptor = getSiteDescriptorFromBasedir( siteDirectory, 
project.getBasedir(), locale );
         }
 
-        String siteDescriptorContent = null;
-        long siteDescriptorLastModified = 0L;
+        DecorationModel decoration = null;
         try
         {
             if ( siteDescriptor != null && siteDescriptor.exists() )
             {
                 getLogger().debug( "Reading site descriptor from " + 
siteDescriptor );
                 Reader siteDescriptorReader = ReaderFactory.newXmlReader( 
siteDescriptor );
-                siteDescriptorContent = IOUtil.toString( siteDescriptorReader 
);
-                siteDescriptorLastModified = siteDescriptor.lastModified();
+                decoration = readDecorationModel( siteDescriptorReader );
+                decoration.setLastModified( siteDescriptor.lastModified() );
             }
         }
         catch ( IOException e )
@@ -1177,16 +1189,6 @@ public class DefaultSiteTool
             throw new SiteToolException( "The site descriptor cannot be 
read!", e );
         }
 
-        DecorationModel decoration = null;
-        if ( siteDescriptorContent != null )
-        {
-            siteDescriptorContent = getInterpolatedSiteDescriptorContent( 
props, project, siteDescriptorContent,
-                                                                          
inputEncoding, outputEncoding );
-
-            decoration = readDecorationModel( siteDescriptorContent );
-            decoration.setLastModified( siteDescriptorLastModified );
-        }
-
         if ( parentProject != null )
         {
             getLogger().debug( "Parent project loaded ..." );
@@ -1233,10 +1235,21 @@ public class DefaultSiteTool
     private DecorationModel readDecorationModel( String siteDescriptorContent )
         throws SiteToolException
     {
+        return readDecorationModel( new StringReader( siteDescriptorContent ) 
);
+    }
+    
+    /**
+     * @param siteDescriptorContent not null
+     * @return the decoration model object
+     * @throws SiteToolException if any
+     */
+    private DecorationModel readDecorationModel( Reader siteDescriptorReader )
+        throws SiteToolException
+    {
         DecorationModel decoration;
         try
         {
-            decoration = new DecorationXpp3Reader().read( new StringReader( 
siteDescriptorContent ) );
+            decoration = new DecorationXpp3Reader().read( siteDescriptorReader 
);
         }
         catch ( XmlPullParserException e )
         {

Modified: 
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java?rev=1214470&r1=1214469&r2=1214470&view=diff
==============================================================================
--- 
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
 (original)
+++ 
maven/shared/trunk/maven-doxia-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
 Wed Dec 14 21:13:54 2011
@@ -25,17 +25,23 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.LinkItem;
 import org.apache.maven.doxia.site.decoration.Skin;
 import org.apache.maven.doxia.tools.stubs.SiteToolMavenProjectStub;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.project.MavenProject;
 
 import org.codehaus.plexus.PlexusTestCase;
 
+import edu.emory.mathcs.backport.java.util.Collections;
+
 /**
  * @author <a href="mailto:[email protected]";>Vincent Siveton</a>
  * @version $Id$
@@ -289,5 +295,38 @@ public class SiteToolTest
                                      siteDirectory, Locale.getDefault(), 
"UTF-8", "UTF-8" );
         assertNotNull( model );
     }
+    
+    // MSHARED-217
+    public void testMultiModuleInterpolation()
+        throws Exception
+    {
+        SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+        assertNotNull( tool );
+
+        MavenProjectStub parentProject = new SiteToolMavenProjectStub( 
"interpolation-parent-test" );
+        parentProject.setGroupId( "org.apache.maven.shared.its" );
+        parentProject.setArtifactId( "mshared-217-parent" );
+        parentProject.setVersion( "1.0-SNAPSHOT" );
+        parentProject.setBasedir( null ); // get it from repo
+        parentProject.setName( "MSHARED-217 Parent" );
+        String siteDirectory = "src/site";
+        
+        MavenProjectStub childProject = new SiteToolMavenProjectStub( 
"interpolation-child-test" );
+        childProject.setParent( parentProject );
+        childProject.setGroupId( "org.apache.maven.shared.its" );
+        childProject.setArtifactId( "mshared-217-child" );
+        childProject.setVersion( "1.0-SNAPSHOT" );
+        childProject.setBasedir( null ); // get it from repo
+        childProject.setName( "MSHARED-217 Child" );
+
+        List<MavenProject> reactorProjects = Collections.singletonList( 
parentProject );
+
+        DecorationModel model =
+            tool.getDecorationModel( childProject, reactorProjects, 
getLocalRepo(),
+                                     
childProject.getRemoteArtifactRepositories(), siteDirectory, 
Locale.getDefault(),
+                                     "ISO-8859-1", "ISO-8859-1" );
+        assertNotNull( model );
+        assertEquals( "MSHARED-217 Child", model.getName() );
+    }
 
 }

Added: 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/pom.xml?rev=1214470&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/pom.xml
 (added)
+++ 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/pom.xml
 Wed Dec 14 21:13:54 2011
@@ -0,0 +1,29 @@
+<?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.shared.its</groupId>
+  <artifactId>mshared-217-parent</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+</project>

Added: 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/site.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/site.xml?rev=1214470&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/site.xml
 (added)
+++ 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-child-test/src/site/site.xml
 Wed Dec 14 21:13:54 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+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 name="${project.name}" 
xmlns="http://maven.apache.org/DECORATION/1.0.0";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 
http://maven.apache.org/xsd/decoration-1.0.0.xsd";>
+</project>
\ No newline at end of file

Added: 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/pom.xml?rev=1214470&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/pom.xml
 (added)
+++ 
maven/shared/trunk/maven-doxia-tools/src/test/resources/unit/interpolation-parent-test/pom.xml
 Wed Dec 14 21:13:54 2011
@@ -0,0 +1,29 @@
+<?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.shared.its</groupId>
+  <artifactId>mshared-217-child</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+</project>


Reply via email to