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