Sfoglia il codice sorgente

Inject the PluginManager.

Change-Id: Ic5eaf45c19502b4d30db49e8b1b95d91be04fc2a
Reviewed-on: http://gerrit.dmdirc.com/2687
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 anni fa
parent
commit
beda762db4

+ 12
- 0
src/com/dmdirc/ClientModule.java Vedi File

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.commandline.CommandLineOptionsModule;
27 27
 import com.dmdirc.config.IdentityManager;
28
+import com.dmdirc.interfaces.ActionController;
28 29
 import com.dmdirc.interfaces.IdentityController;
29 30
 
30 31
 import javax.inject.Singleton;
@@ -88,4 +89,15 @@ public class ClientModule {
88 89
         return actionManager;
89 90
     }
90 91
 
92
+    /**
93
+     * Provides an action controller.
94
+     *
95
+     * @param actionManager The action manager to use as a controller.
96
+     * @return An action controller to use.
97
+     */
98
+    @Provides
99
+    public ActionController getActionController(final ActionManager actionManager) {
100
+        return actionManager;
101
+    }
102
+
91 103
 }

+ 6
- 6
src/com/dmdirc/Main.java Vedi File

@@ -87,6 +87,9 @@ public class Main implements LifecycleController {
87 87
     /** The command-line parser used for this instance. */
88 88
     private final CommandLineParser commandLineParser;
89 89
 
90
+    /** The plugin manager the client will use. */
91
+    private final PluginManager pluginManager;
92
+
90 93
     /** The config dir to use for the client. */
91 94
     private final String configdir;
92 95
 
@@ -94,9 +97,6 @@ public class Main implements LifecycleController {
94 97
     @Deprecated
95 98
     public static Main mainInstance;
96 99
 
97
-    /** Instance of pluginmanager used by this Main. */
98
-    protected PluginManager pluginManager;
99
-
100 100
     /**
101 101
      * Creates a new instance of {@link Main}.
102 102
      *
@@ -104,6 +104,7 @@ public class Main implements LifecycleController {
104 104
      * @param serverManager The server manager the client will use.
105 105
      * @param actionManager The action manager the client will use.
106 106
      * @param commandLineParser The command-line parser used for this instance.
107
+     * @param pluginManager The plugin manager the client will use.
107 108
      * @param configDir The base configuration directory to use.
108 109
      */
109 110
     @Inject
@@ -112,11 +113,13 @@ public class Main implements LifecycleController {
112 113
             final ServerManager serverManager,
113 114
             final ActionManager actionManager,
114 115
             final CommandLineParser commandLineParser,
116
+            final PluginManager pluginManager,
115 117
             @Directory(DirectoryType.BASE) final String configDir) {
116 118
         this.identityManager = identityManager;
117 119
         this.serverManager = serverManager;
118 120
         this.actionManager = actionManager;
119 121
         this.commandLineParser = commandLineParser;
122
+        this.pluginManager = pluginManager;
120 123
         this.configdir = configDir;
121 124
     }
122 125
 
@@ -157,9 +160,6 @@ public class Main implements LifecycleController {
157 160
 
158 161
         MessageSinkManager.getManager().loadDefaultSinks();
159 162
 
160
-        final String fs = System.getProperty("file.separator");
161
-        final String pluginDirectory = configdir + "plugins" + fs;
162
-        pluginManager = new PluginManager(identityManager, actionManager, pluginDirectory);
163 163
         pluginManager.refreshPlugins();
164 164
         checkBundledPlugins(pluginManager, identityManager.getGlobalConfiguration());
165 165
 

+ 26
- 1
src/com/dmdirc/commandline/CommandLineOptionsModule.java Vedi File

@@ -41,7 +41,9 @@ public class CommandLineOptionsModule {
41 41
         /** The base directory, where everything else lives. */
42 42
         BASE,
43 43
         /** The directory that identities are stored in. */
44
-        IDENTITIES;
44
+        IDENTITIES,
45
+        /** The directory that plugins are stored in. */
46
+        PLUGINS;
45 47
     }
46 48
 
47 49
     /**
@@ -65,11 +67,21 @@ public class CommandLineOptionsModule {
65 67
         this.parser = parser;
66 68
     }
67 69
 
70
+    /**
71
+     * Provides the command-line parser used for this instance.
72
+     *
73
+     * @return The command-line parser.
74
+     */
68 75
     @Provides
69 76
     public CommandLineParser getParser() {
70 77
         return parser;
71 78
     }
72 79
 
80
+    /**
81
+     * Provides the base directory that all DMDirc user data is stored in.
82
+     *
83
+     * @return The base directory.
84
+     */
73 85
     @Provides
74 86
     @Singleton
75 87
     @Directory(DirectoryType.BASE)
@@ -81,6 +93,19 @@ public class CommandLineOptionsModule {
81 93
         }
82 94
     }
83 95
 
96
+    /**
97
+     * Provides the path to the plugins directory.
98
+     *
99
+     * @param baseDirectory The base DMDirc directory.
100
+     * @return The plugin directory.
101
+     */
102
+    @Provides
103
+    @Singleton
104
+    @Directory(DirectoryType.PLUGINS)
105
+    public String getPluginsDirectory(final @Directory(DirectoryType.BASE) String baseDirectory) {
106
+        return baseDirectory + "plugins" + File.separator;
107
+    }
108
+
84 109
     /**
85 110
      * Initialises the location of the configuration directory.
86 111
      */

+ 6
- 1
src/com/dmdirc/plugins/PluginManager.java Vedi File

@@ -23,6 +23,8 @@
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;
26 28
 import com.dmdirc.config.prefs.PreferencesDialogModel;
27 29
 import com.dmdirc.interfaces.ActionController;
28 30
 import com.dmdirc.interfaces.ActionListener;
@@ -47,6 +49,8 @@ import java.util.LinkedList;
47 49
 import java.util.List;
48 50
 import java.util.Map;
49 51
 
52
+import javax.inject.Inject;
53
+
50 54
 /**
51 55
  * Searches for and manages plugins and services.
52 56
  */
@@ -80,10 +84,11 @@ public class PluginManager implements ActionListener, ServiceManager {
80 84
      * @param actionController The action controller to use for events.
81 85
      * @param directory The directory to load plugins from.
82 86
      */
87
+    @Inject
83 88
     public PluginManager(
84 89
             final IdentityController identityController,
85 90
             final ActionController actionController,
86
-            final String directory) {
91
+            @Directory(DirectoryType.PLUGINS) final String directory) {
87 92
         this.identityController = identityController;
88 93
         this.actionController = actionController;
89 94
         this.directory = directory;

+ 10
- 5
test/com/dmdirc/TestMain.java Vedi File

@@ -21,17 +21,20 @@ public class TestMain extends Main {
21 21
     private final IdentityManager identityManager;
22 22
     private final ServerManager serverManager;
23 23
     private final ActionManager actionManager;
24
+    private final PluginManager pluginManager;
24 25
     private final String configdir;
25 26
 
26 27
     public TestMain(final IdentityManager identityManager,
27 28
             final ServerManager serverManager,
28 29
             final ActionManager actionManager,
29 30
             final CommandLineParser commandLineParser,
31
+            final PluginManager pluginManager,
30 32
             final String configDir) {
31
-        super(identityManager, serverManager, actionManager, commandLineParser, configDir);
33
+        super(identityManager, serverManager, actionManager, commandLineParser, pluginManager, configDir);
32 34
         this.identityManager = identityManager;
33 35
         this.serverManager = serverManager;
34 36
         this.actionManager = actionManager;
37
+        this.pluginManager = pluginManager;
35 38
         this.configdir = configDir;
36 39
     }
37 40
 
@@ -47,9 +50,6 @@ public class TestMain extends Main {
47 50
             // to handleInvalidConfigFile(); here)
48 51
         }
49 52
 
50
-        final String fs = System.getProperty("file.separator");
51
-        final String pluginDirectory = configdir + "plugins" + fs;
52
-        pluginManager = new PluginManager(IdentityManager.getIdentityManager(), actionManager, pluginDirectory);
53 53
         pluginManager.refreshPlugins();
54 54
         CommandManager.initCommandManager(IdentityManager.getIdentityManager(), serverManager);
55 55
 
@@ -84,7 +84,12 @@ public class TestMain extends Main {
84 84
                 tempFile.delete();
85 85
                 tempFile.mkdir();
86 86
                 tempFile.deleteOnExit();
87
-                instance = new TestMain(identityManager, serverManager, actionManager, null, tempFile.getAbsolutePath() + File.separator);
87
+
88
+                final String configDirectory = tempFile.getAbsolutePath() + File.separator;
89
+                final String pluginDirectory = configDirectory + "plugins" + File.separator;
90
+                final PluginManager pluginManager = new PluginManager(identityManager, actionManager, pluginDirectory);
91
+
92
+                instance = new TestMain(identityManager, serverManager, actionManager, null, pluginManager, configDirectory);
88 93
                 instance.init();
89 94
             } catch (IOException ex) {
90 95
                 // Blargh.

Loading…
Annulla
Salva