Browse Source

Inject GlobalCommandParser, and tidying up.

Rename ActionFactory methods to be consistent with @Factory-generated ones.

Change-Id: Iafd20682f2fb0a166c6d7502443b56c3263da85d
Depends-On: Ifa75714ab3445634e61df3d99792cdef602d319e
Reviewed-on: http://gerrit.dmdirc.com/2899
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
9591bda084

+ 1
- 1
ivy.xml View File

18
         <dependency org="ch.qos.logback" name="logback-classic" rev="1.+" conf="test->default" />
18
         <dependency org="ch.qos.logback" name="logback-classic" rev="1.+" conf="test->default" />
19
 
19
 
20
         <dependency org="org.projectlombok" name="lombok" rev="latest.integration" conf="main->default" />
20
         <dependency org="org.projectlombok" name="lombok" rev="latest.integration" conf="main->default" />
21
-        <dependency org="com.dmdirc" name="annotations" rev="[0.3.2,)" conf="main->default" />
21
+        <dependency org="com.dmdirc" name="annotations" rev="[0.3.4,)" conf="main->default" />
22
 
22
 
23
         <dependency org="com.squareup.dagger" name="dagger" rev="1.1.+" conf="main->default" />
23
         <dependency org="com.squareup.dagger" name="dagger" rev="1.1.+" conf="main->default" />
24
         <dependency org="com.squareup.dagger" name="dagger-compiler" rev="1.1.+" conf="main->default" />
24
         <dependency org="com.squareup.dagger" name="dagger-compiler" rev="1.1.+" conf="main->default" />

+ 7
- 9
src/com/dmdirc/GlobalWindow.java View File

26
 import com.dmdirc.commandparser.CommandType;
26
 import com.dmdirc.commandparser.CommandType;
27
 import com.dmdirc.commandparser.parsers.CommandParser;
27
 import com.dmdirc.commandparser.parsers.CommandParser;
28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
-import com.dmdirc.interfaces.CommandController;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
30
 import com.dmdirc.interfaces.config.ConfigChangeListener;
32
 import com.dmdirc.messages.MessageSinkManager;
31
 import com.dmdirc.messages.MessageSinkManager;
119
         private final AggregateConfigProvider globalConfig;
118
         private final AggregateConfigProvider globalConfig;
120
         /** The factory to use to create tab completers. */
119
         /** The factory to use to create tab completers. */
121
         private final TabCompleterFactory tabCompleterFactory;
120
         private final TabCompleterFactory tabCompleterFactory;
122
-        /** The provider to use to retrieve a command controller. */
123
-        private final Provider<CommandController> commandControllerProvider;
124
         /** The provider to use to retrieve a window manager. */
121
         /** The provider to use to retrieve a window manager. */
125
         private final Provider<WindowManager> windowManagerProvider;
122
         private final Provider<WindowManager> windowManagerProvider;
126
         /** The provider to use to retrieve message sink managers. */
123
         /** The provider to use to retrieve message sink managers. */
127
         private final Provider<MessageSinkManager> messageSinkManagerProvider;
124
         private final Provider<MessageSinkManager> messageSinkManagerProvider;
125
+        /** The provider to use to retrieve a global command parser. */
126
+        private final Provider<GlobalCommandParser> globalCommandParserProvider;
128
 
127
 
129
         /**
128
         /**
130
          * Creates a new instance of {@link GlobalWindowManager}.
129
          * Creates a new instance of {@link GlobalWindowManager}.
131
          *
130
          *
132
          * @param globalConfig Configuration provider to read settings from.
131
          * @param globalConfig Configuration provider to read settings from.
133
          * @param tabCompleterFactory Factory to use to create tab completers.
132
          * @param tabCompleterFactory Factory to use to create tab completers.
134
-         * @param commandControllerProvider The provider to use to retrieve a command controller.
135
          * @param windowManagerProvider The provider to use to retrieve a window manager.
133
          * @param windowManagerProvider The provider to use to retrieve a window manager.
136
          * @param messageSinkManagerProvider The provider to use to retrieve a sink manager.
134
          * @param messageSinkManagerProvider The provider to use to retrieve a sink manager.
135
+         * @param globalCommandParserProvider The provider to use to retrieve a global command parser.
137
          */
136
          */
138
         @Inject
137
         @Inject
