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