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