Browse Source

Move more initialisation into dagger.

Fully initialise the PluginManager instead of passing around
one in various states of existance.

Move plugin extraction logic into a CorePluginExtractor class.

Inject UpdateManager where appropriate.

Change-Id: I6c15f7682cccd93b40dcc189a0a8466d067095f0
Reviewed-on: http://gerrit.dmdirc.com/2692
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
7333fc3f2e

+ 162
- 1
src/com/dmdirc/ClientModule.java View File

@@ -26,17 +26,27 @@ import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.commandline.CommandLineOptionsModule;
27 27
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28 28
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
29
+import com.dmdirc.commandline.CommandLineParser;
30
+import com.dmdirc.commandparser.CommandLoader;
31
+import com.dmdirc.commandparser.CommandManager;
32
+import com.dmdirc.config.ConfigManager;
29 33
 import com.dmdirc.config.IdentityManager;
30 34
 import com.dmdirc.config.InvalidIdentityFileException;
31 35
 import com.dmdirc.interfaces.ActionController;
36
+import com.dmdirc.interfaces.CommandController;
32 37
 import com.dmdirc.interfaces.IdentityController;
33 38
 import com.dmdirc.interfaces.LifecycleController;
34 39
 import com.dmdirc.logger.ErrorLevel;
35 40
 import com.dmdirc.logger.Logger;
36 41
 import com.dmdirc.messages.MessageSinkManager;
42
+import com.dmdirc.plugins.PluginInfo;
37 43
 import com.dmdirc.plugins.PluginManager;
38 44
 import com.dmdirc.ui.WarningDialog;
39 45
 import com.dmdirc.ui.core.components.StatusBarManager;
46
+import com.dmdirc.updater.UpdateChecker;
47
+import com.dmdirc.updater.Version;
48
+import com.dmdirc.updater.components.LauncherComponent;
49
+import com.dmdirc.updater.manager.UpdateManager;
40 50
 
41 51
 import java.awt.GraphicsEnvironment;
42 52
 import java.io.File;
