package org.jenkinsci.backend.ircbot;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.annotation.Nonnull;

/**
 * Stores configurations of {@link IrcBotImpl}.
 * This class has been created to achieve the better IRC Bot flexibility according to INFRA-146.
 * @author Oleg Nenashev <o.v.nenashev@gmail.com>
 */
public class IrcBotConfig {
    
    private static final String varPrefix = "ircbot.";
       
    // General
    /**
     * Name of the bot (up to 16 symbols).
     */
    private static final String DEFAULT_IRCBOT_NAME = ("ircbot-"+System.getProperty("user.name")); 
    static String NAME = System.getProperty(varPrefix+"name", DEFAULT_IRCBOT_NAME);
    static String SERVER = System.getProperty(varPrefix+"server", "irc.freenode.net");
    static final Set<String> DEFAULT_CHANNELS = new HashSet<String>(Arrays.asList("#jenkins","#jenkins-infra"));
    static final String CHANNELS_LIST = System.getProperty(varPrefix+"channels", "#jenkins,#jenkins-infra");
    
    // IRC Hook
    static String IRC_HOOK_NAME = System.getProperty(varPrefix+"ircHook.name", "irc");  
    static String IRC_HOOK_PORT = System.getProperty(varPrefix+"ircHook.port", "6667");
    static String IRC_HOOK_NICK = System.getProperty(varPrefix+"ircHook.nick", "github-jenkins");
    static String IRC_HOOK_PASSWORD = System.getProperty(varPrefix+"ircHook.password", "");
    static String IRC_HOOK_ROOM = System.getProperty(varPrefix+"ircHook.room", "#jenkins-commits");
    static String IRC_HOOK_LONG_URL= System.getProperty(varPrefix+"ircHook.longUrl", "1");
    
    // JIRAs
    static String JIRA_DEFAULT_PROJECT = System.getProperty(varPrefix+"jira.defaultProject", "JENKINS");
    
    // Github
    static String GITHUB_ORGANIZATION = System.getProperty(varPrefix+"github.organization", "jenkinsci");
    static String GITHUB_DEFAULT_TEAM = System.getProperty(varPrefix+"github.defaultTeam", "Everyone");
    static String GITHUB_POST_COMMIT_HOOK_EMAIL = System.getProperty(varPrefix+"github.postCommitHookEmail", "jenkinsci-commits@googlegroups.com");
     
    public static Map<String, String> getIRCHookConfig() {
        
        final Map<String, String> ircHookConfig = new TreeMap<String, String>();
        ircHookConfig.put("server", SERVER);
        ircHookConfig.put("port", IRC_HOOK_PORT);
        ircHookConfig.put("nick", IRC_HOOK_NICK);
        ircHookConfig.put("password", IRC_HOOK_PASSWORD);
        ircHookConfig.put("room", IRC_HOOK_ROOM);
        ircHookConfig.put("long_url", IRC_HOOK_LONG_URL);

        return Collections.unmodifiableMap(ircHookConfig);
    }
    
    public static @Nonnull Set<String> getChannels() {
        HashSet<String> res = new HashSet<String>();
        if (CHANNELS_LIST != null) {
            String[] channels = CHANNELS_LIST.split(",");
            for (String channel : channels) {
                if (channel.startsWith("#")) {
                    res.add(channel);
                }
            }
        }
        return res.isEmpty() ? DEFAULT_CHANNELS : res;
    }
}

@@ -448,21 +448,17 @@
 onfig %7B%0A
-    
 %0A
+
     priv
@@ -504,24 +504,17 @@
 cbot.%22;%0A
-       
 %0A
+
     // G
@@ -677,17 +677,16 @@
 name%22));
- 
 %0A    sta
@@ -1067,29 +1067,25 @@
 ns-infra%22);%0A
-    
 %0A
+
     // IRC H
@@ -1174,18 +1174,16 @@
  %22irc%22);
-  
 %0A    sta
@@ -1640,29 +1640,25 @@
 Url%22, %221%22);%0A
-    
 %0A
+
     // JIRAs
@@ -1763,21 +1763,17 @@
 KINS%22);%0A
-    
 %0A
+
     // G
@@ -2136,22 +2136,17 @@
 .com%22);%0A
-     
 %0A
+
     publ
@@ -2200,17 +2200,9 @@
 ) %7B%0A
-        
 %0A
+
     
@@ -2655,20 +2655,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub

Remove superfluous whitespace