Browse Source

Move loading of core commands out of CommandManager

Change-Id: Id8a9fde29d189e1c3cd025a3b9f30f2b575a7280
Depends-On: I2838ac60f809408480d985123fde9427e1e5f0e4
Reviewed-on: http://gerrit.dmdirc.com/2309
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.6.7rc1
Chris Smith 12 years ago
parent
commit
9ff3b302a6

+ 2
- 1
src/com/dmdirc/Main.java View File

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.commandline.CommandLineParser;
28
+import com.dmdirc.commandparser.CommandLoader;
28 29
 import com.dmdirc.commandparser.CommandManager;
29 30
 import com.dmdirc.config.ConfigManager;
30 31
 import com.dmdirc.config.IdentityManager;
@@ -127,7 +128,7 @@ public final class Main {
127 128
 
128 129
         clp.applySettings();
129 130
 
130
-        CommandManager.getCommandManager().initCommands();
131
+        new CommandLoader().loadCommands(CommandManager.getCommandManager());
131 132
 
132 133
         for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
133 134
             ensureExists(pm, service);

+ 142
- 0
src/com/dmdirc/commandparser/CommandLoader.java View File

@@ -0,0 +1,142 @@
1
+/*
2
+ * Copyright (c) 2006-2012 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.commandparser;
24
+
25
+import com.dmdirc.BasicServerFactory;
26
+import com.dmdirc.commandparser.commands.channel.Ban;
27
+import com.dmdirc.commandparser.commands.channel.Cycle;
28
+import com.dmdirc.commandparser.commands.channel.Invite;
29
+import com.dmdirc.commandparser.commands.channel.KickReason;
30
+import com.dmdirc.commandparser.commands.channel.Mode;
31
+import com.dmdirc.commandparser.commands.channel.Names;
32
+import com.dmdirc.commandparser.commands.channel.Part;
33
+import com.dmdirc.commandparser.commands.channel.SetNickColour;
34
+import com.dmdirc.commandparser.commands.channel.ShowTopic;
35
+import com.dmdirc.commandparser.commands.chat.Me;
36
+import com.dmdirc.commandparser.commands.global.AliasCommand;
37
+import com.dmdirc.commandparser.commands.global.AllServers;
38
+import com.dmdirc.commandparser.commands.global.Clear;
39
+import com.dmdirc.commandparser.commands.global.Echo;
40
+import com.dmdirc.commandparser.commands.global.Exit;
41
+import com.dmdirc.commandparser.commands.global.Help;
42
+import com.dmdirc.commandparser.commands.global.Ifplugin;
43
+import com.dmdirc.commandparser.commands.global.LoadPlugin;
44
+import com.dmdirc.commandparser.commands.global.NewServer;
45
+import com.dmdirc.commandparser.commands.global.Notify;
46
+import com.dmdirc.commandparser.commands.global.OpenWindow;
47
+import com.dmdirc.commandparser.commands.global.ReloadActions;
48
+import com.dmdirc.commandparser.commands.global.ReloadIdentities;
49
+import com.dmdirc.commandparser.commands.global.ReloadPlugin;
50
+import com.dmdirc.commandparser.commands.global.SaveConfig;
51
+import com.dmdirc.commandparser.commands.global.Set;
52
+import com.dmdirc.commandparser.commands.global.UnloadPlugin;
53
+import com.dmdirc.commandparser.commands.server.AllChannels;
54
+import com.dmdirc.commandparser.commands.server.Away;
55
+import com.dmdirc.commandparser.commands.server.Back;
56
+import com.dmdirc.commandparser.commands.server.ChangeServer;
57
+import com.dmdirc.commandparser.commands.server.Ctcp;
58
+import com.dmdirc.commandparser.commands.server.Disconnect;
59
+import com.dmdirc.commandparser.commands.server.Ignore;
60
+import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
61
+import com.dmdirc.commandparser.commands.server.Message;
62
+import com.dmdirc.commandparser.commands.server.Nick;
63
+import com.dmdirc.commandparser.commands.server.Notice;
64
+import com.dmdirc.commandparser.commands.server.OpenQuery;
65
+import com.dmdirc.commandparser.commands.server.Raw;
66
+import com.dmdirc.commandparser.commands.server.RawServerCommand;
67
+import com.dmdirc.commandparser.commands.server.Reconnect;
68
+import com.dmdirc.commandparser.commands.server.Umode;
69
+import com.dmdirc.interfaces.CommandController;
70
+
71
+/**
72
+ * Facilitates loading of core commands into a {@link CommandManager}.
73
+ */
74
+public class CommandLoader {
75
+
76
+    /**
77
+     * Loads all known core commands into the given manager.
78
+     *
79
+     * @param manager The manager to add commands to
80
+     */
81
+    public void loadCommands(final CommandController manager) {
82
+        // Chat commands
83
+        manager.registerCommand(new Me(), Me.INFO);
84
+
85
+        // Channel commands
86
+        manager.registerCommand(new Ban(), Ban.INFO);
87
+        manager.registerCommand(new Cycle(), Cycle.INFO);
88
+        manager.registerCommand(new Invite(), Invite.INFO);
89
+        manager.registerCommand(new KickReason(), KickReason.INFO);
90
+        manager.registerCommand(new Mode(), Mode.INFO);
91
+        manager.registerCommand(new Names(), Names.INFO);
92
+        manager.registerCommand(new Part(), Part.INFO);
93
+        manager.registerCommand(new SetNickColour(), SetNickColour.INFO);
94
+        manager.registerCommand(new ShowTopic(), ShowTopic.INFO);
95
+
96
+        // Server commands
97
+        manager.registerCommand(new AllChannels(), AllChannels.INFO);
98
+        manager.registerCommand(new Away(), Away.INFO);
99
+        manager.registerCommand(new Back(), Back.INFO);
100
+        manager.registerCommand(new ChangeServer(), ChangeServer.INFO);
101
+        manager.registerCommand(new Ctcp(), Ctcp.INFO);
102
+        manager.registerCommand(new Disconnect(), Disconnect.INFO);
103
+        manager.registerCommand(new Ignore(), Ignore.INFO);
104
+        manager.registerCommand(new JoinChannelCommand(), JoinChannelCommand.INFO);
105
+        manager.registerCommand(new Message(), Message.INFO);
106
+        manager.registerCommand(new Nick(), Nick.INFO);
107
+        manager.registerCommand(new Notice(), Notice.INFO);
108
+        manager.registerCommand(new OpenQuery(), OpenQuery.INFO);
109
+        manager.registerCommand(new Raw(), Raw.INFO);
110
+        manager.registerCommand(new Reconnect(), Reconnect.INFO);
111
+        manager.registerCommand(new Umode(), Umode.INFO);
112
+
113
+        manager.registerCommand(new RawServerCommand("lusers"));
114
+        manager.registerCommand(new RawServerCommand("map"));
115
+        manager.registerCommand(new RawServerCommand("motd"));
116
+        manager.registerCommand(new RawServerCommand("oper"));
117
+        manager.registerCommand(new RawServerCommand("whois"));
118
+        manager.registerCommand(new RawServerCommand("who"));
119
+
120
+        // Query commands
121
+
122
+        // Global commands
123
+        manager.registerCommand(new AliasCommand(), AliasCommand.INFO);
124
+        manager.registerCommand(new AllServers(), AllServers.INFO);
125
+        manager.registerCommand(new Clear(), Clear.INFO);
126
+        manager.registerCommand(new Echo(), Echo.INFO);
127
+        manager.registerCommand(new Exit(), Exit.INFO);
128
+        manager.registerCommand(new Help(), Help.INFO);
129
+        manager.registerCommand(new Ifplugin(), Ifplugin.INFO);
130
+        manager.registerCommand(new NewServer(new BasicServerFactory()), NewServer.INFO);
131
+        manager.registerCommand(new Notify(), Notify.INFO);
132
+        manager.registerCommand(new LoadPlugin(), LoadPlugin.INFO);
133
+        manager.registerCommand(new UnloadPlugin(), UnloadPlugin.INFO);
134
+        manager.registerCommand(new OpenWindow(), OpenWindow.INFO);
135
+        manager.registerCommand(new ReloadActions(), ReloadActions.INFO);
136
+        manager.registerCommand(new ReloadIdentities(), ReloadIdentities.INFO);
137
+        manager.registerCommand(new ReloadPlugin(), ReloadPlugin.INFO);
138
+        manager.registerCommand(new SaveConfig(), SaveConfig.INFO);
139
+        manager.registerCommand(new Set(), Set.INFO);
140
+    }
141
+
142
+}

+ 0
- 107
src/com/dmdirc/commandparser/CommandManager.java View File

@@ -22,54 +22,10 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
-import com.dmdirc.BasicServerFactory;
26 25
 import com.dmdirc.Query;
27 26
 import com.dmdirc.Server;
28 27
 import com.dmdirc.ServerManager;
29 28
 import com.dmdirc.commandparser.commands.Command;
30
-import com.dmdirc.commandparser.commands.channel.Ban;
31
-import com.dmdirc.commandparser.commands.channel.Cycle;
32
-import com.dmdirc.commandparser.commands.channel.Invite;
33
-import com.dmdirc.commandparser.commands.channel.KickReason;
34
-import com.dmdirc.commandparser.commands.channel.Mode;
35
-import com.dmdirc.commandparser.commands.channel.Names;
36
-import com.dmdirc.commandparser.commands.channel.Part;
37
-import com.dmdirc.commandparser.commands.channel.SetNickColour;
38
-import com.dmdirc.commandparser.commands.channel.ShowTopic;
39
-import com.dmdirc.commandparser.commands.chat.Me;
40
-import com.dmdirc.commandparser.commands.global.AliasCommand;
41
-import com.dmdirc.commandparser.commands.global.AllServers;
42
-import com.dmdirc.commandparser.commands.global.Clear;
43
-import com.dmdirc.commandparser.commands.global.Echo;
44
-import com.dmdirc.commandparser.commands.global.Exit;
45
-import com.dmdirc.commandparser.commands.global.Help;
46
-import com.dmdirc.commandparser.commands.global.Ifplugin;
47
-import com.dmdirc.commandparser.commands.global.LoadPlugin;
48
-import com.dmdirc.commandparser.commands.global.NewServer;
49
-import com.dmdirc.commandparser.commands.global.Notify;
50
-import com.dmdirc.commandparser.commands.global.OpenWindow;
51
-import com.dmdirc.commandparser.commands.global.ReloadActions;
52
-import com.dmdirc.commandparser.commands.global.ReloadIdentities;
53
-import com.dmdirc.commandparser.commands.global.ReloadPlugin;
54
-import com.dmdirc.commandparser.commands.global.SaveConfig;
55
-import com.dmdirc.commandparser.commands.global.Set;
56
-import com.dmdirc.commandparser.commands.global.UnloadPlugin;
57
-import com.dmdirc.commandparser.commands.server.AllChannels;
58
-import com.dmdirc.commandparser.commands.server.Away;
59
-import com.dmdirc.commandparser.commands.server.Back;
60
-import com.dmdirc.commandparser.commands.server.ChangeServer;
61
-import com.dmdirc.commandparser.commands.server.Ctcp;
62
-import com.dmdirc.commandparser.commands.server.Disconnect;
63
-import com.dmdirc.commandparser.commands.server.Ignore;
64
-import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
65
-import com.dmdirc.commandparser.commands.server.Message;
66
-import com.dmdirc.commandparser.commands.server.Nick;
67
-import com.dmdirc.commandparser.commands.server.Notice;
68
-import com.dmdirc.commandparser.commands.server.OpenQuery;
69
-import com.dmdirc.commandparser.commands.server.Raw;
70
-import com.dmdirc.commandparser.commands.server.RawServerCommand;
71
-import com.dmdirc.commandparser.commands.server.Reconnect;
72
-import com.dmdirc.commandparser.commands.server.Umode;
73 29
 import com.dmdirc.commandparser.parsers.CommandParser;
74 30
 import com.dmdirc.config.ConfigBinding;
75 31
 import com.dmdirc.config.ConfigManager;
@@ -243,69 +199,6 @@ public class CommandManager implements CommandController {
243 199
         }
244 200
     }