@@ -57,12 +67,14 @@ public class ClientModule {
57 67
      * Provides an identity manager for the client.
58 68
      *
59 69
      * @param directory The directory to load settings from.
70
+     * @param commandLineParser The CLI parser to read command line settings from.
60 71
      * @return An initialised {@link IdentityManager}.
61 72
      */
62 73
     @Provides
63 74
     @Singleton
64 75
     public IdentityManager getIdentityManager(
65
-            @Directory(DirectoryType.BASE) final String directory) {
76
+            @Directory(DirectoryType.BASE) final String directory,
77
+            final CommandLineParser commandLineParser) {
66 78
         final IdentityManager identityManager = new IdentityManager(directory);
67 79
         IdentityManager.setIdentityManager(identityManager);
68 80
         identityManager.loadVersionIdentity();
@@ -73,6 +85,11 @@ public class ClientModule {
73 85
             handleInvalidConfigFile(identityManager, directory);
74 86
         }
75 87
 
88
+        if (commandLineParser.getDisableReporting()) {
89
+            identityManager.getGlobalConfigIdentity()
90
+                    .setOption("temp", "noerrorreporting", true);
91
+        }
92
+
76 93
         return identityManager;
77 94
     }
78 95
 
@@ -163,6 +180,103 @@ public class ClientModule {
163 180
         return messageSinkManager;
164 181
     }
165 182
 
183
+    /**
184
+     * Gets the command manager the client should use.
185
+     *
186
+     * @param serverManager The manager to use to iterate servers.
187
+     * @param identityController The controller to use to read settings.
188
+     * @param commandLoader The loader to use to populate default commands.
189
+     * @return The command manager the client should use.
190
+     */
191
+    @Provides
192
+    @Singleton
193
+    public CommandManager getCommandManager(
194
+            final ServerManager serverManager,
195
+            final IdentityController identityController,
196
+            final CommandLoader commandLoader) {
197
+        final CommandManager manager = new CommandManager(serverManager);
198
+        manager.initialise(identityController.getGlobalConfiguration());
199
+        CommandManager.setCommandManager(manager);
200
+        commandLoader.loadCommands(manager);
201
+        return manager;
202
+    }
203
+
204
+    /**
205
+     * Gets a command controller for use in the client.
206
+     *
207
+     * @param commandManager The manager to use as a controller.
208
+     * @return The command controller the client should use.
209
+     */
210
+    @Provides
211
+    public CommandController getCommandController(final CommandManager commandManager) {
212
+        return commandManager;
213
+    }
214
+
215
+    /**
216
+     * Gets an initialised plugin manager for the client.
217
+     *
218
+     * @param identityController The controller to read settings from.
219
+     * @param actionController The action controller to use for events.
220
+     * @param updateManager The update manager to inform about plugins.
221
+     * @param directory The directory to load and save plugins in.
222
+     * @return An initialised plugin manager for the client.
223
+     */
224
+    @Provides
225
+    @Singleton
226
+    public PluginManager getPluginManager(
227
+            final IdentityController identityController,
228
+            final ActionController actionController,
229
+            final UpdateManager updateManager,
230
+            @Directory(DirectoryType.PLUGINS) final String directory) {
231
+        final PluginManager manager = new PluginManager(identityController, actionController, updateManager, directory);
232
+        final CorePluginExtractor extractor = new CorePluginExtractor(manager, directory);
233
+        checkBundledPlugins(extractor, manager, identityController.getGlobalConfiguration());
234
+
235
+        for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
236
+            ensureExists(extractor, manager, service);
237
+        }
238
+
239
+        // The user may have an existing parser plugin (e.g. twitter) which
240
+        // will satisfy the service existance check above, but will render the
241
+        // client pretty useless, so we'll force IRC extraction for now.
242
+        extractor.extractCorePlugins("parser_irc");
243
+        manager.refreshPlugins();
244
+        return manager;
245
+    }
246
+
247
+    /**
248
+     * Gets a core plugin extractor.
249
+     *
250
+     * @param pluginManager The plugin manager to notify about updates.
251
+     * @param directory The directory to extract plugins to.
252
+     * @return A plugin extractor for the client to use.
253
+     */
254
+    @Provides
255
+    public CorePluginExtractor getCorePluginExtractor(
256
+            final PluginManager pluginManager,
257
+            @Directory(DirectoryType.PLUGINS) final String directory) {
258
+        return new CorePluginExtractor(pluginManager, directory);
259
+    }
260
+
261
+    /**
262
+     * Gets an update manager for the client.
263
+     *
264
+     * @param commandLineParser CLI parser to use to find launcher version.
265
+     * @return The update manager to use.
266
+     */
267
+    @Provides
268
+    @Singleton
269
+    public UpdateManager getUpdateManager(final CommandLineParser commandLineParser) {
270
+        UpdateChecker.init();
271
+        final UpdateManager manager = UpdateChecker.getManager();
272
+
273
+        if (commandLineParser.getLauncherVersion() != null) {
274
+            LauncherComponent.setLauncherInfo(manager, commandLineParser.getLauncherVersion());
275
+        }
276
+
277
+        return manager;
278
+    }
279
+
166 280
     /**
167 281
      * Called when the global config cannot be loaded due to an error. This
168 282
      * method informs the user of the problem and installs a new default config
@@ -208,4 +322,51 @@ public class ClientModule {
208 322
         }
209 323
     }
210 324
 
325
+    /**
326
+     * Ensures that there is at least one provider of the specified
327
+     * service type by extracting matching core plugins. Plugins must be named
328
+     * so that their file name starts with the service type, and then an
329
+     * underscore.
330
+     *
331
+     * @param corePluginExtractor Extractor to use if the service doesn't exist
332
+     * @param pm The plugin manager to use to access services
333
+     * @param serviceType The type of service that should exist
334
+     */
335
+    public void ensureExists(
336
+            final CorePluginExtractor corePluginExtractor,
337
+            final PluginManager pm,
338
+            final String serviceType) {
339
+        if (pm.getServicesByType(serviceType).isEmpty()) {
340
+            corePluginExtractor.extractCorePlugins(serviceType + "_");
341
+            pm.refreshPlugins();
342
+        }
343
+    }
344
+
345
+    /**
346
+     * Checks whether the plugins bundled with this release of DMDirc are newer
347
+     * than the plugins known by the specified {@link PluginManager}. If the
348
+     * bundled plugins are newer, they are automatically extracted.
349
+     *
350
+     * @param corePluginExtractor Extractor to use if plugins need updating.
351
+     * @param pm The plugin manager to use to check plugins
352
+     * @param config The configuration source for bundled versions
353
+     */
354
+    private void checkBundledPlugins(
355
+            final CorePluginExtractor corePluginExtractor,
356
+            final PluginManager pm,
357
+            final ConfigManager config) {
358
+        for (PluginInfo plugin : pm.getPluginInfos()) {
359
+            if (config.hasOptionString("bundledplugins_versions", plugin.getMetaData().getName())) {
360
+                final Version bundled = new Version(config.getOption("bundledplugins_versions",
361
+                        plugin.getMetaData().getName()));
362
+                final Version installed = plugin.getMetaData().getVersion();
363
+
364
+                if (installed.compareTo(bundled) < 0) {
365
+                    corePluginExtractor.extractCorePlugins(plugin.getMetaData().getName());
366
+                    pm.reloadPlugin(plugin.getFilename());
367
+                }
368
+            }
369
+        }
370
+    }
371
+
211 372
 }

+ 102
- 0
src/com/dmdirc/CorePluginExtractor.java View File

