You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2010/05/09 23:06:04 UTC

svn commit: r942622 - in /maven/plugins/trunk/maven-site-plugin/src: it/site-attach-descriptor/ it/site-attach-descriptor/src/site/ main/java/org/apache/maven/plugins/site/

Author: dennisl
Date: Sun May  9 21:06:04 2010
New Revision: 942622

URL: http://svn.apache.org/viewvc?rev=942622&view=rev
Log:
[MSITE-478] Attach site descriptor as an artifact, not metadata, to the project

Added:
    maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site_sv.xml
      - copied, changed from r926717, maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site.xml
Modified:
    maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/pom.xml
    maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/verify.bsh
    maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java

Modified: maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/pom.xml?rev=942622&r1=942621&r2=942622&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/pom.xml (original)
+++ maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/pom.xml Sun May  9 21:06:04 2010
@@ -51,6 +51,9 @@ under the License.
       <plugin>
         <artifactId>maven-site-plugin</artifactId>
         <version>@project.version@</version>
+        <configuration>
+          <locales>en,sv</locales>
+        </configuration>
       </plugin>
     </plugins>
   </build>

Copied: maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site_sv.xml (from r926717, maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site.xml)
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site_sv.xml?p2=maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site_sv.xml&p1=maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site.xml&r1=926717&r2=942622&rev=942622&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site.xml (original)
+++ maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/src/site/site_sv.xml Sun May  9 21:06:04 2010
@@ -33,7 +33,7 @@ under the License.
     <breadcrumbs>
       <item name="Maven" href="http://maven.apache.org/${currentVersion}"/>
     </breadcrumbs>
-    <menu name="Releases TODO">
+    <menu name="Releaser att göra">
       <item name="release1.6" href="releases/release1.6.html"/>
       <item name="release1.6.3" href="releases/release1.6.3.html"/>
     </menu>

Modified: maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/verify.bsh?rev=942622&r1=942621&r2=942622&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/verify.bsh (original)
+++ maven/plugins/trunk/maven-site-plugin/src/it/site-attach-descriptor/verify.bsh Sun May  9 21:06:04 2010
@@ -32,14 +32,27 @@ try
         return false;
     }
 
-    File siteDescriptor = new File ( target, "snapshot-repo/test/site-attach-descriptor/1.0-SNAPSHOT/site-attach-descriptor-1.0-SNAPSHOT-site.xml" );
+    File siteDescriptor = new File ( target, "site-attach-descriptor-1.0-SNAPSHOT-site.xml" );
     if ( !siteDescriptor.exists() || siteDescriptor.isDirectory() )
     {
-        System.err.println( "siteDescriptor file is missing or not a directory." );
+        System.err.println( "siteDescriptor file is missing from target or is a directory." );
         return false;
     }    
     
-    
+    File siteDescriptor = new File ( target, "snapshot-repo/test/site-attach-descriptor/1.0-SNAPSHOT/site-attach-descriptor-1.0-SNAPSHOT-site.xml" );
+    if ( !siteDescriptor.exists() || siteDescriptor.isDirectory() )
+    {
+        System.err.println( "siteDescriptor file is missing from local repository or is a directory." );
+        return false;
+    }
+
+    File siteDescriptorSwedish = new File ( target, "site-attach-descriptor-1.0-SNAPSHOT-site_sv.xml" );
+    if ( !siteDescriptorSwedish.exists() || siteDescriptorSwedish.isDirectory() )
+    {
+        System.err.println( "siteDescriptorSwedish file is missing from target or is a directory." );
+        return false;
+    }
+
 }
 catch( IOException e )
 {

Modified: maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java?rev=942622&r1=942621&r2=942622&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java (original)
+++ maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java Sun May  9 21:06:04 2010
@@ -22,16 +22,20 @@ package org.apache.maven.plugins.site;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
+import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
 import org.apache.maven.doxia.tools.SiteToolException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.Writer;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -63,6 +67,15 @@ public class SiteDescriptorAttachMojo
      */
     private File basedir;
 
+    /**
+     * Maven ProjectHelper.
+     *
+     * @component
+     * @readonly
+     * @since 2.1.1
+     */
+    private MavenProjectHelper projectHelper;
+
     public void execute()
         throws MojoExecutionException
     {
@@ -103,7 +116,7 @@ public class SiteDescriptorAttachMojo
                 }
                 catch ( SiteToolException e )
                 {
-                    throw new MojoExecutionException( "Error when interpoling site descriptor", e );
+                    throw new MojoExecutionException( "Error when interpolating site descriptor", e );
                 }
 
                 MavenProject parentProject = siteTool.getParentProject( project, reactorProjects, localRepository );
@@ -120,7 +133,37 @@ public class SiteDescriptorAttachMojo
                     throw new MojoExecutionException( "Error when populating modules", e );
                 }
 
-                artifact.addMetadata( new SiteDescriptorArtifactMetadata( artifact, decoration, descriptorFile ) );
+                // Calculate the classifier to use
+                String classifier = null;
+                int index = descriptorFile.getName().lastIndexOf( '.' );
+                if ( index > 0 )
+                {
+                    classifier = descriptorFile.getName().substring( 0, index );
+                }
+                else
+                {
+                    throw new MojoExecutionException( "Unable to determine the classifier to use" );
+                }
+
+                // Prepare a file for the interpolated site descriptor
+                String filename = project.getArtifactId() + "-" + project.getVersion() + "-" + descriptorFile.getName();
+                File interpolatedDescriptorFile = new File( project.getBuild().getDirectory(), filename );
+                interpolatedDescriptorFile.getParentFile().mkdirs();
+
+                try
+                {
+                    // Write the interpolated site descriptor to a file
+                    Writer writer = WriterFactory.newXmlWriter( interpolatedDescriptorFile );
+                    new DecorationXpp3Writer().write( writer, decoration );
+                    // Attach the interpolated site descriptor
+                    getLog().debug( "Attaching the site descriptor '" + interpolatedDescriptorFile.getAbsolutePath()
+                        + "' with classifier '" + classifier + "' to the project." );
+                    projectHelper.attachArtifact( project, "xml", classifier, interpolatedDescriptorFile );
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( "Unable to store interpolated site descriptor", e );
+                }
             }
         }
     }