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