Coverage Report - org.apache.maven.plugins.site.SiteDescriptorAttachMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
SiteDescriptorAttachMojo
0%
0/28
0%
0/10
12
 
 1  
 package org.apache.maven.plugins.site;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.artifact.Artifact;
 23  
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 24  
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
 25  
 import org.apache.maven.doxia.tools.SiteToolException;
 26  
 import org.apache.maven.plugin.MojoExecutionException;
 27  
 import org.apache.maven.project.MavenProject;
 28  
 import org.codehaus.plexus.util.IOUtil;
 29  
 import org.codehaus.plexus.util.ReaderFactory;
 30  
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 31  
 
 32  
 import java.io.File;
 33  
 import java.io.IOException;
 34  
 import java.io.StringReader;
 35  
 import java.util.HashMap;
 36  
 import java.util.Iterator;
 37  
 import java.util.List;
 38  
 import java.util.Locale;
 39  
 import java.util.Map;
 40  
 
 41  
 /**
 42  
  * Adds the site descriptor (<code>site.xml</code>) to the list of files to be installed/deployed.
 43  
  *
 44  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 45  
  * @version $Id: org.apache.maven.plugins.site.SiteDescriptorAttachMojo.html 816550 2012-05-08 11:52:49Z hboutemy $
 46  
  * @goal attach-descriptor
 47  
  * @phase package
 48  
  */
 49  0
 public class SiteDescriptorAttachMojo
 50  
     extends AbstractSiteMojo
 51  
 {
 52  
     /**
 53  
      * @parameter expression="${project.artifact}"
 54  
      * @required
 55  
      * @readonly
 56  
      */
 57  
     private Artifact artifact;
 58  
 
 59  
     /**
 60  
      * @parameter expression="${basedir}"
 61  
      * @required
 62  
      * @readonly
 63  
      */
 64  
     private File basedir;
 65  
 
 66  
     public void execute()
 67  
         throws MojoExecutionException
 68  
     {
 69  0
         List localesList = siteTool.getAvailableLocales( locales );
 70  
 
 71  0
         for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
 72  
         {
 73  0
             Locale locale = (Locale) iterator.next();
 74  
 
 75  0
             File descriptorFile = siteTool.getSiteDescriptorFromBasedir( toRelative( project.getBasedir(),
 76  
                                                                                      siteDirectory.getAbsolutePath() ),
 77  
                                                                          basedir, locale );
 78  
 
 79  0
             if ( descriptorFile.exists() )
 80  
             {
 81  0
                 Map props = new HashMap();
 82  0
                 props.put( "reports", "<menu ref=\"reports\"/>" );
 83  0
                 props.put( "modules", "<menu ref=\"modules\"/>" );
 84  
 
 85  
                 DecorationModel decoration;
 86  
                 try
 87  
                 {
 88  0
                     String siteDescriptorContent = IOUtil.toString( ReaderFactory.newXmlReader( descriptorFile ) );
 89  
 
 90  0
                     siteDescriptorContent =
 91  
                         siteTool.getInterpolatedSiteDescriptorContent( props, project, siteDescriptorContent,
 92  
                                                                        getInputEncoding(), getOutputEncoding() );
 93  
 
 94  0
                     decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) );
 95  
                 }
 96  0
                 catch ( XmlPullParserException e )
 97  
                 {
 98  0
                     throw new MojoExecutionException( "Error parsing site descriptor", e );
 99  
                 }
 100  0
                 catch ( IOException e )
 101  
                 {
 102  0
                     throw new MojoExecutionException( "Error reading site descriptor", e );
 103  
                 }
 104  0
                 catch ( SiteToolException e )
 105  
                 {
 106  0
                     throw new MojoExecutionException( "Error when interpoling site descriptor", e );
 107  0
                 }
 108  
 
 109  0
                 MavenProject parentProject = siteTool.getParentProject( project, reactorProjects, localRepository );
 110  0
                 if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null )
 111  
                 {
 112  0
                     siteTool.populateParentMenu( decoration, locale, project, parentProject, true );
 113  
                 }
 114  
                 try
 115  
                 {
 116  0
                     siteTool.populateModulesMenu( project, reactorProjects, localRepository, decoration, locale, true );
 117  
                 }
 118  0
                 catch ( SiteToolException e )
 119  
                 {
 120  0
                     throw new MojoExecutionException( "Error when populating modules", e );
 121  0
                 }
 122  
 
 123  0
                 artifact.addMetadata( new SiteDescriptorArtifactMetadata( artifact, decoration, descriptorFile ) );
 124  
             }
 125  
         }
 126  0
     }
 127  
 }