View Javadoc
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 org.apache.maven.artifact.repository.ArtifactRepository;
23  import org.apache.maven.doxia.sink.Sink;
24  import org.apache.maven.doxia.tools.SiteTool;
25  import org.apache.maven.plugin.logging.Log;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.project.MavenProject;
28  import org.apache.maven.project.ProjectBuilder;
29  import org.codehaus.plexus.i18n.I18N;
30  
31  import java.util.List;
32  import java.util.Locale;
33  
34  /**
35   * Generates the Project Index report.
36   *
37   * @author <a href="mailto:brett@apache.org">Brett Porter </a>
38   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
39   * @since 2.0
40   */
41  @Mojo( name = "index" )
42  public class IndexReport
43      extends AbstractProjectInfoReport
44  {
45      // ----------------------------------------------------------------------
46      // Public methods
47      // ----------------------------------------------------------------------
48  
49      @Override
50      public String getName( Locale locale )
51      {
52          return getI18nString( locale, "title" );
53      }
54  
55      @Override
56      public String getDescription( Locale locale )
57      {
58          String desc;
59          if ( project.getDescription() != null )
60          {
61              // TODO How to handle i18n?
62              desc = project.getDescription();
63          }
64          else
65          {
66              return getI18nString( locale, "nodescription" );
67          }
68          return desc;
69      }
70  
71      @Override
72      public void executeReport( Locale locale )
73      {
74          ProjectIndexRenderer r = new ProjectIndexRenderer( project, getReactorProjects(), projectBuilder,
75                                                             localRepository, getName( locale ), getDescription( locale ),
76                                                             getSink(), getI18N( locale ), locale, getLog(), siteTool );
77  
78          r.render();
79      }
80  
81      /** {@inheritDoc} */
82      public String getOutputName()
83      {
84          return "index";
85      }
86  
87      @Override
88      protected String getI18Nsection()
89      {
90          return "index";
91      }
92  
93      // ----------------------------------------------------------------------
94      // Private
95      // ----------------------------------------------------------------------
96  
97      /**
98       * Internal renderer class
99       */
100     private static class ProjectIndexRenderer
101         extends ModulesReport.ModulesRenderer
102     {
103         private final String title;
104 
105         private final String description;
106 
107         private boolean modules = false;
108 
109         ProjectIndexRenderer( MavenProject project, List<MavenProject> reactorProjects,
110                               ProjectBuilder projectBuilder, ArtifactRepository localRepository, String title,
111                               String description, Sink sink, I18N i18n, Locale locale, Log log, SiteTool siteTool )
112         {
113             super( sink, project, reactorProjects, projectBuilder, localRepository, i18n, locale, log, siteTool );
114 
115             this.title = title;
116 
117             this.description = description;
118         }
119 
120         @Override
121         public String getTitle()
122         {
123             return modules ? super.getTitle() : title;
124         }
125 
126         @Override
127         public void renderBody()
128         {
129             startSection( title.trim() + " " + project.getName() );
130 
131             paragraph( description );
132 
133             if ( !project.getModel().getModules().isEmpty() )
134             {
135                 modules = true;
136                 super.renderBody();
137             }
138 
139             endSection();
140         }
141     }
142 }