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.DistributionManagement;
24 import org.apache.maven.model.Organization;
25 import org.apache.maven.project.MavenProject;
26 import org.apache.maven.reporting.MavenReportException;
27 import org.codehaus.plexus.util.FileUtils;
28 import org.codehaus.plexus.util.StringUtils;
29 import org.codehaus.plexus.util.xml.Xpp3Dom;
30
31 import java.io.File;
32 import java.io.IOException;
33 import java.util.Locale;
34
35
36
37
38
39
40
41
42
43
44 public class ProjectSummaryReport
45 extends AbstractProjectInfoReport
46 {
47
48
49
50
51 @Override
52 protected void executeReport( Locale locale )
53 throws MavenReportException
54 {
55 new ProjectSummaryRenderer( getSink(), locale ).render();
56 }
57
58
59 public String getOutputName()
60 {
61 return "project-summary";
62 }
63
64 @Override
65 protected String getI18Nsection()
66 {
67 return "summary";
68 }
69
70
71
72
73
74
75
76
77 private class ProjectSummaryRenderer
78 extends AbstractProjectInfoRenderer
79 {
80 ProjectSummaryRenderer( Sink sink, Locale locale )
81 {
82 super( sink, getI18N( locale ), locale );
83 }
84
85 @Override
86 protected String getI18Nsection()
87 {
88 return "summary";
89 }
90
91 @Override
92 protected void renderBody()
93 {
94 startSection( getTitle() );
95
96
97 startSection( getI18nString( "general.title" ) );
98 startTable();
99 tableHeader( new String[] { getI18nString( "field" ), getI18nString( "value" ) } );
100 tableRow( new String[] { getI18nString( "general.name" ), project.getName() } );
101 tableRow( new String[] { getI18nString( "general.description" ), project.getDescription() } );
102 tableRowWithLink( new String[] { getI18nString( "general.homepage" ), project.getUrl() } );
103 endTable();
104 endSection();
105
106
107 startSection( getI18nString( "organization.title" ) );
108 Organization organization = project.getOrganization();
109 if ( organization == null )
110 {
111 paragraph( getI18nString( "noorganization" ) );
112 }
113 else
114 {
115 startTable();
116 tableHeader( new String[] { getI18nString( "field" ), getI18nString( "value" ) } );
117 tableRow( new String[] { getI18nString( "organization.name" ), organization.getName() } );
118 tableRowWithLink( new String[] { getI18nString( "organization.url" ), organization.getUrl() } );
119 endTable();
120 }
121 endSection();
122
123
124 startSection( getI18nString( "build.title" ) );
125 startTable();
126 tableHeader( new String[] { getI18nString( "field" ), getI18nString( "value" ) } );
127 tableRow( new String[] { getI18nString( "build.groupid" ), project.getGroupId() } );
128 tableRow( new String[] { getI18nString( "build.artifactid" ), project.getArtifactId() } );
129 tableRow( new String[] { getI18nString( "build.version" ), project.getVersion() } );
130 tableRow( new String[] { getI18nString( "build.type" ), project.getPackaging() } );
131 if ( isJavaProject( project ) )
132 {
133 tableRow( new String[] { getI18nString( "build.jdk" ), getMinimumJavaVersion() } );
134 }
135 endTable();
136 endSection();
137
138
139 DistributionManagement distributionManagement = project.getDistributionManagement();
140 if ( distributionManagement != null )
141 {
142 if ( StringUtils.isNotEmpty( distributionManagement.getDownloadUrl() ) )
143 {
144 startSection( getI18nString( "download" ) );
145 link( distributionManagement.getDownloadUrl(), distributionManagement.getDownloadUrl() );
146 endSection();
147 }
148 else if ( distributionManagement.getRepository() != null
149 && StringUtils.isNotEmpty( distributionManagement.getRepository().getUrl() ) )
150 {
151 startSection( getI18nString( "download" ) );
152 String link = distributionManagement.getRepository().getUrl();
153 if ( !link.endsWith( "/" ) )
154 {
155 link += "/";
156 }
157 link += StringUtils.replace( project.getGroupId(), ".", "/" );
158 link += "/";
159 link += project.getArtifactId();
160 link( link, link );
161 endSection();
162 }
163 }
164
165 endSection();
166 }
167
168 private String getMinimumJavaVersion()
169 {
170 Xpp3Dom pluginConfig =
171 project.getGoalConfiguration( "org.apache.maven.plugins", "maven-compiler-plugin", null, null );
172
173 String source = null;
174 String target = null;
175 String compilerVersion = null;
176
177 if ( pluginConfig != null )
178 {
179 source = getChildValue( pluginConfig, "source" );
180 target = getChildValue( pluginConfig, "target" );
181
182 String fork = getChildValue( pluginConfig, "fork" );
183 if ( "true".equalsIgnoreCase( fork ) )
184 {
185 compilerVersion = getChildValue( pluginConfig, "compilerVersion" );
186 }
187 }
188
189 String minimumJavaVersion = compilerVersion;
190 if ( target != null )
191 {
192 minimumJavaVersion = target;
193 }
194 else if ( source != null )
195 {
196 minimumJavaVersion = source;
197 }
198 else if ( compilerVersion != null )
199 {
200 minimumJavaVersion = compilerVersion;
201 }
202 else
203 {
204
205
206 }
207
208 return minimumJavaVersion;
209 }
210
211 private String getChildValue( Xpp3Dom parent, String childName )
212 {
213 if ( parent == null )
214 {
215 return null;
216 }
217
218 Xpp3Dom child = parent.getChild( childName );
219
220 if ( child == null )
221 {
222 return null;
223 }
224
225 String value = child.getValue();
226
227 if ( value == null || value.trim().length() == 0 )
228 {
229 return null;
230 }
231
232 return value.trim();
233 }
234
235 private void tableRowWithLink( String[] content )
236 {
237 sink.tableRow();
238
239 for ( int ctr = 0; ctr < content.length; ctr++ )
240 {
241 String cell = content[ctr];
242
243 sink.tableCell();
244
245 if ( StringUtils.isEmpty( cell ) )
246 {
247 sink.text( "-" );
248 }
249 else if ( ctr == content.length - 1 && cell.length() > 0 )
250 {
251 sink.link( cell );
252 sink.text( cell );
253 sink.link_();
254 }
255 else
256 {
257 sink.text( cell );
258 }
259 sink.tableCell_();
260 }
261
262 sink.tableRow_();
263 }
264
265
266
267
268
269
270
271 private boolean isJavaProject( MavenProject project )
272 {
273 String packaging = project.getPackaging().trim().toLowerCase( Locale.ENGLISH );
274 if ( packaging.equals( "pom" ) )
275 {
276 return false;
277 }
278
279
280 if ( packaging.equals( "jar" ) || packaging.equals( "ear" ) || packaging.equals( "war" )
281 || packaging.equals( "rar" ) || packaging.equals( "sar" ) || packaging.equals( "har" )
282 || packaging.equals( "par" ) || packaging.equals( "ejb" ) )
283 {
284 return true;
285 }
286
287
288 try
289 {
290 if ( FileUtils.getFileNames( new File( project.getBuild().getSourceDirectory() ), "**/*.java", null,
291 false ).size() > 0 )
292 {
293 return true;
294 }
295 }
296 catch ( IOException e )
297 {
298
299 }
300
301
302 Xpp3Dom pluginConfig =
303 project.getGoalConfiguration( "org.apache.maven.plugins", "maven-compiler-plugin", null, null );
304 if ( pluginConfig != null )
305 {
306 return true;
307 }
308
309 return false;
310 }
311 }
312 }