1616import java .io .IOException ;
1717
1818public class SlackNotificationMainConfig implements ChangeListener {
19- public final String DEFAULT_BOTNAME = "TeamCity" ;
19+ public static final String DEFAULT_BOTNAME = "TeamCity" ;
2020 public static final String DEFAULT_ICONURL = "https://raw.githubusercontent.com/PeteGoo/tcSlackBuildNotifier/master/docs/TeamCity32.png" ;
2121
2222
@@ -38,19 +38,14 @@ public class SlackNotificationMainConfig implements ChangeListener {
3838
3939 public final String SINGLE_HOST_REGEX = "^[^./~`'\" ]+(?:/.*)?$" ;
4040 public final String HOSTNAME_ONLY_REGEX = "^([^/]+)(?:/.*)?$" ;
41- private String iconUrl = DEFAULT_ICONURL ;
42- private String botName = DEFAULT_BOTNAME ;
43- private Boolean showBuildAgent ;
44- private Boolean showElapsedBuildTime ;
45- private Boolean showCommits = true ;
46- private Boolean showCommitters = true ;
47- private int maxCommitsToDisplay = 5 ;
48- private boolean configFileExists ;
41+ private SlackNotificationContentConfig content ;
42+ private boolean configFileExists ;
4943
5044
5145
52- public SlackNotificationMainConfig (ServerPaths serverPaths ) {
5346
47+ public SlackNotificationMainConfig (ServerPaths serverPaths ) {
48+ this .content = new SlackNotificationContentConfig ();
5449 this .myConfigDir = new File (serverPaths .getConfigDir (), "slack" );
5550 this .myConfigFile = new File (this .myConfigDir , "slack-config.xml" );
5651 configFileExists = this .myConfigFile .exists ();
@@ -186,26 +181,6 @@ public void setToken(String token) {
186181 this .token = token ;
187182 }
188183
189- public String getIconUrl ()
190- {
191- return iconUrl ;
192- }
193-
194- public void setIconUrl (String iconUrl )
195- {
196- this .iconUrl = iconUrl ;
197- }
198-
199- public String getBotName ()
200- {
201- return botName ;
202- }
203-
204- public void setBotName (String botName )
205- {
206- this .botName = botName ;
207- }
208-
209184 public Integer getProxyPort () {
210185 return proxyPort ;
211186 }
@@ -279,46 +254,6 @@ public Boolean getSlackNotificationShowFurtherReading() {
279254 }
280255
281256
282- public Boolean getShowBuildAgent () {
283- return showBuildAgent ;
284- }
285-
286- public void setShowBuildAgent (Boolean showBuildAgent ) {
287- this .showBuildAgent = showBuildAgent ;
288- }
289-
290- public Boolean getShowElapsedBuildTime () {
291- return showElapsedBuildTime ;
292- }
293-
294- public void setShowElapsedBuildTime (Boolean showElapsedBuildTime ) {
295- this .showElapsedBuildTime = showElapsedBuildTime ;
296- }
297-
298- public boolean getShowCommits () {
299- return showCommits ;
300- }
301-
302- public void setShowCommits (boolean showCommits ) {
303- this .showCommits = showCommits ;
304- }
305-
306- public boolean getShowCommitters () {
307- return showCommitters ;
308- }
309-
310- public void setShowCommitters (boolean showCommitters ) {
311- this .showCommitters = showCommitters ;
312- }
313-
314- public int getMaxCommitsToDisplay () {
315- return maxCommitsToDisplay ;
316- }
317-
318- public void setMaxCommitsToDisplay (int maxCommitsToDisplay ) {
319- this .maxCommitsToDisplay = maxCommitsToDisplay ;
320- }
321-
322257 public synchronized void save ()
323258 {
324259 this .myChangeObserver .runActionWithDisabledObserver (new Runnable ()
@@ -332,21 +267,21 @@ public void process(Element rootElement) {
332267 rootElement .setAttribute ("defaultChannel" , emptyIfNull (SlackNotificationMainConfig .this .defaultChannel ));
333268 rootElement .setAttribute ("teamName" , emptyIfNull (SlackNotificationMainConfig .this .teamName ));
334269 rootElement .setAttribute ("token" , emptyIfNull (SlackNotificationMainConfig .this .token ));
335- rootElement .setAttribute ("iconurl" , emptyIfNull (SlackNotificationMainConfig .this .iconUrl ));
336- rootElement .setAttribute ("botname" , emptyIfNull (SlackNotificationMainConfig .this .botName ));
337- if (SlackNotificationMainConfig .this .showBuildAgent != null ){
338- rootElement .setAttribute ("showBuildAgent" , Boolean .toString (SlackNotificationMainConfig .this .showBuildAgent ));
270+ rootElement .setAttribute ("iconurl" , emptyIfNull (SlackNotificationMainConfig .this .content . getIconUrl () ));
271+ rootElement .setAttribute ("botname" , emptyIfNull (SlackNotificationMainConfig .this .content . getBotName () ));
272+ if (SlackNotificationMainConfig .this .content . getShowBuildAgent () != null ){
273+ rootElement .setAttribute ("showBuildAgent" , Boolean .toString (SlackNotificationMainConfig .this .content . getShowBuildAgent () ));
339274 }
340- if (SlackNotificationMainConfig .this .showElapsedBuildTime != null ) {
341- rootElement .setAttribute ("showElapsedBuildTime" , Boolean .toString (SlackNotificationMainConfig .this .showElapsedBuildTime ));
275+ if (SlackNotificationMainConfig .this .content . getShowElapsedBuildTime () != null ) {
276+ rootElement .setAttribute ("showElapsedBuildTime" , Boolean .toString (SlackNotificationMainConfig .this .content . getShowElapsedBuildTime () ));
342277 }
343- if (SlackNotificationMainConfig .this .showCommits != null ) {
344- rootElement .setAttribute ("showCommits" , Boolean .toString (SlackNotificationMainConfig .this .showCommits ));
278+ if (SlackNotificationMainConfig .this .content . getShowCommits () != null ) {
279+ rootElement .setAttribute ("showCommits" , Boolean .toString (SlackNotificationMainConfig .this .content . getShowCommits () ));
345280 }
346- if (SlackNotificationMainConfig .this .showCommitters != null ) {
347- rootElement .setAttribute ("showCommitters" , Boolean .toString (SlackNotificationMainConfig .this .showCommitters ));
281+ if (SlackNotificationMainConfig .this .content . getShowCommitters () != null ) {
282+ rootElement .setAttribute ("showCommitters" , Boolean .toString (SlackNotificationMainConfig .this .content . getShowCommitters () ));
348283 }
349- rootElement .setAttribute ("maxCommitsToDisplay" , Integer .toString (SlackNotificationMainConfig .this .maxCommitsToDisplay ));
284+ rootElement .setAttribute ("maxCommitsToDisplay" , Integer .toString (SlackNotificationMainConfig .this .content . getMaxCommitsToDisplay () ));
350285
351286 rootElement .removeChildren ("proxy" );
352287 rootElement .removeChildren ("info" );
@@ -386,6 +321,7 @@ public boolean getConfigFileExists() {
386321
387322 void readConfigurationFromXmlElement (Element slackNotificationsElement ) {
388323 if (slackNotificationsElement != null ){
324+ content .setEnabled (true );
389325 if (slackNotificationsElement .getAttribute ("enabled" ) != null )
390326 {
391327 setEnabled (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("enabled" )));
@@ -404,31 +340,31 @@ void readConfigurationFromXmlElement(Element slackNotificationsElement) {
404340 }
405341 if (slackNotificationsElement .getAttribute ("iconurl" ) != null )
406342 {
407- setIconUrl (slackNotificationsElement .getAttributeValue ("iconurl" ));
343+ content . setIconUrl (slackNotificationsElement .getAttributeValue ("iconurl" ));
408344 }
409345 if (slackNotificationsElement .getAttribute ("botname" ) != null )
410346 {
411- setBotName (slackNotificationsElement .getAttributeValue ("botname" ));
347+ content . setBotName (slackNotificationsElement .getAttributeValue ("botname" ));
412348 }
413349 if (slackNotificationsElement .getAttribute ("showBuildAgent" ) != null )
414350 {
415- setShowBuildAgent (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showBuildAgent" )));
351+ content . setShowBuildAgent (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showBuildAgent" )));
416352 }
417353 if (slackNotificationsElement .getAttribute ("showElapsedBuildTime" ) != null )
418354 {
419- setShowElapsedBuildTime (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showElapsedBuildTime" )));
355+ content . setShowElapsedBuildTime (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showElapsedBuildTime" )));
420356 }
421357 if (slackNotificationsElement .getAttribute ("showCommits" ) != null )
422358 {
423- setShowCommits (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showCommits" )));
359+ content . setShowCommits (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showCommits" )));
424360 }
425361 if (slackNotificationsElement .getAttribute ("showCommitters" ) != null )
426362 {
427- setShowCommitters (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showCommitters" )));
363+ content . setShowCommitters (Boolean .parseBoolean (slackNotificationsElement .getAttributeValue ("showCommitters" )));
428364 }
429365 if (slackNotificationsElement .getAttribute ("maxCommitsToDisplay" ) != null )
430366 {
431- setMaxCommitsToDisplay (Integer .parseInt (slackNotificationsElement .getAttributeValue ("maxCommitsToDisplay" )));
367+ content . setMaxCommitsToDisplay (Integer .parseInt (slackNotificationsElement .getAttributeValue ("maxCommitsToDisplay" )));
432368 }
433369
434370 Element proxyElement = slackNotificationsElement .getChild ("proxy" );
@@ -466,4 +402,8 @@ void readConfigurationFromXmlElement(Element slackNotificationsElement) {
466402 public SlackNotificationProxyConfig getProxyConfig () {
467403 return new SlackNotificationProxyConfig (proxyHost , proxyPort , proxyUsername , proxyPassword );
468404 }
405+
406+ public SlackNotificationContentConfig getContent () {
407+ return content ;
408+ }
469409}
0 commit comments