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.apache.maven.project.ProjectBuildingRequest;
32  import org.codehaus.plexus.i18n.I18N;
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 extends AbstractProjectInfoReport {
43      // ----------------------------------------------------------------------
44      // Public methods
45      // ----------------------------------------------------------------------
46  
47      @Override
48      public String getName(Locale locale) {
49          return getI18nString(locale, "title");
50      }
51  
52      @Override
53      public String getDescription(Locale locale) {
54          String desc;
55          if (project.getDescription() != null) {
56              // TODO How to handle i18n?
57              desc = project.getDescription();
58          } else {
59              return getI18nString(locale, "nodescription");
60          }
61          return desc;
62      }
63  
64      @Override
65      public void executeReport(Locale locale) {
66          ProjectIndexRenderer r = new ProjectIndexRenderer(
67                  project,
68                  getReactorProjects(),
69                  projectBuilder,
70                  getSession().getProjectBuildingRequest(),
71                  localRepository,
72                  getName(locale),
73                  getDescription(locale),
74                  getSink(),
75                  getI18N(locale),
76                  locale,
77                  getLog(),
78                  siteTool);
79  
80          r.render();
81      }
82  
83      /** {@inheritDoc} */
84      public String getOutputName() {
85          return "index";
86      }
87  
88      @Override
89      protected String getI18Nsection() {
90          return "index";
91      }
92  
93      // ----------------------------------------------------------------------
94      // Private
95      // ----------------------------------------------------------------------
96  
97      /**
98       * Internal renderer class
99       */
100     private static class ProjectIndexRenderer extends ModulesReport.ModulesRenderer {
101         private final String title;
102 
103         private final String description;
104 
105         private boolean modules = false;
106 
107         ProjectIndexRenderer(
108                 MavenProject project,
109                 List<MavenProject> reactorProjects,
110                 ProjectBuilder projectBuilder,
111                 ProjectBuildingRequest buildingRequest,
112                 ArtifactRepository localRepository,
113                 String title,
114                 String description,
115                 Sink sink,
116                 I18N i18n,
117                 Locale locale,
118                 Log log,
119                 SiteTool siteTool) {
120             super(
121                     sink,
122                     project,
123                     reactorProjects,
124                     projectBuilder,
125                     buildingRequest,
126                     localRepository,
127                     i18n,
128                     locale,
129                     log,
130                     siteTool);
131 
132             this.title = title;
133 
134             this.description = description;
135         }
136 
137         @Override
138         public String getTitle() {
139             return modules ? super.getTitle() : title;
140         }
141 
142         @Override
143         protected void renderBody() {
144             startSection(title.trim() + " " + project.getName());
145 
146             paragraph(description);
147 
148             if (!project.getModel().getModules().isEmpty()) {
149                 modules = true;
150                 super.renderBody();
151             }
152 
153             endSection();
154         }
155     }
156 }