Coverage Report - org.apache.maven.report.projectinfo.ModulesReport
 
Classes in this File Line Coverage Branch Coverage Complexity
ModulesReport
74%
17/23
50%
2/4
1.778
ModulesReport$ModulesRenderer
79%
23/29
67%
4/6
1.778
 
 1  
 package org.apache.maven.report.projectinfo;
 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 java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.io.Reader;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 import java.util.Locale;
 28  
 
 29  
 import org.apache.maven.doxia.sink.Sink;
 30  
 import org.apache.maven.model.Model;
 31  
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 32  
 
 33  
 import org.codehaus.plexus.i18n.I18N;
 34  
 import org.codehaus.plexus.util.IOUtil;
 35  
 import org.codehaus.plexus.util.ReaderFactory;
 36  
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 37  
 
 38  
 /**
 39  
  * Generates the Project Modules report.
 40  
  *
 41  
  * @author ltheussl
 42  
  * @version $Id: ModulesReport.java 940663 2010-05-03 22:58:15Z hboutemy $
 43  
  * @since 2.2
 44  
  * @goal modules
 45  
  */
 46  5
 public class ModulesReport
 47  
     extends AbstractProjectInfoReport
 48  
 {
 49  
     // ----------------------------------------------------------------------
 50  
     // Public methods
 51  
     // ----------------------------------------------------------------------
 52  
 
 53  
     /** {@inheritDoc} */
 54  
     public void executeReport( Locale locale )
 55  
     {
 56  1
         new ModulesRenderer( getSink(), getProject().getModel(), i18n, locale ).render();
 57  1
     }
 58  
 
 59  
     /** {@inheritDoc} */
 60  
     public String getOutputName()
 61  
     {
 62  2
         return "modules";
 63  
     }
 64  
 
 65  
     protected String getI18Nsection()
 66  
     {
 67  1
         return "modules";
 68  
     }
 69  
 
 70  
     /** {@inheritDoc} */
 71  
     public boolean canGenerateReport()
 72  
     {
 73  2
         return ( getProject().getModel().getModules() != null && !getProject().getModel().getModules().isEmpty() );
 74  
     }
 75  
 
 76  
     // ----------------------------------------------------------------------
 77  
     // Private
 78  
     // ----------------------------------------------------------------------
 79  
 
 80  
     /**
 81  
      * Internal renderer class
 82  
      */
 83  1
     private class ModulesRenderer
 84  
         extends AbstractProjectInfoRenderer
 85  
     {
 86  
         private Model model;
 87  
 
 88  
         ModulesRenderer( Sink sink, Model model, I18N i18n, Locale locale )
 89  1
         {
 90  1
             super( sink, i18n, locale );
 91  
 
 92  1
             this.model = model;
 93  1
         }
 94  
 
 95  
         protected String getI18Nsection()
 96  
         {
 97  5
             return "modules";
 98  
         }
 99  
 
 100  
         /** {@inheritDoc} */
 101  
         public void renderBody()
 102  
         {
 103  1
             List modules = model.getModules();
 104  
 
 105  1
             startSection( getTitle() );
 106  
 
 107  1
             paragraph( getI18nString( "intro" ) );
 108  
 
 109  1
             startTable();
 110  
 
 111  1
             String name = getI18nString( "header.name" );
 112  1
             String description = getI18nString( "header.description" );
 113  1
             tableHeader( new String[] {name, description} );
 114  
 
 115  1
             for ( Iterator it = modules.iterator(); it.hasNext(); )
 116  
             {
 117  2
                 String module = (String) it.next();
 118  
 
 119  
                 Model moduleModel;
 120  2
                 File f = new File( project.getBasedir(), module + "/pom.xml" );
 121  
 
 122  2
                 if ( f.exists() )
 123  
                 {
 124  2
                     moduleModel = readModel( f );
 125  
 
 126  2
                     if ( moduleModel == null )
 127  
                     {
 128  0
                         getLog().warn( "Unable to read filesystem POM for module " + module );
 129  
 
 130  0
                         moduleModel = new Model();
 131  0
                         moduleModel.setName( module );
 132  
                     }
 133  
                 }
 134  
                 else
 135  
                 {
 136  0
                     getLog().warn( "No filesystem POM found for module " + module );
 137  
 
 138  0
                     moduleModel = new Model();
 139  0
                     moduleModel.setName( module );
 140  
                 }
 141  
 
 142  2
                 tableRow( new String[] {linkedName( moduleModel.getName(), module ), moduleModel.getDescription()} );
 143  2
             }
 144  
 
 145  1
             endTable();
 146  
 
 147  1
             endSection();
 148  1
         }
 149  
     }
 150  
 
 151  
     private String linkedName( String name, String link )
 152  
     {
 153  2
         return "{" + name + ", ./" + link + "/}";
 154  
     }
 155  
 
 156  
     /**
 157  
      * Gets the pom model for this file.
 158  
      *
 159  
      * @param pom the pom
 160  
      *
 161  
      * @return the model
 162  
      */
 163  
     private Model readModel ( File pom )
 164  
     {
 165  2
         MavenXpp3Reader xpp3 = new MavenXpp3Reader();
 166  2
         Model model = null;
 167  2
         Reader reader = null;
 168  
 
 169  
         try
 170  
         {
 171  2
             reader = ReaderFactory.newXmlReader( pom );
 172  2
             model = xpp3.read( reader );
 173  
         }
 174  0
         catch ( IOException io )
 175  
         {
 176  0
             getLog().debug( io );
 177  0
             return null;
 178  
         }
 179  0
         catch ( XmlPullParserException xe )
 180  
         {
 181  0
             getLog().debug( xe );
 182  0
             return null;
 183  
         }
 184  
         finally
 185  
         {
 186  2
             IOUtil.close( reader );
 187  2
             reader = null;
 188  2
         }
 189  
 
 190  2
         return model;
 191  
     }
 192  
 }