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