139
         public GlobalWindowManager(
138
         public GlobalWindowManager(
140
                 @GlobalConfig final AggregateConfigProvider globalConfig,
139
                 @GlobalConfig final AggregateConfigProvider globalConfig,
141
                 final TabCompleterFactory tabCompleterFactory,
140
                 final TabCompleterFactory tabCompleterFactory,
142
-                final Provider<CommandController> commandControllerProvider,
143
                 final Provider<WindowManager> windowManagerProvider,
141
                 final Provider<WindowManager> windowManagerProvider,
144
-                final Provider<MessageSinkManager> messageSinkManagerProvider) {
142
+                final Provider<MessageSinkManager> messageSinkManagerProvider,
143
+                final Provider<GlobalCommandParser> globalCommandParserProvider) {
145
             this.globalConfig = globalConfig;
144
             this.globalConfig = globalConfig;
146
             this.tabCompleterFactory = tabCompleterFactory;
145
             this.tabCompleterFactory = tabCompleterFactory;
147
-            this.commandControllerProvider = commandControllerProvider;
148
             this.windowManagerProvider = windowManagerProvider;
146
             this.windowManagerProvider = windowManagerProvider;
149
             this.messageSinkManagerProvider = messageSinkManagerProvider;
147
             this.messageSinkManagerProvider = messageSinkManagerProvider;
148
+            this.globalCommandParserProvider = globalCommandParserProvider;
150
         }
149
         }
151
 
150
 
152
         /** {@inheritDoc} */
151
         /** {@inheritDoc} */
