1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.sink.Sink;
23 import org.apache.maven.model.Organization;
24 import org.apache.maven.reporting.AbstractMavenReportRenderer;
25 import org.apache.maven.reporting.MavenReportException;
26 import org.codehaus.plexus.util.StringUtils;
27
28 import java.util.Locale;
29
30
31
32
33
34
35
36
37
38
39 public class ProjectSummaryReport
40 extends AbstractProjectInfoReport
41 {
42
43
44
45
46
47 protected void executeReport( Locale locale )
48 throws MavenReportException
49 {
50 new ProjectSummaryRenderer( getSink(), locale ).render();
51 }
52
53
54 public String getName( Locale locale )
55 {
56 return i18n.getString( "project-info-report", locale, "report.summary.name" );
57 }
58
59
60 public String getDescription( Locale locale )
61 {
62 return i18n.getString( "project-info-report", locale, "report.summary.description" );
63 }
64
65
66 public String getOutputName()
67 {
68 return "project-summary";
69 }
70
71
72
73
74
75
76
77
78 private class ProjectSummaryRenderer
79 extends AbstractMavenReportRenderer
80 {
81 private final Locale locale;
82
83 ProjectSummaryRenderer( Sink sink, Locale locale )
84 {
85 super( sink );
86
87 this.locale = locale;
88 }
89
90
91 public String getTitle()
92 {
93 return getReportString( "report.summary.title" );
94 }
95
96
97 protected void renderBody()
98 {
99 startSection( getTitle() );
100
101
102 String name = project.getName();
103 if ( name == null )
104 {
105 name = "";
106 }
107 String description = project.getDescription();
108 if ( description == null )
109 {
110 description = "";
111 }
112 String homepage = project.getUrl();
113 if ( homepage == null )
114 {
115 homepage = "";
116 }
117
118 startSection( getReportString( "report.summary.general.title" ) );
119 startTable();
120 tableHeader(
121 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
122 tableRow( new String[]{getReportString( "report.summary.general.name" ), name} );
123 tableRow( new String[]{getReportString( "report.summary.general.description" ), description} );
124 tableRowWithLink( new String[]{getReportString( "report.summary.general.homepage" ), homepage} );
125 endTable();
126 endSection();
127
128
129 startSection( getReportString( "report.summary.organization.title" ) );
130 Organization organization = project.getOrganization();
131 if ( organization == null )
132 {
133 paragraph( getReportString( "report.summary.noorganization" ) );
134 }
135 else
136 {
137 if ( organization.getName() == null )
138 {
139 organization.setName( "" );
140 }
141 if ( organization.getUrl() == null )
142 {
143 organization.setUrl( "" );
144 }
145
146 startTable();
147 tableHeader( new String[]{getReportString( "report.summary.field" ),
148 getReportString( "report.summary.value" )} );
149 tableRow( new String[] { getReportString( "report.summary.organization.name" ),
150 organization.getName() } );
151 tableRowWithLink(
152 new String[]{getReportString( "report.summary.organization.url" ), organization.getUrl()} );
153 endTable();
154 }
155 endSection();
156
157
158 startSection( getReportString( "report.summary.build.title" ) );
159 startTable();
160 tableHeader(
161 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
162 tableRow( new String[]{getReportString( "report.summary.build.groupid" ), project.getGroupId()} );
163 tableRow( new String[]{getReportString( "report.summary.build.artifactid" ), project.getArtifactId()} );
164 tableRow( new String[]{getReportString( "report.summary.build.version" ), project.getVersion()} );
165 tableRow( new String[]{getReportString( "report.summary.build.type" ), project.getPackaging()} );
166 endTable();
167 endSection();
168
169 endSection();
170 }
171
172 private String getReportString( String key )
173 {
174 return i18n.getString( "project-info-report", locale, key );
175 }
176
177 private void tableRowWithLink( String[] content )
178 {
179 sink.tableRow();
180
181 for ( int ctr = 0; ctr < content.length; ctr++ )
182 {
183 String cell = content[ctr];
184
185 sink.tableCell();
186
187 if ( StringUtils.isEmpty( cell ) )
188 {
189 sink.text( "-" );
190 }
191 else
192 {
193 if ( ctr == content.length - 1 && cell.length() > 0 )
194 {
195 sink.link( cell );
196 sink.text( cell );
197 sink.link_();
198 }
199 else
200 {
201 sink.text( cell );
202 }
203 }
204 sink.tableCell_();
205 }
206
207 sink.tableRow_();
208 }
209 }
210 }