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