172
                 if (globalConfig.getOptionBool("general", "showglobalwindow")) {
171
                 if (globalConfig.getOptionBool("general", "showglobalwindow")) {
173
                     if (globalWindow == null) {
172
                     if (globalWindow == null) {
174
                         globalWindow = new GlobalWindow(globalConfig,
173
                         globalWindow = new GlobalWindow(globalConfig,
175
-                                new GlobalCommandParser(globalConfig,
176
-                                commandControllerProvider.get()),
174
+                                globalCommandParserProvider.get(),
177
                                 tabCompleterFactory,
175
                                 tabCompleterFactory,
178
                                 messageSinkManagerProvider.get());
176
                                 messageSinkManagerProvider.get());
179
                         windowManagerProvider.get().addWindow(globalWindow);
177
                         windowManagerProvider.get().addWindow(globalWindow);

+ 9
- 2
src/com/dmdirc/actions/Action.java View File

22
 
22
 
23
 package com.dmdirc.actions;
23
 package com.dmdirc.actions;
24
 
24
 
25
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
25
 import com.dmdirc.config.prefs.PreferencesSetting;
26
 import com.dmdirc.config.prefs.PreferencesSetting;
26
 import com.dmdirc.config.prefs.PreferencesType;
27
 import com.dmdirc.config.prefs.PreferencesType;
27
 import com.dmdirc.interfaces.ActionController;
28
 import com.dmdirc.interfaces.ActionController;
44
 import java.util.List;
45
 import java.util.List;
45
 import java.util.Map;
46
 import java.util.Map;
46
 
47
 
48
+import javax.inject.Provider;
49
+
47
 /**
50
 /**
48
  * Describes a single action.
51
  * Describes a single action.
49
  */
52
  */
81
      * Creates a new instance of Action. The group and name specified must
84
      * Creates a new instance of Action. The group and name specified must
82
      * be the group and name of a valid action already saved to disk.
85
      * be the group and name of a valid action already saved to disk.
83
      *
86
      *
87
+     * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
84
      * @param actionController The controller that owns this action.
88
      * @param actionController The controller that owns this action.
85
      * @param identityController The controller to use to retrieve and update settings.
89
      * @param identityController The controller to use to retrieve and update settings.
86
      * @param actionsDirectory The base directory to store actions in.
90
      * @param actionsDirectory The base directory to store actions in.
88
      * @param name The name of the action
92
      * @param name The name of the action
89
      */
93
      */
90
     public Action(
94
     public Action(
95
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
91
             final ActionController actionController,
96
             final ActionController actionController,
92
             final IdentityController identityController,
97
             final IdentityController identityController,
93
             final String actionsDirectory,
98
             final String actionsDirectory,
94
             final String group,
99
             final String group,
95
             final String name) {
100
             final String name) {
96
-        super(group, name);
101
+        super(globalCommandParserProvider, group, name);
97
 
102
 
98
         this.actionController = actionController;
103
         this.actionController = actionController;
99
         this.identityController = identityController;
104
         this.identityController = identityController;
120
      * Creates a new instance of Action with the specified properties and saves
125
      * Creates a new instance of Action with the specified properties and saves
121
      * it to disk.
126
      * it to disk.
122
      *
127
      *
128
+     * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
123
      * @param actionController The controller that owns this action.
129
      * @param actionController The controller that owns this action.
124
      * @param identityController The controller to use to retrieve and update settings.
130
      * @param identityController The controller to use to retrieve and update settings.
125
      * @param actionsDirectory The base directory to store actions in.
131
      * @param actionsDirectory The base directory to store actions in.
132
      * @param newFormat The new formatter to use
138
      * @param newFormat The new formatter to use
133
      */
139
      */
134
     public Action(
140
     public Action(
141
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
135
             final ActionController actionController,
142
             final ActionController actionController,
136
             final IdentityController identityController,
143
             final IdentityController identityController,
137
             final String actionsDirectory,
144
             final String actionsDirectory,
142
             final List<ActionCondition> conditions,
149
             final List<ActionCondition> conditions,
143
             final ConditionTree conditionTree,
150
             final ConditionTree conditionTree,
144
             final String newFormat) {
151
             final String newFormat) {
145
-        super(group, name, triggers, response, conditions, conditionTree, newFormat);
152
+        super(globalCommandParserProvider, group, name, triggers, response, conditions, conditionTree, newFormat);
146
 
153
 
147
         this.actionController = actionController;
154
         this.actionController = actionController;
148
         this.identityController = identityController;
155
         this.identityController = identityController;

+ 12
- 23
src/com/dmdirc/actions/ActionFactory.java View File

24
 
24
 
25
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
25
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
26
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
26
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
27
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
27
 import com.dmdirc.interfaces.ActionController;
28
 import com.dmdirc.interfaces.ActionController;
28
 import com.dmdirc.interfaces.actions.ActionType;
29
 import com.dmdirc.interfaces.actions.ActionType;
29
 import com.dmdirc.interfaces.config.IdentityController;
30
 import com.dmdirc.interfaces.config.IdentityController;
40
 @Singleton
41
 @Singleton
41
 public class ActionFactory {
42
 public class ActionFactory {
42
 
43
 
44
+    /** Provider of global command parsers. */
45
+    private final Provider<GlobalCommandParser> globalCommandParserProvider;
43
     /** The controller that will own actions. */
46
     /** The controller that will own actions. */
44
     private final Provider<ActionController> actionController;
47
     private final Provider<ActionController> actionController;
45
     /** The controller to use to retrieve and update settings. */
48
     /** The controller to use to retrieve and update settings. */
52
      *
55
      *
53
      * @param actionController The controller that will own actions.
56
      * @param actionController The controller that will own actions.
54
      * @param identityController The controller to use to retrieve and update settings.
57
      * @param identityController The controller to use to retrieve and update settings.
58
+     * @param globalCommandParserProvider The global command parser to use for actions without windows.
55
      * @param actionsDirectory The base directory to store actions in.
59
      * @param actionsDirectory The base directory to store actions in.
56
      */
60
      */
57
     @Inject
61
     @Inject
58
     public ActionFactory(
62
     public ActionFactory(
59
             final Provider<ActionController> actionController,
63
             final Provider<ActionController> actionController,
60
             final Provider<IdentityController> identityController,
64
             final Provider<IdentityController> identityController,
65
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
61
             @Directory(DirectoryType.ACTIONS) final String actionsDirectory) {
66
             @Directory(DirectoryType.ACTIONS) final String actionsDirectory) {
62
         this.actionController = actionController;
67
         this.actionController = actionController;
63
         this.identityController = identityController;
68
         this.identityController = identityController;
69
+        this.globalCommandParserProvider = globalCommandParserProvider;
64
         this.actionsDirectory = actionsDirectory;
70
         this.actionsDirectory = actionsDirectory;
65
     }
71
     }
66
 
72
 
72
      * @param name The name of the action
78
      * @param name The name of the action
73
      * @return A relevant action.
79
      * @return A relevant action.
74
      */
80
      */
75
-    public Action create(final String group, final String name) {
76
-        return new Action(actionController.get(), identityController.get(), actionsDirectory, group, name);
77
-    }
78
-
79
-    /**
80
-     * Creates a new instance of Action with the specified properties and saves
81
-     * it to disk.
82
-     *
83
-     * @param group The group the action belongs to
84
-     * @param name The name of the action
85
-     * @param triggers The triggers to use
86
-     * @param response The response to use
87
-     * @param conditions The conditions to use
88
-     * @param newFormat The new formatter to use
89
-     * @return A relevant action.
90
-     */
91
-    public Action create(final String group, final String name,
92
-            final ActionType[] triggers, final String[] response,
93
-            final List<ActionCondition> conditions, final String newFormat) {
94
-        return create(group, name, triggers, response, conditions,
95
-                ConditionTree.createConjunction(conditions.size()), newFormat);
81
+    public Action getAction(final String group, final String name) {
82
+        return new Action(globalCommandParserProvider, actionController.get(),
83
+                identityController.get(), actionsDirectory, group, name);
96
     }
84
     }
97
 
85
 
98
     /**
86
     /**
108
      * @param newFormat The new formatter to use
96
      * @param newFormat The new formatter to use
109
      * @return A relevant action.
97
      * @return A relevant action.
110
      */
98
      */
111
-    public Action create(final String group, final String name,
99
+    public Action getAction(final String group, final String name,
112
             final ActionType[] triggers, final String[] response,
100
             final ActionType[] triggers, final String[] response,
113
             final List<ActionCondition> conditions,
101
             final List<ActionCondition> conditions,
114
             final ConditionTree conditionTree, final String newFormat) {
102
             final ConditionTree conditionTree, final String newFormat) {
115
-        return new Action(actionController.get(), identityController.get(), actionsDirectory, group,
103
+        return new Action(globalCommandParserProvider, actionController.get(),
104
+                identityController.get(), actionsDirectory, group,
116
                 name, triggers, response, conditions, conditionTree, newFormat);
105
                 name, triggers, response, conditions, conditionTree, newFormat);
117
     }
106
     }
118
 
107
 

+ 1
- 1
src/com/dmdirc/actions/ActionManager.java View File

317
         }
317
         }
318
 
318
 
319
         for (File file : dir.listFiles()) {
319
         for (File file : dir.listFiles()) {
320
-            factory.create(dir.getName(), file.getName());
320
+            factory.getAction(dir.getName(), file.getName());
321
         }
321
         }
322
     }
322
     }
323
 
323
 

+ 17
- 7
src/com/dmdirc/actions/ActionModel.java View File

25
 import com.dmdirc.Precondition;
25
 import com.dmdirc.Precondition;
26
 import com.dmdirc.ServerManager;
26
 import com.dmdirc.ServerManager;
27
 import com.dmdirc.WritableFrameContainer;
27
 import com.dmdirc.WritableFrameContainer;
28
-import com.dmdirc.commandparser.CommandManager;
29
 import com.dmdirc.commandparser.parsers.CommandParser;
28
 import com.dmdirc.commandparser.parsers.CommandParser;
30
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
31
-import com.dmdirc.config.IdentityManager;
32
 import com.dmdirc.interfaces.actions.ActionType;
30
 import com.dmdirc.interfaces.actions.ActionType;
33
 
31
 
34
 import java.util.ArrayList;
32
 import java.util.ArrayList;
35
 import java.util.Arrays;
33
 import java.util.Arrays;
36
 import java.util.List;
34
 import java.util.List;
37
 
35
 
36
+import javax.inject.Provider;
37
+
38
 /**
38
 /**
39
  * Represents the basic model of an action, and its triggering mechanism.
39
  * Represents the basic model of an action, and its triggering mechanism.
40
  * Saving and loading are handled by the Action class.
40
  * Saving and loading are handled by the Action class.
41
  */
41
  */
42
 public class ActionModel {
42
 public class ActionModel {
43
 
43
 
44
+    /** Provider of global command parsers, for use when triggering window-less actions. */
45
+    private final Provider<GlobalCommandParser> globalCommandParserProvider;
46
+
44
     /** The group this action belongs to. */
47
     /** The group this action belongs to. */
45
     protected String group;
48
     protected String group;
46
 
49
 
83
     /**
86
     /**
84
      * Creates a new instance of ActionModel with the specified properties.
87
      * Creates a new instance of ActionModel with the specified properties.
85
      *
88
      *
89
+     * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
86
      * @param group The group the action belongs to
90
      * @param group The group the action belongs to
87
      * @param name The name of the action
91
      * @param name The name of the action
88
      */
92
      */
89
-    public ActionModel(final String group, final String name) {
93
+    public ActionModel(
94
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
95
+            final String group,
96
+            final String name) {
97
+        this.globalCommandParserProvider = globalCommandParserProvider;
90
         this.group = group;
98
         this.group = group;
91
         this.name = name;
99
         this.name = name;
92
     }
100
     }
94
     /**
102
     /**
95
      * Creates a new instance of ActionModel with the specified properties.
103
      * Creates a new instance of ActionModel with the specified properties.
96
      *
104
      *
105
+     * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
97
      * @param group The group the action belongs to
106
      * @param group The group the action belongs to
98
      * @param name The name of the action
107
      * @param name The name of the action
99
      * @param triggers The triggers to use
108
      * @param triggers The triggers to use
102
      * @param conditionTree The condition tree to use
111
      * @param conditionTree The condition tree to use
103
      * @param newFormat The new formatter to use
112
      * @param newFormat The new formatter to use
104
      */
113
      */
105
-    public ActionModel(final String group, final String name,
114
+    public ActionModel(
115
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
116
+            final String group, final String name,
106
             final ActionType[] triggers, final String[] response,
117
             final ActionType[] triggers, final String[] response,
107
             final List<ActionCondition> conditions,
118
             final List<ActionCondition> conditions,
108
             final ConditionTree conditionTree, final String newFormat) {
119
             final ConditionTree conditionTree, final String newFormat) {
109
-        this(group, name);
120
+        this(globalCommandParserProvider, group, name);
110
         this.triggers = triggers.clone();
121
         this.triggers = triggers.clone();
111
         this.response = response.clone();
122
         this.response = response.clone();
112
         this.conditions = conditions;
123
         this.conditions = conditions;
154
         }
165
         }
155
 
166
 
156
         if (container == null) {
167
         if (container == null) {
157
-            cp = new GlobalCommandParser(IdentityManager.getIdentityManager()
158
-                    .getGlobalConfiguration(), CommandManager.getCommandManager());
168
+            cp = globalCommandParserProvider.get();
159
         } else {
169
         } else {
160
             cp = container.getCommandParser();
170
             cp = container.getCommandParser();
161
         }
171
         }

+ 3
- 1
src/com/dmdirc/actions/wrappers/Alias.java View File

25
 import com.dmdirc.actions.Action;
25
 import com.dmdirc.actions.Action;
26
 import com.dmdirc.actions.ActionCondition;
26
 import com.dmdirc.actions.ActionCondition;
27
 import com.dmdirc.actions.ActionFactory;
27
 import com.dmdirc.actions.ActionFactory;
28
+import com.dmdirc.actions.ConditionTree;
28
 import com.dmdirc.actions.CoreActionComparison;
29
 import com.dmdirc.actions.CoreActionComparison;
29
 import com.dmdirc.actions.CoreActionComponent;
30
 import com.dmdirc.actions.CoreActionComponent;
30
 import com.dmdirc.actions.CoreActionType;
31
 import com.dmdirc.actions.CoreActionType;
231
      * @return A new action for this alias.
232
      * @return A new action for this alias.
232
      */
233
      */
233
     public Action createAction() {
234
     public Action createAction() {
234
-        return actionFactory.create(
235
+        return actionFactory.getAction(
235
                 AliasWrapper.GROUP_NAME,
236
                 AliasWrapper.GROUP_NAME,
236
                 getName(),
237
                 getName(),
237
                 new ActionType[] {CoreActionType.UNKNOWN_COMMAND, },
238
                 new ActionType[] {CoreActionType.UNKNOWN_COMMAND, },
238
                 getResponse(),
239
                 getResponse(),
239
                 getArguments(),
240
                 getArguments(),
241
+                ConditionTree.createConjunction(getArguments().size()),
240
                 "");
242
                 "");
241
     }
243
     }
242
 
244
 

+ 4
- 2
src/com/dmdirc/actions/wrappers/PerformWrapper.java View File

29
 import com.dmdirc.actions.ActionFactory;
29
 import com.dmdirc.actions.ActionFactory;
30
 import com.dmdirc.actions.ActionGroup;
30
 import com.dmdirc.actions.ActionGroup;
31
 import com.dmdirc.actions.ActionManager;
31
 import com.dmdirc.actions.ActionManager;
32
+import com.dmdirc.actions.ConditionTree;
32
 import com.dmdirc.actions.CoreActionComparison;
33
 import com.dmdirc.actions.CoreActionComparison;
33
 import com.dmdirc.actions.CoreActionComponent;
34
 import com.dmdirc.actions.CoreActionComponent;
34
 import com.dmdirc.actions.CoreActionType;
35
 import com.dmdirc.actions.CoreActionType;
233
                     CoreActionComparison.STRING_EQUALS, profile));
234
                     CoreActionComparison.STRING_EQUALS, profile));
234
         }
235
         }
235
 
236
 
236
-        return actionFactory.create(getName(), server + network
237
+        return actionFactory.getAction(getName(), server + network
237
                 + (profile == null ? "" : " - " + profile),
238
                 + (profile == null ? "" : " - " + profile),
238
                 new ActionType[]{CoreActionType.SERVER_CONNECTED},
239
                 new ActionType[]{CoreActionType.SERVER_CONNECTED},
239
-                new String[0], conditions, null);
240
+                new String[0], conditions,
241
+                ConditionTree.createConjunction(conditions.size()), null);
240
     }
242
     }
