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.plugins.annotations.Mojo;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.project.MavenProjectBuilder;
28  import org.codehaus.plexus.i18n.I18N;
29  
30  import java.util.Locale;
31  
32  /**
33   * Generates the project index page.
34   *
35   * @author <a href="mailto:brett@apache.org">Brett Porter </a>
36   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
37   * @version $Id: ProjectIndexPageReport.html 935177 2015-01-05 21:05:55Z michaelo $
38   * @since 2.0
39   */
40  @Mojo( name = "index" )
41  public class ProjectIndexPageReport
42      extends AbstractProjectInfoReport
43  {
44      // ----------------------------------------------------------------------
45      // Public methods
46      // ----------------------------------------------------------------------
47  
48      @Override
49      public String getName( Locale locale )
50      {
51          return getI18nString( locale, "title" );
52      }
53  
54      @Override
55      public String getDescription( Locale locale )
56      {
57          String desc;
58          if ( project.getDescription() != null )
59          {
60              // TODO How to handle i18n?
61              desc = project.getDescription();
62          }
63          else
64          {
65              return getI18nString( locale, "nodescription" );
66          }
67          return desc;
68      }
69  
70      @Override
71      public void executeReport( Locale locale )
72      {
73          ProjectIndexRenderer r =
74              new ProjectIndexRenderer( project, mavenProjectBuilder, localRepository,
75                                        getName( locale ), getDescription( locale ), getSink(),
76                                        getI18N( locale ), locale, 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, MavenProjectBuilder mavenProjectBuilder,
110                               ArtifactRepository localRepository, String title, String description,
111                               Sink sink, I18N i18n, Locale locale, SiteTool siteTool )
112         {
113             super( sink, project, mavenProjectBuilder, localRepository, i18n, locale, 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 }