245 201
 
246
-    /** {@inheritDoc} */
247
-    @Override
248
-    public void initCommands() {
249
-        // Chat commands
250
-        registerCommand(new Me(), Me.INFO);
251
-
252
-        // Channel commands
253
-        registerCommand(new Ban(), Ban.INFO);
254
-        registerCommand(new Cycle(), Cycle.INFO);
255
-        registerCommand(new Invite(), Invite.INFO);
256
-        registerCommand(new KickReason(), KickReason.INFO);
257
-        registerCommand(new Mode(), Mode.INFO);
258
-        registerCommand(new Names(), Names.INFO);
259
-        registerCommand(new Part(), Part.INFO);
260
-        registerCommand(new SetNickColour(), SetNickColour.INFO);
261
-        registerCommand(new ShowTopic(), ShowTopic.INFO);
262
-
263
-        // Server commands
264
-        registerCommand(new AllChannels(), AllChannels.INFO);
265
-        registerCommand(new Away(), Away.INFO);
266
-        registerCommand(new Back(), Back.INFO);
267
-        registerCommand(new ChangeServer(), ChangeServer.INFO);
268
-        registerCommand(new Ctcp(), Ctcp.INFO);
269
-        registerCommand(new Disconnect(), Disconnect.INFO);
270
-        registerCommand(new Ignore(), Ignore.INFO);
271
-        registerCommand(new JoinChannelCommand(), JoinChannelCommand.INFO);
272
-        registerCommand(new Message(), Message.INFO);
273
-        registerCommand(new Nick(), Nick.INFO);
274
-        registerCommand(new Notice(), Notice.INFO);
275
-        registerCommand(new OpenQuery(), OpenQuery.INFO);
276
-        registerCommand(new Raw(), Raw.INFO);
277
-        registerCommand(new Reconnect(), Reconnect.INFO);
278
-        registerCommand(new Umode(), Umode.INFO);
279
-
280
-        registerCommand(new RawServerCommand("lusers"));
281
-        registerCommand(new RawServerCommand("map"));
282
-        registerCommand(new RawServerCommand("motd"));
283
-        registerCommand(new RawServerCommand("oper"));
284
-        registerCommand(new RawServerCommand("whois"));
285
-        registerCommand(new RawServerCommand("who"));
286
-
287
-        // Query commands
288
-
289
-        // Global commands
290
-        registerCommand(new AliasCommand(), AliasCommand.INFO);
291
-        registerCommand(new AllServers(), AllServers.INFO);
292
-        registerCommand(new Clear(), Clear.INFO);
293
-        registerCommand(new Echo(), Echo.INFO);
294
-        registerCommand(new Exit(), Exit.INFO);
295
-        registerCommand(new Help(), Help.INFO);
296
-        registerCommand(new Ifplugin(), Ifplugin.INFO);
297
-        registerCommand(new NewServer(new BasicServerFactory()), NewServer.INFO);
298
-        registerCommand(new Notify(), Notify.INFO);
299
-        registerCommand(new LoadPlugin(), LoadPlugin.INFO);
300
-        registerCommand(new UnloadPlugin(), UnloadPlugin.INFO);
301
-        registerCommand(new OpenWindow(), OpenWindow.INFO);
302
-        registerCommand(new ReloadActions(), ReloadActions.INFO);
303
-        registerCommand(new ReloadIdentities(), ReloadIdentities.INFO);
304
-        registerCommand(new ReloadPlugin(), ReloadPlugin.INFO);
305
-        registerCommand(new SaveConfig(), SaveConfig.INFO);
306
-        registerCommand(new Set(), Set.INFO);
307
-    }
308
-
309 202
     /** {@inheritDoc} */
