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 @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 }
149
150 endSection();
151 }
152
153 private String getMinimumJavaVersion()
154 {
155
156 final String pluginId = "org.apache.maven.plugins:maven-compiler-plugin";
157 String sourceConfigured = getPluginParameter( pluginId, "source" );
158 String targetConfigured = getPluginParameter( pluginId, "target" );
159
160 String forkFlag = getPluginParameter( pluginId, "fork" );
161 String compilerVersionConfigured = null;
162 if ( "true".equalsIgnoreCase( forkFlag ) )
163 {
164 compilerVersionConfigured = getPluginParameter( pluginId, "compilerVersion" );
165 }
166
167 String minimumJavaVersion = compilerVersionConfigured;
168 if ( targetConfigured != null )
169 {
170 minimumJavaVersion = targetConfigured;
171 }
172 else if ( sourceConfigured != null )
173 {
174 minimumJavaVersion = sourceConfigured;
175 }
176 else
177 {
178
179
180 }
181
182 return minimumJavaVersion;
183 }
184
185 private void tableRowWithLink( String[] content )
186 {
187 sink.tableRow();
188
189 for ( int ctr = 0; ctr < content.length; ctr++ )
190 {
191 String cell = content[ctr];
192
193 sink.tableCell();
194
195 if ( StringUtils.isEmpty( cell ) )
196 {
197 sink.text( "-" );
198 }
199 else if ( ctr == content.length - 1 && cell.length() > 0 )
200 {
201 sink.link( cell );
202 sink.text( cell );
203 sink.link_();
204 }
205 else
206 {
207 sink.text( cell );
208 }
209 sink.tableCell_();
210 }
211
212 sink.tableRow_();
213 }
214
215
216
217
218
219
220
221 private boolean isJavaProject( MavenProject project )
222 {
223 String packaging = project.getPackaging().trim().toLowerCase( Locale.ENGLISH );
224 if ( packaging.equals( "pom" ) )
225 {
226 return false;
227 }
228
229
230 if ( packaging.equals( "jar" ) || packaging.equals( "ear" ) || packaging.equals( "war" )
231 || packaging.equals( "rar" ) || packaging.equals( "sar" ) || packaging.equals( "har" )
232 || packaging.equals( "par" ) || packaging.equals( "ejb" ) )
233 {
234 return true;
235 }
236
237
238 final File sourceDir = new File( project.getBuild().getSourceDirectory() );
239 if ( sourceDir.exists() )
240 {
241 try
242 {
243 if ( FileUtils.getFileNames( sourceDir, "**/*.java", null, false ).size() > 0 )
244 {
245 return true;
246 }
247 }
248 catch ( IOException e )
249 {
250
251 }
252 }
253
254
255 Xpp3Dom pluginConfig =
256 project.getGoalConfiguration( "org.apache.maven.plugins", "maven-compiler-plugin", null, null );
257 if ( pluginConfig != null )
258 {
259 return true;
260 }
261
262 return false;
263 }
264 }
265 }