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