310 203
     @Override
311 204
     public void loadCommands(final CommandParser parser,

+ 0
- 5
src/com/dmdirc/interfaces/CommandController.java View File

@@ -85,11 +85,6 @@ public interface CommandController {
85 85
      */
86 86
     char getSilenceChar();
87 87
 
88
-    /**
89
-     * Instansiates the default commands.
90
-     */
91
-    void initCommands();
92
-
93 88
     /**
94 89
      * Determines if the specified command is a valid channel command.
95 90
      *

+ 2
- 1
test/com/dmdirc/commandparser/commands/HelpTest.java View File

@@ -22,6 +22,7 @@
22 22
 package com.dmdirc.commandparser.commands;
23 23
 
24 24
 import com.dmdirc.commandparser.CommandInfo;
25
+import com.dmdirc.commandparser.CommandLoader;
25 26
 import com.dmdirc.commandparser.CommandManager;
26 27
 import com.dmdirc.commandparser.CommandType;
27 28
 import com.dmdirc.config.IdentityManager;
@@ -62,7 +63,7 @@ public class HelpTest {
62 63
         final List<Object[]> res = new LinkedList<Object[]>();
63 64
 
64 65
         IdentityManager.getIdentityManager().initialise();
65
-        CommandManager.getCommandManager().initCommands();
66
+        new CommandLoader().loadCommands(CommandManager.getCommandManager());
66 67
 
67 68
         for (CommandType type : CommandType.values()) {
68 69
             for (CommandInfo command : CommandManager.getCommandManager().getCommands(type).keySet()) {

+ 1
- 1
test/com/dmdirc/commandparser/parsers/CommandParserTest.java View File

@@ -36,7 +36,7 @@ public class CommandParserTest {
36 36
     @BeforeClass
37 37
     public static void setUpClass() throws Exception {
38 38
         IdentityManager.getIdentityManager().initialise();
39
-        CommandManager.getCommandManager().initCommands();
39
+        CommandManager.getCommandManager().registerCommand(new Echo(), Echo.INFO);
40 40
     }
41 41
 
42 42
     @Test

Loading…
Cancel
Save