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