View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.report.projectinfo;
20  
21  import java.util.List;
22  import java.util.Locale;
23  
24  import org.apache.maven.artifact.repository.ArtifactRepository;
25  import org.apache.maven.doxia.sink.Sink;
26  import org.apache.maven.doxia.tools.SiteTool;
27  import org.apache.maven.plugin.logging.Log;
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.apache.maven.project.MavenProject;
30  import org.apache.maven.project.ProjectBuilder;
31  import org.codehaus.plexus.i18n.I18N;
32  
33  /**
34   * Generates the Project Index report.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter </a>
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
38   * @since 2.0
39   */
40  @Mojo(name = "index")
41  public class IndexReport extends AbstractProjectInfoReport {
42      // ----------------------------------------------------------------------
43      // Public methods
44      // ----------------------------------------------------------------------
45  
46      @Override
47      public String getName(Locale locale) {
48          return getI18nString(locale, "title");
49      }
50  
51      @Override
52      public String getDescription(Locale locale) {
53          String desc;
54          if (project.getDescription() != null) {
55              // TODO How to handle i18n?
56              desc = project.getDescription();
57          } else {
58              return getI18nString(locale, "nodescription");
59          }
60          return desc;
61      }
62  
63      @Override
64      public void executeReport(Locale locale) {
65          ProjectIndexRenderer r = new ProjectIndexRenderer(
66                  project,
67                  getReactorProjects(),
68                  projectBuilder,
69                  localRepository,
70                  getName(locale),
71                  getDescription(locale),
72                  getSink(),
73                  getI18N(locale),
74                  locale,
75                  getLog(),
76                  siteTool);
77  
78          r.render();
79      }
80  
81      /** {@inheritDoc} */
82      public String getOutputName() {
83          return "index";
84      }
85  
86      @Override
87      protected String getI18Nsection() {
88          return "index";
89      }
90  
91      // ----------------------------------------------------------------------
92      // Private
93      // ----------------------------------------------------------------------
94  
95      /**
96       * Internal renderer class
97       */
98      private static class ProjectIndexRenderer extends ModulesReport.ModulesRenderer {
99          private final String title;
100 
101         private final String description;
102 
103         private boolean modules = false;
104 
105         ProjectIndexRenderer(
106                 MavenProject project,
107                 List<MavenProject> reactorProjects,
108                 ProjectBuilder projectBuilder,
109                 ArtifactRepository localRepository,
110                 String title,
111                 String description,
112                 Sink sink,
113                 I18N i18n,
114                 Locale locale,
115                 Log log,
116                 SiteTool siteTool) {
117             super(sink, project, reactorProjects, projectBuilder, localRepository, i18n, locale, log, siteTool);
118 
119             this.title = title;
120 
121             this.description = description;
122         }
123 
124         @Override
125         public String getTitle() {
126             return modules ? super.getTitle() : title;
127         }
128 
129         @Override
130         protected void renderBody() {
131             startSection(title.trim() + " " + project.getName());
132 
133             paragraph(description);
134 
135             if (!project.getModel().getModules().isEmpty()) {
136                 modules = true;
137                 super.renderBody();
138             }
139 
140             endSection();
141         }
142     }
143 }