241
 
243
 
242
     /**
244
     /**

+ 11
- 2
src/com/dmdirc/commandparser/commands/global/Ifplugin.java View File

39
 import com.dmdirc.ui.input.TabCompleter;
39
 import com.dmdirc.ui.input.TabCompleter;
40
 
40
 
41
 import javax.inject.Inject;
41
 import javax.inject.Inject;
42
+import javax.inject.Provider;
42
 
43
 
43
 /**
44
 /**
44
  * The if plugin command allows the user to execute commands based on whether
45
  * The if plugin command allows the user to execute commands based on whether
55
     /** The plugin manager to use to query plugins. */
56
     /** The plugin manager to use to query plugins. */
56
     private final PluginManager pluginManager;
57
     private final PluginManager pluginManager;
57
 
58
 
59
+    /** Provider of global command parsers. */
60
+    private final Provider<GlobalCommandParser> globalCommandParserProvider;
61
+
58
     /**
62
     /**
59
      * Creates a new instance of the {@link Ifplugin} command.
63
      * Creates a new instance of the {@link Ifplugin} command.
60
      *
64
      *
61
      * @param controller The controller to use for command information.
65
      * @param controller The controller to use for command information.
62
      * @param pluginManager The plugin manager to use to query plugins.
66
      * @param pluginManager The plugin manager to use to query plugins.
67
+     * @param globalCommandParserProvider Provider to use to retrieve a global command parser.
63
      */
