Coverage Report - org.apache.maven.plugins.site.AbstractSiteMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSiteMojo
4%
1/26
0%
0/20
2,4
 
 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 java.io.File;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 import java.util.Locale;
 26  
 import java.util.Map;
 27  
 
 28  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 29  
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 30  
 import org.apache.maven.doxia.site.decoration.Menu;
 31  
 import org.apache.maven.doxia.site.decoration.MenuItem;
 32  
 import org.apache.maven.doxia.tools.SiteTool;
 33  
 import org.apache.maven.plugin.AbstractMojo;
 34  
 import org.apache.maven.project.MavenProject;
 35  
 import org.apache.maven.project.MavenProjectBuilder;
 36  
 import org.apache.maven.reporting.MavenReport;
 37  
 import org.codehaus.plexus.i18n.I18N;
 38  
 import org.codehaus.plexus.util.ReaderFactory;
 39  
 
 40  
 /**
 41  
  * Base class for site mojos.
 42  
  *
 43  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 44  
  */
 45  2
 public abstract class AbstractSiteMojo
 46  
     extends AbstractMojo
 47  
 {
 48  
     /**
 49  
      * A comma separated list of locales supported by Maven. The first valid token will be the default Locale
 50  
      * for this instance of the Java Virtual Machine.
 51  
      *
 52  
      * @parameter expression="${locales}"
 53  
      */
 54  
     protected String locales;
 55  
 
 56  
     /**
 57  
      * SiteTool.
 58  
      *
 59  
      * @component
 60  
      */
 61  
     protected SiteTool siteTool;
 62  
 
 63  
     /**
 64  
      * Internationalization.
 65  
      *
 66  
      * @component
 67  
      */
 68  
     protected I18N i18n;
 69  
 
 70  
     /**
 71  
      * Directory containing the site.xml file and the source for apt, fml and xdoc docs.
 72  
      *
 73  
      * @parameter expression="${basedir}/src/site"
 74  
      * @required
 75  
      */
 76  
     protected File siteDirectory;
 77  
 
 78  
     /**
 79  
      * The maven project.
 80  
      *
 81  
      * @parameter expression="${project}"
 82  
      * @required
 83  
      * @readonly
 84  
      */
 85  
     protected MavenProject project;
 86  
 
 87  
     /**
 88  
      * The local repository.
 89  
      *
 90  
      * @parameter expression="${localRepository}"
 91  
      */
 92  
     protected ArtifactRepository localRepository;
 93  
 
 94  
     /**
 95  
      * The reactor projects.
 96  
      *
 97  
      * @parameter expression="${reactorProjects}"
 98  
      * @required
 99  
      * @readonly
 100  
      */
 101  
     protected List reactorProjects;
 102  
 
 103  
     /**
 104  
      * Project builder
 105  
      *
 106  
      * @component
 107  
      */
 108  
     protected MavenProjectBuilder mavenProjectBuilder;
 109  
 
 110  
     /**
 111  
      * Specifies the input encoding.
 112  
      *
 113  
      * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
 114  
      */
 115  
     private String inputEncoding;
 116  
 
 117  
     /**
 118  
      * Specifies the output encoding.
 119  
      *
 120  
      * @parameter expression="${outputEncoding}" default-value="${project.reporting.outputEncoding}"
 121  
      */
 122  
     private String outputEncoding;
 123  
 
 124  
     /**
 125  
      * Gets the input files encoding.
 126  
      *
 127  
      * @return The input files encoding, never <code>null</code>.
 128  
      */
 129  
     protected String getInputEncoding()
 130  
     {
 131  0
         return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding;
 132  
     }
 133  
 
 134  
     /**
 135  
      * Gets the effective reporting output files encoding.
 136  
      *
 137  
      * @return The effective reporting output file encoding, never <code>null</code>.
 138  
      */
 139  
     protected String getOutputEncoding()
 140  
     {
 141  0
         return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
 142  
     }
 143  
 
 144  
     protected void populateReportItems( DecorationModel decorationModel, Locale locale, Map reportsByOutputName )
 145  
     {
 146  0
         for ( Iterator i = decorationModel.getMenus().iterator(); i.hasNext(); )
 147  
         {
 148  0
             Menu menu = (Menu) i.next();
 149  
 
 150  0
             populateItemRefs( menu.getItems(), locale, reportsByOutputName );
 151  
         }
 152  0
     }
 153  
 
 154  
     private void populateItemRefs( List items, Locale locale, Map reportsByOutputName )
 155  
     {
 156  0
         for ( Iterator i = items.iterator(); i.hasNext(); )
 157  
         {
 158  0
             MenuItem item = (MenuItem) i.next();
 159  
 
 160  0
             if ( item.getRef() != null )
 161  
             {
 162  0
                 if ( reportsByOutputName.containsKey( item.getRef() ) )
 163  
                 {
 164  0
                     MavenReport report = (MavenReport) reportsByOutputName.get( item.getRef() );
 165  
 
 166  0
                     if ( item.getName() == null )
 167  
                     {
 168  0
                         item.setName( report.getName( locale ) );
 169  
                     }
 170  
 
 171  0
                     if ( item.getHref() == null || item.getHref().length() == 0 )
 172  
                     {
 173  0
                         item.setHref( report.getOutputName() + ".html" );
 174  
                     }
 175  
                 }
 176  
                 else
 177  
                 {
 178  0
                     getLog().warn( "Unrecognised reference: '" + item.getRef() + "'" );
 179  0
                     i.remove();
 180  
                 }
 181  
             }
 182  0
             populateItemRefs( item.getItems(), locale, reportsByOutputName );
 183  
         }
 184  0
     }
 185  
 
 186  
     /**
 187  
      * TODO should be removed see PLXUTILS-61
 188  
      *
 189  
      * @param basedir
 190  
      * @param absolutePath
 191  
      * @return
 192  
      */
 193  
     protected static String toRelative( File basedir, String absolutePath )
 194  
     {
 195  
         String relative;
 196  
 
 197  0
         absolutePath = absolutePath.replace( '\\', '/' );
 198  0
         String basedirPath = basedir.getAbsolutePath().replace( '\\', '/' );
 199  
 
 200  0
         if ( absolutePath.startsWith( basedirPath ) )
 201  
         {
 202  0
             relative = absolutePath.substring( basedirPath.length() + 1 );
 203  
         }
 204  
         else
 205  
         {
 206  0
             relative = absolutePath;
 207  
         }
 208  
 
 209  0
         return relative;
 210  
     }
 211  
 }