Browse Source

Tidy up core plugin functionality.

Move stuff from ClientModule into a CorePluginHelper, and
move CorePluginExtractor into the plugins package.

Change-Id: I0f0211edba8e8c19857d0a783f23b90aee89e84c
Reviewed-on: http://gerrit.dmdirc.com/3748
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Chris Smith 9 years ago
parent
commit
d240937227

+ 6
- 49
src/com/dmdirc/ClientModule.java View File

@@ -47,10 +47,11 @@ import com.dmdirc.logger.ErrorLevel;
47 47
 import com.dmdirc.logger.ErrorManager;
48 48
 import com.dmdirc.logger.Logger;
49 49
 import com.dmdirc.messages.MessagesModule;
50
+import com.dmdirc.plugins.CorePluginExtractor;
51
+import com.dmdirc.plugins.CorePluginHelper;
50 52
 import com.dmdirc.plugins.LegacyServiceLocator;
51 53
 import com.dmdirc.plugins.PluginInjectorInitialiser;
52 54
 import com.dmdirc.plugins.PluginManager;
53
-import com.dmdirc.plugins.PluginMetaData;
54 55
 import com.dmdirc.plugins.ServiceLocator;
55 56
 import com.dmdirc.plugins.ServiceManager;
56 57
 import com.dmdirc.ui.IconManager;
@@ -58,7 +59,6 @@ import com.dmdirc.ui.WarningDialog;
58 59
 import com.dmdirc.ui.messages.ColourManager;
59 60
 import com.dmdirc.ui.themes.ThemeManager;
60 61
 import com.dmdirc.updater.UpdaterModule;
61
-import com.dmdirc.updater.Version;
62 62
 import com.dmdirc.updater.manager.UpdateManager;
63 63
 import com.dmdirc.util.URLBuilder;
64 64
 import com.dmdirc.util.io.Downloader;
@@ -219,14 +219,16 @@ public class ClientModule {
219 219
             final UpdateManager updateManager,
220 220
             final Provider<PluginInjectorInitialiser> initialiserProvider,
221 221
             final ObjectGraph objectGraph,
222
+            final CorePluginHelper pluginHelper,
222 223
             @Directory(DirectoryType.PLUGINS) final String directory) {
223 224
         final PluginManager manager = new PluginManager(eventBus, identityController,
224 225
                 updateManager, initialiserProvider, objectGraph, directory);
225 226
         final CorePluginExtractor extractor = new CorePluginExtractor(manager, directory, eventBus);
226
-        checkBundledPlugins(extractor, manager, identityController.getGlobalConfiguration());
227
+        pluginHelper.checkBundledPlugins(extractor, manager,
228
+                identityController.getGlobalConfiguration());
227 229
 
228 230
         for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
229
-            ensureExists(extractor, manager, service);
231
+            pluginHelper.ensureExists(extractor, manager, service);
230 232
         }
231 233
 
232 234
         // The user may have an existing parser plugin (e.g. twitter) which
@@ -351,49 +353,4 @@ public class ClientModule {
351 353
         }
352 354
     }
353 355
 
354
-    /**
355
-     * Ensures that there is at least one provider of the specified service type by extracting
356
-     * matching core plugins. Plugins must be named so that their file name starts with the service
357
-     * type, and then an underscore.
358
-     *
359
-     * @param corePluginExtractor Extractor to use if the service doesn't exist
360
-     * @param pm                  The plugin manager to use to access services
361
-     * @param serviceType         The type of service that should exist
362
-     */
363
-    public void ensureExists(
364
-            final CorePluginExtractor corePluginExtractor,
365
-            final PluginManager pm,
366
-            final String serviceType) {
367
-        if (pm.getServicesByType(serviceType).isEmpty()) {
368
-            corePluginExtractor.extractCorePlugins(serviceType + "_");
369
-            pm.refreshPlugins();
370
-        }
371
-    }
372
-
373
-    /**
374
-     * Checks whether the plugins bundled with this release of DMDirc are newer than the plugins
375
-     * known by the specified {@link PluginManager}. If the bundled plugins are newer, they are
376
-     * automatically extracted.
377
-     *
378
-     * @param corePluginExtractor Extractor to use if plugins need updating.
379
-     * @param pm                  The plugin manager to use to check plugins
380
-     * @param config              The configuration source for bundled versions
381
-     */
382
-    private void checkBundledPlugins(
383
-            final CorePluginExtractor corePluginExtractor,
384
-            final PluginManager pm,
385
-            final AggregateConfigProvider config) {
386
-        for (PluginMetaData plugin : pm.getAllPlugins()) {
387
-            if (config.hasOptionString("bundledplugins_versions", plugin.getName())) {
388
-                final Version bundled = new Version(config.getOption("bundledplugins_versions",
389
-                        plugin.getName()));
390
-                final Version installed = plugin.getVersion();
391
-
392
-                if (installed.compareTo(bundled) < 0) {
393
-                    corePluginExtractor.extractCorePlugins(plugin.getName());
394
-                }
395
-            }
396
-        }
397
-    }
398
-
399 356
 }

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