@@ -0,0 +1,102 @@
1
+/*
2
+ * Copyright (c) 2006-2013 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
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc;
24
+
25
+import com.dmdirc.logger.ErrorLevel;
26
+import com.dmdirc.logger.Logger;
27
+import com.dmdirc.plugins.PluginInfo;
28
+import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.util.resourcemanager.ResourceManager;
30
+
31
+import java.io.File;
32
+import java.io.IOException;
33
+import java.util.Map;
34
+
35
+/**
36
+ * Utility class that can extract bundled plugins.
37
+ */
38
+public class CorePluginExtractor {
39
+
40
+    /** The plugin manager to inform when plugins are updated. */
41
+    private final PluginManager pluginManager;
42
+    /** The directory to extract plugins to. */
43
+    private final String pluginDir;
44
+
45
+    /**
46
+     * Creates a new instance of {@link CorePluginExtractor}.
47
+     *
48
+     * @param pluginManager The plugin manager to inform when plugins are updated.
49
+     * @param pluginDir The directory to extract plugins to.
50
+     */
51
+    public CorePluginExtractor(final PluginManager pluginManager, final String pluginDir) {
52
+        this.pluginManager = pluginManager;
53
+        this.pluginDir = pluginDir;
54
+    }
55
+
56
+    /**
57
+     * Extracts plugins bundled with DMDirc to the user's profile's plugin
58
+     * directory.
59
+     *
60
+     * @param prefix If non-null, only plugins whose file name starts with
61
+     * this prefix will be extracted.
62
+     */
63
+    public void extractCorePlugins(final String prefix) {
64
+        final Map<String, byte[]> resources = ResourceManager.getResourceManager()
65
+                .getResourcesStartingWithAsBytes("plugins");
66
+        for (Map.Entry<String, byte[]> resource : resources.entrySet()) {
67
+            try {
68
+                final String resourceName = pluginDir + resource.getKey().substring(7);
69
+
70
+                if (prefix != null && !resource.getKey().substring(8).startsWith(prefix)) {
71
+                    continue;
72
+                }
73
+
74
+                final File newDir = new File(resourceName.substring(0,
75
+                        resourceName.lastIndexOf('/')) + "/");
76
+
77
+                if (!newDir.exists()) {
78
+                    newDir.mkdirs();
79
+                }
80
+
81
+                final File newFile = new File(newDir,
82
+                        resourceName.substring(resourceName.lastIndexOf('/') + 1,
83
+                        resourceName.length()));
84
+
85
+                if (!newFile.isDirectory()) {
86
+                    ResourceManager.getResourceManager().
87
+                            resourceToFile(resource.getValue(), newFile);
88
+
89
+                    final PluginInfo plugin = pluginManager.getPluginInfo(newFile
90
+                            .getAbsolutePath().substring(pluginManager.getDirectory().length()));
91
+
92
+                    if (plugin != null) {
93
+                        plugin.pluginUpdated();
94
+                    }
95
+                }
96
+            } catch (IOException ex) {
97
+                Logger.userError(ErrorLevel.LOW, "Failed to extract plugins", ex);
98
+            }
99
+        }
100
+    }
101
+
102
+}

+ 17
- 135
src/com/dmdirc/Main.java View File

@@ -26,35 +26,24 @@ import com.dmdirc.interfaces.LifecycleController;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28 28
 import com.dmdirc.commandline.CommandLineOptionsModule;
29
-import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
30
-import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
31 29
 import com.dmdirc.commandline.CommandLineParser;
32
-import com.dmdirc.commandparser.CommandLoader;
33 30
 import com.dmdirc.commandparser.CommandManager;
34
-import com.dmdirc.config.ConfigManager;
35 31
 import com.dmdirc.config.IdentityManager;
36 32
 import com.dmdirc.interfaces.ui.UIController;
37 33
 import com.dmdirc.logger.DMDircExceptionHandler;
38 34
 import com.dmdirc.logger.ErrorLevel;
39 35
 import com.dmdirc.logger.Logger;
40 36
 import com.dmdirc.messages.MessageSinkManager;
41
-import com.dmdirc.plugins.PluginInfo;
42 37
 import com.dmdirc.plugins.PluginManager;
43 38
 import com.dmdirc.plugins.Service;
44 39
 import com.dmdirc.plugins.ServiceProvider;
45 40
 import com.dmdirc.ui.WarningDialog;
46 41
 import com.dmdirc.ui.themes.ThemeManager;
47
-import com.dmdirc.updater.UpdateChecker;
48
-import com.dmdirc.updater.Version;
49
-import com.dmdirc.util.resourcemanager.ResourceManager;
50 42
 
51 43
 import java.awt.GraphicsEnvironment;
52
-import java.io.File;
53
-import java.io.IOException;
54 44
 import java.util.Collection;
55 45
 import java.util.HashSet;
56 46
 import java.util.List;
57
-import java.util.Map;
58 47
 import java.util.Timer;
59 48
 import java.util.TimerTask;
60 49
 
