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