@@ -39,6 +39,7 @@ import com.dmdirc.interfaces.ui.UIController;
39 39
 import com.dmdirc.logger.DMDircExceptionHandler;
40 40
 import com.dmdirc.logger.ErrorLevel;
41 41
 import com.dmdirc.logger.Logger;
42
+import com.dmdirc.plugins.CorePluginExtractor;
42 43
 import com.dmdirc.plugins.PluginManager;
43 44
 import com.dmdirc.plugins.Service;
44 45
 import com.dmdirc.plugins.ServiceProvider;

src/com/dmdirc/CorePluginExtractor.java → src/com/dmdirc/plugins/CorePluginExtractor.java View File

@@ -20,14 +20,12 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc;
23
+package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
26 26
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
27 27
 import com.dmdirc.events.UserErrorEvent;
28 28
 import com.dmdirc.logger.ErrorLevel;
29
-import com.dmdirc.plugins.PluginInfo;
30
-import com.dmdirc.plugins.PluginManager;
31 29
 import com.dmdirc.util.resourcemanager.ResourceManager;
32 30
 
33 31
 import com.google.common.eventbus.EventBus;

+ 86
- 0
src/com/dmdirc/plugins/CorePluginHelper.java View File

@@ -0,0 +1,86 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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.plugins;
24
+
25
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
26
+import com.dmdirc.updater.Version;
27
+
28
+import javax.inject.Inject;
29
+import javax.inject.Singleton;
30
+
31
+/**
32
+ * Provides helper methods for dealing with plugins.
33
+ */
34
+@Singleton
35
+public class CorePluginHelper {
36
+
37
+    @Inject
38
+    public CorePluginHelper() {
39
+    }
40
+
41
+    /**
42
+     * Ensures that there is at least one provider of the specified service type by extracting
43
+     * matching core plugins. Plugins must be named so that their file name starts with the service
44
+     * type, and then an underscore.
45
+     *
46
+     * @param corePluginExtractor Extractor to use if the service doesn't exist
47
+     * @param pm                  The plugin manager to use to access services
48
+     * @param serviceType         The type of service that should exist
49
+     */
50
+    public void ensureExists(
51
+            final CorePluginExtractor corePluginExtractor,
52
+            final PluginManager pm,
53
+            final String serviceType) {
54
+        if (pm.getServicesByType(serviceType).isEmpty()) {
55
+            corePluginExtractor.extractCorePlugins(serviceType + "_");
56
+            pm.refreshPlugins();
57
+        }
58
+    }
59
+
60
+    /**
61
+     * Checks whether the plugins bundled with this release of DMDirc are newer than the plugins
62
+     * known by the specified {@link PluginManager}. If the bundled plugins are newer, they are
63
+     * automatically extracted.
64
+     *
65
+     * @param corePluginExtractor Extractor to use if plugins need updating.
66
+     * @param pm                  The plugin manager to use to check plugins
67
+     * @param config              The configuration source for bundled versions
68
+     */
69
+    public void checkBundledPlugins(
70
+            final CorePluginExtractor corePluginExtractor,
71
+            final PluginManager pm,
72
+            final AggregateConfigProvider config) {
73
+        for (PluginMetaData plugin : pm.getAllPlugins()) {
74
+            if (config.hasOptionString("bundledplugins_versions", plugin.getName())) {
75
+                final Version bundled = new Version(config.getOption("bundledplugins_versions",
76
+                        plugin.getName()));
77
+                final Version installed = plugin.getVersion();
78
+
79
+                if (installed.compareTo(bundled) < 0) {
80
+                    corePluginExtractor.extractCorePlugins(plugin.getName());
81
+                }
82
+            }
83
+        }
84
+    }
85
+
86
+}

+ 0
- 1
src/com/dmdirc/plugins/PluginInjectorInitialiser.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.plugins;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.CorePluginExtractor;
27 26
 import com.dmdirc.ServerManager;
28 27
 import com.dmdirc.actions.ActionFactory;
29 28
 import com.dmdirc.actions.ActionManager;

Loading…
Cancel
Save