@@ -88,14 +77,8 @@ public class Main implements LifecycleController {
88 77
     /** The plugin manager the client will use. */
89 78
     private final PluginManager pluginManager;
90 79
 
91
-    /** The command manager the client will use. */
92
-    private final CommandManager commandManager;
93
-
94
-    /** The command loader to use to initialise the command manager. */
95
-    private final CommandLoader commandLoader;
96
-
97
-    /** The config dir to use for the client. */
98
-    private final String configdir;
80
+    /** The extractor to use for core plugins. */
81
+    private final CorePluginExtractor corePluginExtractor;
99 82
 
100 83
     /** Instance of main, protected to allow subclasses direct access. */
101 84
     @Deprecated
@@ -109,10 +92,9 @@ public class Main implements LifecycleController {
109 92
      * @param actionManager The action manager the client will use.
110 93
      * @param commandLineParser The command-line parser used for this instance.
111 94
      * @param pluginManager The plugin manager the client will use.
112
-     * @param commandManager The command manager the client will use.
113
-     * @param commandLoader The command loader to use to initialise the command manager.
95
+     * @param commandManager Unused for now - TODO: remove me when it's injected somewhere sensible.
114 96
      * @param messageSinkManager Unused for now - TODO: remove me when it's injected somewhere sensible.
115
-     * @param configDir The base configuration directory to use.
97
+     * @param corePluginExtractor Extractor to use for core plugins.
116 98
      */
117 99
     @Inject
118 100
     public Main(
@@ -122,17 +104,14 @@ public class Main implements LifecycleController {
122 104
             final CommandLineParser commandLineParser,
123 105
             final PluginManager pluginManager,
124 106
             final CommandManager commandManager,
125
-            final CommandLoader commandLoader,
126 107
             final MessageSinkManager messageSinkManager,
127
-            @Directory(DirectoryType.BASE) final String configDir) {
108
+            final CorePluginExtractor corePluginExtractor) {
128 109
         this.identityManager = identityManager;
129 110
         this.serverManager = serverManager;
130 111
         this.actionManager = actionManager;
131 112
         this.commandLineParser = commandLineParser;
132 113
         this.pluginManager = pluginManager;
133
-        this.commandManager = commandManager;
134
-        this.commandLoader = commandLoader;
135
-        this.configdir = configDir;
114
+        this.corePluginExtractor = corePluginExtractor;
136 115
     }
137 116
 
138 117
     /**
@@ -162,29 +141,8 @@ public class Main implements LifecycleController {
162 141
      * @param args The command line arguments
163 142
      */
164 143
     public void init() {
165
-        UpdateChecker.init(this);
166
-
167
-        pluginManager.refreshPlugins();
168
-        checkBundledPlugins(pluginManager, identityManager.getGlobalConfiguration());
169
-
170 144
         ThemeManager.loadThemes();
171 145
 
172
-        commandLineParser.applySettings(identityManager.getGlobalConfigIdentity());
173
-
174
-        commandManager.initialise(identityManager.getGlobalConfiguration());
175
-        CommandManager.setCommandManager(commandManager);
176
-        commandLoader.loadCommands(commandManager);
177
-
178
-        for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
179
-            ensureExists(pluginManager, service);
180
-        }
181
-
182
-        // The user may have an existing parser plugin (e.g. twitter) which
183
-        // will satisfy the service existance check above, but will render the
184
-        // client pretty useless, so we'll force IRC extraction for now.
185
-        extractCorePlugins("parser_irc");
186
-        pluginManager.refreshPlugins();
187
-
188 146
         loadUIs(pluginManager);
189 147
 
190 148
         doFirstRun();
@@ -239,18 +197,18 @@ public class Main implements LifecycleController {
239 197
      */
240 198
     private void handleMissingUI() {
241 199
         // Check to see if we have already tried this
242
-        if (IdentityManager.getIdentityManager().getGlobalConfiguration().hasOptionBool("debug", "uiFixAttempted")) {
200
+        if (identityManager.getGlobalConfiguration().hasOptionBool("debug", "uiFixAttempted")) {
243 201
             System.out.println("DMDirc is unable to load any compatible UI plugins.");
244 202
             if (!GraphicsEnvironment.isHeadless()) {
245 203
                 new WarningDialog(WarningDialog.NO_COMPAT_UIS_TITLE,
246 204
                         WarningDialog.NO_RECOV_UIS).displayBlocking();
247 205
             }
248
-            IdentityManager.getIdentityManager().getGlobalConfigIdentity().unsetOption("debug", "uiFixAttempted");
206
+            identityManager.getGlobalConfigIdentity().unsetOption("debug", "uiFixAttempted");
249 207
             System.exit(1);
250 208
         } else {
251 209
             // Try to extract the UIs again incase they changed between versions
252 210
             // and the user didn't update the UI plugin.
253
-            extractCorePlugins("ui_");
211
+            corePluginExtractor.extractCorePlugins("ui_");
254 212
 
255 213
             System.out.println("DMDirc has updated the UI plugins and needs to restart.");
256 214
 
@@ -260,52 +218,12 @@ public class Main implements LifecycleController {
260 218
             }
261 219
 
262 220
             // Allow the rebooted DMDirc to know that we have attempted restarting.
263
-            IdentityManager.getIdentityManager().getGlobalConfigIdentity()
264
-                    .setOption("debug", "uiFixAttempted", "true");
221
+            identityManager.getGlobalConfigIdentity().setOption("debug", "uiFixAttempted", "true");
265 222
             // Tell the launcher to restart!
266 223
             System.exit(42);
267 224
         }
268 225
     }
269 226
 
270
-    /**
271
-     * Ensures that there is at least one provider of the specified
272
-     * service type by extracting matching core plugins. Plugins must be named
273
-     * so that their file name starts with the service type, and then an
274
-     * underscore.
275
-     *
276
-     * @param pm The plugin manager to use to access services
277
-     * @param serviceType The type of service that should exist
278
-     */
279
-    public void ensureExists(final PluginManager pm, final String serviceType) {
280
-        if (pm.getServicesByType(serviceType).isEmpty()) {
281
-            extractCorePlugins(serviceType + "_");
282
-            pm.refreshPlugins();
283
-        }
284
-    }
285
-
286
-    /**
287
-     * Checks whether the plugins bundled with this release of DMDirc are newer
288
-     * than the plugins known by the specified {@link PluginManager}. If the
289
-     * bundled plugins are newer, they are automatically extracted.
290
-     *
291
-     * @param pm The plugin manager to use to check plugins
292
-     * @param config The configuration source for bundled versions
293
-     */
294
-    private void checkBundledPlugins(final PluginManager pm, final ConfigManager config) {
295
-        for (PluginInfo plugin : pm.getPluginInfos()) {
296
-            if (config.hasOptionString("bundledplugins_versions", plugin.getMetaData().getName())) {
297
-                final Version bundled = new Version(config.getOption("bundledplugins_versions",
298
-                        plugin.getMetaData().getName()));
299
-                final Version installed = plugin.getMetaData().getVersion();
300
-
301
-                if (installed.compareTo(bundled) < 0) {
302
-                    extractCorePlugins(plugin.getMetaData().getName());
303
-                    pm.reloadPlugin(plugin.getFilename());
304
-                }
305
-            }
306
-        }
307
-    }
308
-
309 227
     /**
310 228
      * Attempts to find and activate a service which provides a UI that we
311 229
      * can use.
@@ -332,10 +250,8 @@ public class Main implements LifecycleController {
332 250
             handleMissingUI();
333 251
         } else {
334 252
             // The fix worked!
335
-            if (IdentityManager.getIdentityManager().getGlobalConfiguration()
336
-                    .hasOptionBool("debug", "uiFixAttempted")) {
337
-                IdentityManager.getIdentityManager().getGlobalConfigIdentity()
338
-                        .unsetOption("debug", "uiFixAttempted");
253
+            if (identityManager.getGlobalConfiguration().hasOptionBool("debug", "uiFixAttempted")) {
254
+                identityManager.getGlobalConfigIdentity().unsetOption("debug", "uiFixAttempted");
339 255
             }
340 256
         }
341 257
     }
@@ -344,8 +260,8 @@ public class Main implements LifecycleController {
344 260
      * Executes the first run or migration wizards as required.
345 261
      */
346 262
     private void doFirstRun() {
347
-        if (IdentityManager.getIdentityManager().getGlobalConfiguration().getOptionBool("general", "firstRun")) {
348
-            IdentityManager.getIdentityManager().getGlobalConfigIdentity().setOption("general", "firstRun", "false");
263
+        if (identityManager.getGlobalConfiguration().getOptionBool("general", "firstRun")) {
264
+            identityManager.getGlobalConfigIdentity().setOption("general", "firstRun", "false");
349 265
             for (UIController controller : CONTROLLERS) {
350 266
                 controller.showFirstRunWizard();
351 267
             }
@@ -427,45 +343,11 @@ public class Main implements LifecycleController {
427 343
      *
428 344
      * @param prefix If non-null, only plugins whose file name starts with
429 345
      * this prefix will be extracted.
346
+     * @deprecated Go via a {@link CorePluginExtractor}.
430 347
      */
348
+    @Deprecated
431 349
     public void extractCorePlugins(final String prefix) {
432
-        final Map<String, byte[]> resources = ResourceManager.getResourceManager()
433
-                .getResourcesStartingWithAsBytes("plugins");
434
-        for (Map.Entry<String, byte[]> resource : resources.entrySet()) {
435
-            try {
436
-                final String resourceName = configdir + "plugins"
437
-                        + resource.getKey().substring(7);
438
-
439
-                if (prefix != null && !resource.getKey().substring(8).startsWith(prefix)) {
440
-                    continue;
441
-                }
442
-
443
-                final File newDir = new File(resourceName.substring(0,
444
-                        resourceName.lastIndexOf('/')) + "/");
445
-
446
-                if (!newDir.exists()) {
447
-                    newDir.mkdirs();
448
-                }
449
-
450
-                final File newFile = new File(newDir,
451
-                        resourceName.substring(resourceName.lastIndexOf('/') + 1,
452
-                        resourceName.length()));
453
-
454
-                if (!newFile.isDirectory()) {
455
-                    ResourceManager.getResourceManager().
456
-                            resourceToFile(resource.getValue(), newFile);
457
-
458
-                    final PluginInfo plugin = pluginManager.getPluginInfo(newFile
459
-                            .getAbsolutePath().substring(pluginManager.getDirectory().length()));
460
-
461
-                    if (plugin != null) {
462
-                        plugin.pluginUpdated();
463
-                    }
464
-                }
465
-            } catch (IOException ex) {
466
-                Logger.userError(ErrorLevel.LOW, "Failed to extract plugins", ex);
467
-            }
468
-        }
350
+        corePluginExtractor.extractCorePlugins(prefix);
469 351
     }
470 352
 
471 353
 }

+ 9
- 3
src/com/dmdirc/ServerManager.java View File

@@ -23,10 +23,10 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.actions.wrappers.AliasWrapper;
26
-import com.dmdirc.commandparser.CommandManager;
27 26
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
28 27
 import com.dmdirc.config.ConfigManager;
29 28
 import com.dmdirc.config.Identity;
29
+import com.dmdirc.interfaces.CommandController;
30 30
 import com.dmdirc.interfaces.IdentityController;
31 31
 import com.dmdirc.interfaces.ServerFactory;
32 32
 import com.dmdirc.logger.ErrorLevel;
@@ -61,18 +61,24 @@ public class ServerManager implements ServerFactory {
61 61
     /** The identity controller to use to find profiles. */
62 62
     private final IdentityController identityController;
63 63
 
64
+    /** A provider of {@link CommandController}s to pass to servers. */
65
+    private final Provider<CommandController> commandController;
66
+
64 67
     /**
65 68
      * Creates a new instance of ServerManager.
66 69
      *
67 70
      * @param parserFactoryProvider The provider of {@link ParserFactory}s to give to servers.
68 71
      * @param identityController The identity controller to use to find profiles.
72
+     * @param commandController A provider of {@link CommandController}s to pass to servers.
69 73
      */
70 74
     @Inject
71 75
     public ServerManager(
72 76
             final Provider<ParserFactory> parserFactoryProvider,
73
-            final IdentityController identityController) {
77
+            final IdentityController identityController,
78
+            final Provider<CommandController> commandController) {
74 79
         this.parserFactoryProvider = parserFactoryProvider;
75 80
         this.identityController = identityController;
81
+        this.commandController = commandController;
76 82
     }
77 83
 
78 84
     /** {@inheritDoc} */
@@ -87,7 +93,7 @@ public class ServerManager implements ServerFactory {
87 93
                 parserFactoryProvider.get(),
88 94
                 WindowManager.getWindowManager(),
89 95
                 AliasWrapper.getAliasWrapper(),
90
-                CommandManager.getCommandManager(),
96
+                commandController.get(),
91 97
                 uri,
92 98
                 profile);
93 99
     }

+ 15
- 11
src/com/dmdirc/commandline/CommandLineParser.java View File

@@ -25,11 +25,9 @@ package com.dmdirc.commandline;
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.commandparser.commands.global.NewServer;
28
-import com.dmdirc.config.Identity;
29 28
 import com.dmdirc.config.IdentityManager;
30 29
 import com.dmdirc.logger.ErrorLevel;
31 30
 import com.dmdirc.logger.Logger;
32
-import com.dmdirc.updater.components.LauncherComponent;
33 31
 import com.dmdirc.util.resourcemanager.DMDircResourceManager;
34 32
 
35 33
 import java.io.File;
@@ -68,7 +66,7 @@ public class CommandLineParser {
68 66
     private boolean disablereporting;
69 67
 
70 68
     /** The version string passed for the launcher. */
71
-    private String launcherVersion = "";
69
+    private String launcherVersion;
72 70
 
73 71
     /** The configuration directory. */
74 72
     private String configDirectory;
@@ -358,16 +356,22 @@ public class CommandLineParser {
358 356
     }
359 357
 
360 358
     /**
361
-     * Applies any applicable settings to the config identity.
359
+     * Indicates whether the user has requested error reporting be disabled.
360
+     *
361
+     * @return True if the user has disabled reporting, false otherwise.
362 362
      */
363
-    public void applySettings(final Identity globalIdentity) {
364
-        if (disablereporting) {
365
-            globalIdentity.setOption("temp", "noerrorreporting", true);
366
-        }
363
+    public boolean getDisableReporting() {
364
+        return disablereporting;
365
+    }
367 366
 
368
-        if (!launcherVersion.isEmpty()) {
369
-            LauncherComponent.setLauncherInfo(launcherVersion);
370
-        }
367
+    /**
368
+     * Returns the provided launcher version, if any.
369
+     *
370
+     * @return The version supplied by the launcher, or {@code null} if no
371
+     * launcher is identified.
372
+     */
373
+    public String getLauncherVersion() {
374
+        return launcherVersion;
371 375
     }
372 376
 
373 377
     /**

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

@@ -39,16 +39,12 @@ import java.util.HashMap;
39 39
 import java.util.List;
40 40
 import java.util.Map;
41 41
 
42
-import javax.inject.Inject;
43
-import javax.inject.Singleton;
44
-
45 42
 import lombok.Getter;
46 43
 
47 44
 /**
48 45
  * The command manager creates and manages a single instance of all commands,
49 46
  * and provides methods to load each group of commands into a parser instance.
50 47
  */
51
-@Singleton
52 48
 @SuppressWarnings("PMD.UnusedPrivateField")
53 49
 public class CommandManager implements CommandController {
54 50
 
@@ -81,7 +77,6 @@ public class CommandManager implements CommandController {
81 77
      *
82 78
      * @param serverManager the manager to use to iterate servers.
83 79
      */
84
-    @Inject
85 80
     public CommandManager(final ServerManager serverManager) {
86 81
         this.serverManager = serverManager;
87 82
     }

+ 9
- 10
src/com/dmdirc/plugins/PluginManager.java View File

@@ -23,8 +23,6 @@
23 23
 package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.actions.CoreActionType;
26
-import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
-import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
28 26
 import com.dmdirc.config.prefs.PreferencesDialogModel;
29 27
 import com.dmdirc.interfaces.ActionController;
30 28
 import com.dmdirc.interfaces.ActionListener;
@@ -32,8 +30,8 @@ import com.dmdirc.interfaces.IdentityController;
32 30
 import com.dmdirc.interfaces.actions.ActionType;
33 31
 import com.dmdirc.logger.ErrorLevel;
34 32
 import com.dmdirc.logger.Logger;
35
-import com.dmdirc.updater.UpdateChecker;
36 33
 import com.dmdirc.updater.components.PluginComponent;
34
+import com.dmdirc.updater.manager.UpdateManager;
37 35
 import com.dmdirc.util.collections.MapList;
38 36
 
39 37
 import java.io.File;
@@ -49,13 +47,9 @@ import java.util.LinkedList;
49 47
 import java.util.List;
50 48
 import java.util.Map;
51 49
 
52
-import javax.inject.Inject;
53
-import javax.inject.Singleton;
54
-
55 50
 /**
56 51
  * Searches for and manages plugins and services.
57 52
  */
58
-@Singleton
59 53
 public class PluginManager implements ActionListener, ServiceManager {
60 54
 
61 55
     /** List of known plugins' file names to their corresponding {@link PluginInfo} objects. */
@@ -73,6 +67,9 @@ public class PluginManager implements ActionListener, ServiceManager {
73 67
     /** The action controller to use for events. */
74 68
     private final ActionController actionController;
75 69
 
70
+    /** The update manager to inform about plugins. */
71
+    private final UpdateManager updateManager;
72
+
76 73
     /** Map of services. */
77 74
     private final Map<String, Map<String, Service>> services = new HashMap<>();
78 75
 
@@ -84,15 +81,17 @@ public class PluginManager implements ActionListener, ServiceManager {
84 81
      *
85 82
      * @param identityController The identity controller to use for configuration options.
86 83
      * @param actionController The action controller to use for events.
84
+     * @param updateManager The update manager to inform about plugins.
87 85
      * @param directory The directory to load plugins from.
88 86
      */
89
-    @Inject
90 87
     public PluginManager(
91 88
             final IdentityController identityController,
92 89
             final ActionController actionController,
93
-            @Directory(DirectoryType.PLUGINS) final String directory) {
90
+            final UpdateManager updateManager,
91
+            final String directory) {
94 92
         this.identityController = identityController;
95 93
         this.actionController = actionController;
94
+        this.updateManager = updateManager;
96 95
         this.directory = directory;
97 96
         this.globalClassLoader = new GlobalClassLoader(this);
98 97
 
@@ -265,7 +264,7 @@ public class PluginManager implements ActionListener, ServiceManager {
265 264
             if ((metadata.getUpdaterId() > 0 && metadata.getVersion().isValid())
266 265
                     || (identityController.getGlobalConfiguration()
267 266
                     .hasOptionInt("plugin-addonid", metadata.getName()))) {
268
-                UpdateChecker.getManager().addComponent(new PluginComponent(pluginInfo));
267
+                updateManager.addComponent(new PluginComponent(pluginInfo));
269 268
             }
270 269
 
271 270
             knownPlugins.put(filename.toLowerCase(), pluginInfo);

+ 2
- 3
src/com/dmdirc/updater/UpdateChecker.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.updater;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.config.ConfigManager;
27 26
 import com.dmdirc.config.IdentityManager;
28 27
 import com.dmdirc.logger.ErrorLevel;
@@ -107,9 +106,9 @@ public final class UpdateChecker implements Runnable {
107 106
      *
108 107
      * @param main Parent Main class
109 108
      */
110
-    public static void init(final Main main) {
109
+    public static void init() {
111 110
         manager = new DMDircUpdateManager(IdentityManager.getIdentityManager()
112
-                .getGlobalConfiguration(), IdentityManager.getIdentityManager().getConfigDir(), 3, main);
111
+                .getGlobalConfiguration(), IdentityManager.getIdentityManager().getConfigDir(), 3);
113 112
 
114 113
         initTimer();
115 114
     }

+ 1
- 10
src/com/dmdirc/updater/components/ClientComponent.java View File

@@ -35,15 +35,6 @@ import java.io.File;
35 35
  */
36 36
 public class ClientComponent implements UpdateComponent {
37 37
 
38
-    // @deprecated This is only needed because we need to show a UI for
39
-    // manual installs. This should be removed at some point.
40
-    /** Reference to parent Main. */
41
-    final Main main;
42
-
43
-    public ClientComponent(final Main main) {
44
-        this.main = main;
45
-    }
46
-
47 38
     /** {@inheritDoc} */
48 39
     @Override
49 40
     public String getName() {
@@ -128,7 +119,7 @@ public class ClientComponent implements UpdateComponent {
128 119
             // @deprecated Should be removed when updater UI changes are
129 120
             // implemented.
130 121
             final String message = this.getManualInstructions(path);
131
-            main.getUI().showMessageDialog("Client update downloaded", message);
122
+            Main.mainInstance.getUI().showMessageDialog("Client update downloaded", message);
132 123
         }
133 124
 
134 125
         return true;

+ 4
- 3
src/com/dmdirc/updater/components/LauncherComponent.java View File

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.updater.components;
24 24
 
25
-import com.dmdirc.updater.UpdateChecker;
26 25
 import com.dmdirc.updater.UpdateComponent;
27 26
 import com.dmdirc.updater.Version;
27
+import com.dmdirc.updater.manager.UpdateManager;
28 28
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
29 29
 
30 30
 import java.io.File;
@@ -44,9 +44,10 @@ public class LauncherComponent implements UpdateComponent {
44 44
     /**
45 45
      * Parses the specified launcher information.
46 46
      *
47
+     * @param manager THe manager to update with the launcher component.
47 48
      * @param info The platform and version of the launcher, separated by '-'.
48 49
      */
49
-    public static void setLauncherInfo(final String info) {
50
+    public static void setLauncherInfo(final UpdateManager manager, final String info) {
50 51
         final int hpos = info.indexOf('-');
51 52
         final int cpos = info.indexOf(',');
52 53
 
@@ -61,7 +62,7 @@ public class LauncherComponent implements UpdateComponent {
61 62
             version = new Version(info.substring(hpos + 1, cpos));
62 63
         }
63 64
 
64
-        UpdateChecker.getManager().addComponent(new LauncherComponent());
65
+        manager.addComponent(new LauncherComponent());
65 66
     }
66 67
 
67 68
     /**

+ 2
- 4
src/com/dmdirc/updater/manager/DMDircUpdateManager.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.updater.manager;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.config.ConfigBinding;
27 26
 import com.dmdirc.config.ConfigManager;
28 27
 import com.dmdirc.updater.UpdateChannel;
@@ -56,17 +55,16 @@ public class DMDircUpdateManager extends CachingUpdateManagerImpl {
56 55
      * @param configManager The config manager to use to retrieve channel info
57 56
      * @param tempFolder Temporary folder to use for downloading updates
58 57
      * @param threads The number of threads to use for updating
59
-     * @param main Instance of main for ClientComponent
60 58
      */
61 59
     public DMDircUpdateManager(final ConfigManager configManager,
62
-            final String tempFolder, final int threads, final Main main) {
60
+            final String tempFolder, final int threads) {
63 61
         super(new ThreadPoolExecutor(threads, threads, 1, TimeUnit.MINUTES,
64 62
                 new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory()),
65 63
                 new NaiveConsolidator(),
66 64
                 new ConfigComponentPolicy(configManager));
67 65
 
68 66
         // @deprecated See ClientComponent
69
-        addComponent(new ClientComponent(main));
67
+        addComponent(new ClientComponent());
70 68
         addComponent(new ModeAliasesComponent());
71 69
         addComponent(new DefaultsComponent());
72 70
 

+ 4
- 1
test/com/dmdirc/ServerManagerTest.java View File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.interfaces.CommandController;
25 26
 import com.dmdirc.interfaces.IdentityController;
26 27
 import com.dmdirc.parser.common.ChannelJoinRequest;
27 28
 
@@ -43,11 +44,13 @@ public class ServerManagerTest {
43 44
 
44 45
     @Mock private IdentityController identityController;
45 46
     @Mock private Provider<ParserFactory> parserFactoryProvider;
47
+    @Mock private Provider<CommandController> commandControllerProvider;
46 48
     private ServerManager serverManager;
47 49
 
48 50
     @Before
49 51
     public void setUp() throws Exception {
50
-        serverManager = new ServerManager(parserFactoryProvider, identityController);
52
+        serverManager = new ServerManager(parserFactoryProvider,
53
+                identityController, commandControllerProvider);
51 54
     }
52 55
 
53 56
     @After

+ 9
- 10
test/com/dmdirc/TestMain.java View File

@@ -6,6 +6,7 @@ import com.dmdirc.commandparser.CommandManager;
6 6
 import com.dmdirc.config.IdentityManager;
7 7
 import com.dmdirc.config.InvalidIdentityFileException;
8 8
 import com.dmdirc.plugins.PluginManager;
9
+import com.dmdirc.updater.manager.UpdateManager;
9 10
 
10 11
 import java.io.File;
11 12
 import java.io.IOException;
@@ -19,11 +20,8 @@ public class TestMain extends Main {
19 20
     private static Main instance;
20 21
 
21 22
     private final IdentityManager identityManager;
22
-    private final ServerManager serverManager;
23
-    private final ActionManager actionManager;
24 23
     private final PluginManager pluginManager;
25 24
     private final CommandManager commandManager;
26
-    private final String configdir;
27 25
 
28 26
     public TestMain(final IdentityManager identityManager,
29 27
             final ServerManager serverManager,
@@ -31,15 +29,12 @@ public class TestMain extends Main {
31 29
             final CommandLineParser commandLineParser,
32 30
             final PluginManager pluginManager,
33 31
             final CommandManager commandManager,
34
-            final String configDir) {
32
+            final CorePluginExtractor corePluginExtractor) {
35 33
         super(identityManager, serverManager, actionManager, commandLineParser,
36
-                pluginManager, commandManager, null, null, configDir);
34
+                pluginManager, commandManager, null, corePluginExtractor);
37 35
         this.identityManager = identityManager;
38
-        this.serverManager = serverManager;
39
-        this.actionManager = actionManager;
40 36
         this.pluginManager = pluginManager;
41 37
         this.commandManager = commandManager;
42
-        this.configdir = configDir;
43 38
     }
44 39
 
45 40
     /** {@inheritDoc} */
@@ -93,11 +88,15 @@ public class TestMain extends Main {
93 88
                 final ActionManager actionManager = new ActionManager(serverManager, identityManager);
94 89
                 ActionManager.setActionManager(actionManager);
95 90
 
96
-                final PluginManager pluginManager = new PluginManager(identityManager, actionManager, pluginDirectory);
91
+                final PluginManager pluginManager = new PluginManager(
92
+                        identityManager, actionManager,
93
+                        mock(UpdateManager.class), pluginDirectory);
94
+                final CorePluginExtractor corePluginExtractor =
95
+                        new CorePluginExtractor(pluginManager, pluginDirectory);
97 96
 
98 97
                 instance = new TestMain(identityManager, serverManager,
99 98
                         actionManager, null, pluginManager,
100
-                        new CommandManager(serverManager), configDirectory);
99
+                        new CommandManager(serverManager), corePluginExtractor);
101 100
                 instance.init();
102 101
             } catch (IOException ex) {
103 102
                 // Blargh.

Loading…
Cancel
Save