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.util.Arrays;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Locale;
25 import java.util.Set;
26
27 import org.apache.maven.doxia.sink.Sink;
28 import org.apache.maven.model.CiManagement;
29 import org.apache.maven.model.Model;
30 import org.apache.maven.model.Notifier;
31 import org.apache.maven.plugins.annotations.Mojo;
32 import org.apache.maven.reporting.MavenReportException;
33 import org.codehaus.plexus.i18n.I18N;
34
35
36
37
38
39
40
41 @Mojo(name = "ci-management")
42 public class CiManagementReport extends AbstractProjectInfoReport {
43
44
45
46
47 @Override
48 public boolean canGenerateReport() throws MavenReportException {
49 boolean result = super.canGenerateReport();
50 if (result && skipEmptyReport) {
51 CiManagement cim = getProject().getModel().getCiManagement();
52 result = cim != null;
53 }
54
55 return result;
56 }
57
58 @Override
59 public void executeReport(Locale locale) {
60 CiManagementRenderer r =
61 new CiManagementRenderer(getSink(), getProject().getModel(), getI18N(locale), locale);
62
63 r.render();
64 }
65
66
67 public String getOutputName() {
68 return "ci-management";
69 }
70
71 @Override
72 protected String getI18Nsection() {
73 return "ci-management";
74 }
75
76
77
78
79
80
81
82
83 private static class CiManagementRenderer extends AbstractProjectInfoRenderer {
84
85 private static final Set<String> SYSTEMS = new HashSet<>(Arrays.asList(
86 "anthill",
87 "bamboo",
88 "buildforge",
89 "continuum",
90 "cruisecontrol",
91 "github",
92 "hudson",
93 "jenkins",
94 "luntbuild",
95 "teamcity",
96 "travis"));
97
98 private Model model;
99
100 CiManagementRenderer(Sink sink, Model model, I18N i18n, Locale locale) {
101 super(sink, i18n, locale);
102
103 this.model = model;
104 }
105
106 @Override
107 protected String getI18Nsection() {
108 return "ci-management";
109 }
110
111 @Override
112 protected void renderBody() {
113 CiManagement cim = model.getCiManagement();
114 if (cim == null) {
115 startSection(getTitle());
116
117 paragraph(getI18nString("nocim"));
118
119 endSection();
120
121 return;
122 }
123
124 String system = cim.getSystem();
125 String url = cim.getUrl();
126 List<Notifier> notifiers = cim.getNotifiers();
127
128
129 startSection(getI18nString("overview.title"));
130
131 sink.paragraph();
132 linkPatternedText(getIntroForCiManagementSystem(system));
133 sink.paragraph_();
134
135 endSection();
136
137
138 startSection(getI18nString("access"));
139
140 if (!(url == null || url.isEmpty())) {
141 paragraph(getI18nString("url"));
142
143 verbatimLink(url, url);
144 } else {
145 paragraph(getI18nString("nourl"));
146 }
147
148 endSection();
149
150
151 startSection(getI18nString("notifiers.title"));
152
153 if (notifiers == null || notifiers.isEmpty()) {
154 paragraph(getI18nString("notifiers.nolist"));
155 } else {
156 sink.paragraph();
157 sink.text(getI18nString("notifiers.intro"));
158 sink.paragraph_();
159
160 startTable();
161
162 String type = getI18nString("notifiers.column.type");
163 String address = getI18nString("notifiers.column.address");
164 String configuration = getI18nString("notifiers.column.configuration");
165
166 tableHeader(new String[] {type, address, configuration});
167
168 for (Notifier notifier : notifiers) {
169 tableRow(new String[] {
170 notifier.getType(),
171 createLinkPatternedText(notifier.getAddress(), notifier.getAddress()),
172 propertiesToString(notifier.getConfiguration())
173 });
174 }
175
176 endTable();
177 }
178
179 endSection();
180 }
181
182
183
184
185
186
187
188 private String getIntroForCiManagementSystem(String system) {
189 if (system == null || system.isEmpty()) {
190 return getI18nString("general.intro");
191 }
192
193 String systemLowerCase = system.toLowerCase(Locale.ENGLISH);
194
195 for (String systemName : SYSTEMS) {
196 if (systemLowerCase.startsWith(systemName)) {
197 return getI18nString(systemName + ".intro");
198 }
199 }
200
201 return getI18nString("general.intro");
202 }
203 }
204 }