68
      */
64
     @Inject
69
     @Inject
65
-    public Ifplugin(final CommandController controller, final PluginManager pluginManager) {
70
+    public Ifplugin(
71
+            final CommandController controller,
72
+            final PluginManager pluginManager,
73
+            final Provider<GlobalCommandParser> globalCommandParserProvider) {
66
         super(controller);
74
         super(controller);
67
         this.pluginManager = pluginManager;
75
         this.pluginManager = pluginManager;
76
+        this.globalCommandParserProvider = globalCommandParserProvider;
68
     }
77
     }
69
 
78
 
70
     /** {@inheritDoc} */
79
     /** {@inheritDoc} */
90
 
99
 
91
         if (result != negative) {
100
         if (result != negative) {
92
             if (origin == null) {
101
             if (origin == null) {
93
-                new GlobalCommandParser(origin.getConfigManager(), getController())
102
+                globalCommandParserProvider.get()
94
                         .parseCommand(null, args.getArgumentsAsString(1));
103
                         .parseCommand(null, args.getArgumentsAsString(1));
95
             } else {
104
             } else {
96
                 ((WritableFrameContainer) origin).getCommandParser()
105
                 ((WritableFrameContainer) origin).getCommandParser()

+ 8
- 1
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java View File

22
 
22
 
23
 package com.dmdirc.commandparser.parsers;
23
 package com.dmdirc.commandparser.parsers;
24
 
24
 
25
+import com.dmdirc.ClientModule;
25
 import com.dmdirc.FrameContainer;
26
 import com.dmdirc.FrameContainer;
26
 import com.dmdirc.commandparser.CommandArguments;
27
 import com.dmdirc.commandparser.CommandArguments;
27
 import com.dmdirc.commandparser.CommandInfo;
28
 import com.dmdirc.commandparser.CommandInfo;
33
 import com.dmdirc.logger.ErrorLevel;
34
 import com.dmdirc.logger.ErrorLevel;
34
 import com.dmdirc.logger.Logger;
35
 import com.dmdirc.logger.Logger;
35
 
36
 
37
+import javax.inject.Inject;
38
+import javax.inject.Singleton;
39
+
36
 /**
40
 /**
37
  * The command parser used for global commands.
41
  * The command parser used for global commands.
38
  */
42
  */
43
+@Singleton
39
 public class GlobalCommandParser extends CommandParser {
44
 public class GlobalCommandParser extends CommandParser {
40
 
45
 
41
     /**
46
     /**
51
      * @param configManager Config manager to read settings from
56
      * @param configManager Config manager to read settings from
52
      * @param commandManager Command manager to load commands from
57
      * @param commandManager Command manager to load commands from
53
      */
58
      */
54
-    public GlobalCommandParser(final AggregateConfigProvider configManager,
59
+    @Inject
60
+    public GlobalCommandParser(
61
+            @ClientModule.GlobalConfig final AggregateConfigProvider configManager,
55
             final CommandController commandManager) {
62
             final CommandController commandManager) {
56
         super(configManager, commandManager);
63
         super(configManager, commandManager);
57
     }
64
     }

+ 11
- 8
test/com/dmdirc/actions/ActionModelTest.java View File

22
 
22
 
23
 package com.dmdirc.actions;
23
 package com.dmdirc.actions;
24
 
24
 
25
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
25
 import com.dmdirc.interfaces.ActionController;
26
 import com.dmdirc.interfaces.ActionController;
26
 import com.dmdirc.interfaces.actions.ActionType;
27
 import com.dmdirc.interfaces.actions.ActionType;
27
 
28
 
29
 import java.util.Arrays;
30
 import java.util.Arrays;
30
 import java.util.List;
31
 import java.util.List;
31
 
32
 
33
+import javax.inject.Provider;
32
 import org.junit.Test;
34
 import org.junit.Test;
33
 import org.junit.runner.RunWith;
35
 import org.junit.runner.RunWith;
34
 import org.mockito.Mock;
36
 import org.mockito.Mock;
39
 @RunWith(MockitoJUnitRunner.class)
41
 @RunWith(MockitoJUnitRunner.class)
40
 public class ActionModelTest {
42
 public class ActionModelTest {
41
 
43
 
44
+    @Mock private Provider<GlobalCommandParser> gcpProvider;
42
     @Mock private ActionController actionController;
45
     @Mock private ActionController actionController;
43
 
46
 
44
     @Test
47
     @Test
45
     public void testConditions() {
48
     public void testConditions() {
46
-        final ActionModel model = new ActionModel("group", "name");
49
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
47
 
50
 
48
         assertTrue("ActionModel must start with no conditions",
51
         assertTrue("ActionModel must start with no conditions",
49
                 model.getConditions().isEmpty());
52
                 model.getConditions().isEmpty());
58
 
61
 
59
     @Test
62
     @Test
60
     public void testTriggers() {
63
     public void testTriggers() {
61
-        final ActionModel model = new ActionModel("group", "name");
64
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
62
 
65
 
63
         assertNull("ActionModel must start with null triggers",
66
         assertNull("ActionModel must start with null triggers",
64
                 model.getTriggers());
67
                 model.getTriggers());
73
 
76
 
74
     @Test
77
     @Test
75
     public void testNewFormat() {
78
     public void testNewFormat() {
76
-        final ActionModel model = new ActionModel("group", "name");
79
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
77
 
80
 
78
         assertNull("ActionModel must start with null format",
81
         assertNull("ActionModel must start with null format",
79
                 model.getNewFormat());
82
                 model.getNewFormat());
91
 
94
 
92
     @Test
95
     @Test
93
     public void testResponse() {
96
     public void testResponse() {
94
-        final ActionModel model = new ActionModel("group", "name");
97
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
95
 
98
 
96
         assertNull("ActionModel must start with null response",
99
         assertNull("ActionModel must start with null response",
97
                 model.getResponse());
100
                 model.getResponse());
106
 
109
 
107
     @Test
110
     @Test
108
     public void testGroup() {
111
     public void testGroup() {
109
-        final ActionModel model = new ActionModel("group", "name");
112
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
110
 
113
 
111
         assertEquals("ActionModel constructor must set group",
114
         assertEquals("ActionModel constructor must set group",
112
                 "group", model.getGroup());
115
                 "group", model.getGroup());
119
 
122
 
120
     @Test
123
     @Test
121
     public void testName() {
124
     public void testName() {
122
-        final ActionModel model = new ActionModel("group", "name");
125
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name");
123
 
126
 
124
         assertEquals("ActionModel constructor must set name",
127
         assertEquals("ActionModel constructor must set name",
125
                 "name", model.getName());
128
                 "name", model.getName());
132
 
135
 
133
     @Test
136
     @Test
134
     public void testTest() {
137
     public void testTest() {
135
-        final ActionModel model = new ActionModel("group", "name",
138
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name",
136
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
139
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
137
                 new String[0], Arrays.asList(new ActionCondition[]{
140
                 new String[0], Arrays.asList(new ActionCondition[]{
138
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,
141
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,
152
 
155
 
153
     @Test
156
     @Test
154
     public void testTestNoCondTree() {
157
     public void testTestNoCondTree() {
155
-        final ActionModel model = new ActionModel("group", "name",
158
+        final ActionModel model = new ActionModel(gcpProvider, "group", "name",
156
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
159
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
157
                 new String[0], Arrays.asList(new ActionCondition[]{
160
                 new String[0], Arrays.asList(new ActionCondition[]{
158
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,
161
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,

+ 10
- 6
test/com/dmdirc/actions/ActionTest.java View File

21
  */
21
  */
22
 package com.dmdirc.actions;
22
 package com.dmdirc.actions;
23
 
23
 
24
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
24
 import com.dmdirc.config.prefs.PreferencesSetting;
25
 import com.dmdirc.config.prefs.PreferencesSetting;
25
 import com.dmdirc.config.prefs.PreferencesType;
26
 import com.dmdirc.config.prefs.PreferencesType;
26
 import com.dmdirc.interfaces.ActionController;
27
 import com.dmdirc.interfaces.ActionController;
40
 import java.util.HashMap;
41
 import java.util.HashMap;
41
 import java.util.Map;
42
 import java.util.Map;
42
 
43
 
44
+import javax.inject.Provider;
45
+
43
 import org.junit.After;
46
 import org.junit.After;
44
 import org.junit.Before;
47
 import org.junit.Before;
45
 import org.junit.BeforeClass;
48
 import org.junit.BeforeClass;
54
 @RunWith(MockitoJUnitRunner.class)
57
 @RunWith(MockitoJUnitRunner.class)
55
 public class ActionTest {
58
 public class ActionTest {
56
 
59
 
60
+    @Mock private Provider<GlobalCommandParser> gcpProvider;
57
     @Mock private ActionController actionController;
61
     @Mock private ActionController actionController;
58
     @Mock private ActionGroup actionGroup;
62
     @Mock private ActionGroup actionGroup;
59
     @Mock private IdentityController identityController;
63
     @Mock private IdentityController identityController;
100
 
104
 
101
     @Test
105
     @Test
102
     public void testSave() {
106
     public void testSave() {
103
-        new Action(actionController, identityController, testDirectory,
107
+        new Action(gcpProvider, actionController, identityController, testDirectory,
104
                 "unit-test", "test1", new ActionType[0],
108
                 "unit-test", "test1", new ActionType[0],
105
                 new String[0], new ArrayList<ActionCondition>(),
109
                 new String[0], new ArrayList<ActionCondition>(),
106
                 ConditionTree.createConjunction(0), null);
110
                 ConditionTree.createConjunction(0), null);
111
 
115
 
112
     @Test
116
     @Test
113
     public void testSetGroup() {
117
     public void testSetGroup() {
114
-        Action action = new Action(actionController, identityController, testDirectory,
118
+        Action action = new Action(gcpProvider, actionController, identityController, testDirectory,
115
                 "unit-test", "test1", new ActionType[0],
119
                 "unit-test", "test1", new ActionType[0],
116
                 new String[0], new ArrayList<ActionCondition>(),
120
                 new String[0], new ArrayList<ActionCondition>(),
117
                 ConditionTree.createConjunction(0), null);
121
                 ConditionTree.createConjunction(0), null);
125
 
129
 
126
     @Test
130
     @Test
127
     public void testSetName() {
131
     public void testSetName() {
128
-        Action action = new Action(actionController, identityController, testDirectory,
132
+        Action action = new Action(gcpProvider, actionController, identityController, testDirectory,
129
                 "unit-test", "test1", new ActionType[0],
133
                 "unit-test", "test1", new ActionType[0],
130
                 new String[0], new ArrayList<ActionCondition>(),
134
                 new String[0], new ArrayList<ActionCondition>(),
131
                 ConditionTree.createConjunction(0), null);
135
                 ConditionTree.createConjunction(0), null);
139
 
143
 
140
     @Test
144
     @Test
141
     public void testDelete() {
145
     public void testDelete() {
142
-        Action action = new Action(actionController, identityController, testDirectory,
146
+        Action action = new Action(gcpProvider, actionController, identityController, testDirectory,
143
                 "unit-test", "test1", new ActionType[0],
147
                 "unit-test", "test1", new ActionType[0],
144
                 new String[0], new ArrayList<ActionCondition>(),
148
                 new String[0], new ArrayList<ActionCondition>(),
145
                 ConditionTree.createConjunction(0), null);
149
                 ConditionTree.createConjunction(0), null);
152
 
156
 
153
     @Test
157
     @Test
154
     public void testRead() throws IOException, InvalidConfigFileException {
158
     public void testRead() throws IOException, InvalidConfigFileException {
155
-        Action action = new Action(actionController, identityController, testDirectory,
159
+        Action action = new Action(gcpProvider, actionController, identityController, testDirectory,
156
                 "unit-test", "doesn't_exist");
160
                 "unit-test", "doesn't_exist");
157
         action.config = new ConfigFile(getClass().getResourceAsStream("action1"));
161
         action.config = new ConfigFile(getClass().getResourceAsStream("action1"));
158
         action.config.read();
162
         action.config.read();
170
 
174
 
171
     @Test
175
     @Test
172
     public void testMultipleGroups() throws IOException, InvalidConfigFileException {
176
     public void testMultipleGroups() throws IOException, InvalidConfigFileException {
173
-        Action action = new Action(actionController, identityController, testDirectory,
177
+        Action action = new Action(gcpProvider, actionController, identityController, testDirectory,
174
                 "unit-test", "doesn't_exist");
178
                 "unit-test", "doesn't_exist");
175
         action.config = new ConfigFile(getClass().getResourceAsStream("action_multisettings"));
179
         action.config = new ConfigFile(getClass().getResourceAsStream("action_multisettings"));
176
         action.config.read();
180
         action.config.read();

+ 4
- 1
test/com/dmdirc/commandparser/commands/global/IfpluginTest.java View File

24
 import com.dmdirc.FrameContainer;
24
 import com.dmdirc.FrameContainer;
25
 import com.dmdirc.commandparser.CommandArguments;
25
 import com.dmdirc.commandparser.CommandArguments;
26
 import com.dmdirc.commandparser.commands.context.CommandContext;
26
 import com.dmdirc.commandparser.commands.context.CommandContext;
27
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
27
 import com.dmdirc.interfaces.CommandController;
28
 import com.dmdirc.interfaces.CommandController;
28
 import com.dmdirc.plugins.PluginManager;
29
 import com.dmdirc.plugins.PluginManager;
29
 
30
 
31
+import javax.inject.Provider;
30
 import org.junit.Before;
32
 import org.junit.Before;
31
 import org.junit.Test;
33
 import org.junit.Test;
32
 import org.junit.runner.RunWith;
34
 import org.junit.runner.RunWith;
38
 @RunWith(MockitoJUnitRunner.class)
40
 @RunWith(MockitoJUnitRunner.class)
39
 public class IfpluginTest {
41
 public class IfpluginTest {
40
 
42
 
43
+    @Mock private Provider<GlobalCommandParser> gcpProvider;
41
     @Mock private CommandController controller;
44
     @Mock private CommandController controller;
42
     @Mock private PluginManager pluginManager;
45
     @Mock private PluginManager pluginManager;
43
     @Mock private FrameContainer tiw;
46
     @Mock private FrameContainer tiw;
45
 
48
 
46
     @Before
49
     @Before
47
     public void setUp() {
50
     public void setUp() {
48
-        command = new Ifplugin(controller, pluginManager);
51
+        command = new Ifplugin(controller, pluginManager, gcpProvider);
49
     }
52
     }
50
 
53
 
51
     @Test
54
     @Test

Loading…
Cancel
Save