Browse Source

Fix various dependencies.

Change-Id: I8a7de439f394086ec7c2a27fbef5c1ed6bc59dfe
Depends-On: I0d78fdc62431866377a06da819724a49e738b417
Reviewed-on: http://gerrit.dmdirc.com/2704
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
1a24895588

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

@@ -68,7 +68,7 @@ import dagger.Provides;
68 68
 /**
69 69
  * Provides dependencies for the client.
70 70
  */
71
-@Module(injects = Main.class, includes = CommandLineOptionsModule.class)
71
+@Module(injects = {Main.class, CommandLineParser.class}, includes = CommandLineOptionsModule.class)
72 72
 public class ClientModule {
73 73
 
74 74
     /**

+ 3
- 4
src/com/dmdirc/Main.java View File

@@ -25,7 +25,6 @@ package com.dmdirc;
25 25
 import com.dmdirc.interfaces.LifecycleController;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28
-import com.dmdirc.commandline.CommandLineOptionsModule;
29 28
 import com.dmdirc.commandline.CommandLineParser;
30 29
 import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.config.IdentityManager;
@@ -127,9 +126,9 @@ public class Main implements LifecycleController {
127 126
         Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());
128 127
 
129 128
         try {
130
-            ObjectGraph graph = ObjectGraph.create(
131
-                    new ClientModule(),
132
-                    new CommandLineOptionsModule(new CommandLineParser(args)));
129
+            final ObjectGraph graph = ObjectGraph.create(new ClientModule());
130
+            final CommandLineParser parser = graph.get(CommandLineParser.class);
131
+            parser.parse(args);
133 132
             mainInstance = graph.get(Main.class);
134 133
             mainInstance.init();
135 134
         } catch (Throwable ex) {

+ 3
- 24
src/com/dmdirc/commandline/CommandLineOptionsModule.java View File

@@ -31,7 +31,7 @@ import dagger.Provides;
31 31
 /**
32 32
  * Provides options based on the command line.
33 33
  */
34
-@Module(library = true)
34
+@Module(library = true, complete = false)
35 35
 public class CommandLineOptionsModule {
36 36
 
37 37
     /**
@@ -57,37 +57,16 @@ public class CommandLineOptionsModule {
57 57
         DirectoryType value();
58 58
     }
59 59
 
60
-    /** The parser to use for command-line information. */
61
-    private final CommandLineParser parser;
62
-
63
-    /**
64
-     * Creates a new {@link CommandLineOptionsModule}.
65
-     *
66
-     * @param parser The parser to use for command-line information.
67
-     */
68
-    public CommandLineOptionsModule(final CommandLineParser parser) {
69
-        this.parser = parser;
70
-    }
71
-
72
-    /**
73
-     * Provides the command-line parser used for this instance.
74
-     *
75
-     * @return The command-line parser.
76
-     */
77
-    @Provides
78
-    public CommandLineParser getParser() {
79
-        return parser;
80
-    }
81
-
82 60
     /**
83 61
      * Provides the base directory that all DMDirc user data is stored in.
84 62
      *
63
+     * @param parser The parser to get the user-supplied directory from.
85 64
      * @return The base directory.
86 65
      */
87 66
     @Provides
88 67
     @Singleton
89 68
     @Directory(DirectoryType.BASE)
90
-    public String getBaseDirectory() {
69
+    public String getBaseDirectory(final CommandLineParser parser) {
91 70
         if (parser.getConfigDirectory() == null) {
92 71
             return getDefaultBaseDirectory();
93 72
         } else {

+ 18
- 3
src/com/dmdirc/commandline/CommandLineParser.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.commandline;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.ServerManager;
27 26
 import com.dmdirc.commandparser.commands.global.NewServer;
28 27
 import com.dmdirc.config.IdentityManager;
@@ -37,9 +36,14 @@ import java.rmi.RemoteException;
37 36
 import java.util.ArrayList;
38 37
 import java.util.List;
39 38
 
39
+import javax.inject.Inject;
40
+import javax.inject.Provider;
41
+import javax.inject.Singleton;
42
+
40 43
 /**
41 44
  * Parses command line arguments for the client.
42 45
  */
46
+@Singleton
43 47
 public class CommandLineParser {
44 48
 
45 49
     /**
@@ -62,6 +66,9 @@ public class CommandLineParser {
62 66
     /** A list of addresses to autoconnect to. */
63 67
     private final List<URI> addresses = new ArrayList<>();
64 68
 
69
+    /** Provider to use to get server managers. */
70
+    private final Provider<ServerManager> serverManagerProvider;
71
+
65 72
     /** Whether to disable error reporting or not. */
66 73
     private boolean disablereporting;
67 74
 
@@ -76,10 +83,18 @@ public class CommandLineParser {
76 83
 
77 84
     /**
78 85
      * Creates a new instance of CommandLineParser.
86
+     */
87
+    @Inject
88
+    public CommandLineParser(final Provider<ServerManager> serverManagerProvider) {
89
+        this.serverManagerProvider = serverManagerProvider;
90
+    }
91
+
92
+    /**
93
+     * Parses the given arguments.
79 94
      *
80 95
      * @param arguments The arguments to be parsed
81 96
      */
82
-    public CommandLineParser(final String ... arguments) {
97
+    public void parse(final String ... arguments) {
83 98
         boolean inArg = false;
84 99
         char previousArg = '.';
85 100
 
@@ -114,7 +129,7 @@ public class CommandLineParser {
114 129
             }
115 130
         }
116 131
 
117
-        new RemoteServer(Main.mainInstance).bind();
132
+        new RemoteServer(serverManagerProvider).bind();
118 133
     }
119 134
 
120 135
     /**

+ 10
- 10
src/com/dmdirc/commandline/RemoteServer.java View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandline;
24 24
 
25
-import com.dmdirc.Main;
25
+import com.dmdirc.ServerManager;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28 28
 
@@ -34,6 +34,8 @@ import java.rmi.registry.Registry;
34 34
 import java.rmi.server.UnicastRemoteObject;
35 35
 import java.util.List;
36 36
 
37
+import javax.inject.Provider;
38
+
37 39
 /**
38 40
  * An RMI server that allows other clients to interact with DMDirc.
39 41
  */
@@ -43,23 +45,23 @@ public class RemoteServer implements RemoteInterface {
43 45
     private static final int MINPORT = 3634;
44 46
     /** The maximum port to use for RMI binding. */
45 47
     private static final int MAXPORT = MINPORT + 5;
46
-    /** The interface we're exposing. */
47
-    private final Main main;
48
+    /** Provider for the server manager to use to connect. */
49
+    private final Provider<ServerManager> serverManager;
48 50
 
49 51
     /**
50 52
      * Crate a new RemoteServer.
51 53
      *
52
-     * @param main Main instance to use to do things.
54
+     * @param serverManager Provider of a server manager to use to connect.
53 55
      */
54
-    public RemoteServer(final Main main) {
55
-        this.main = main;
56
+    public RemoteServer(final Provider<ServerManager> serverManager) {
57
+        this.serverManager = serverManager;
56 58
     }
57 59
 
58 60
     /** {@inheritDoc} */
59 61
     @Override
60 62
     public void connect(final List<URI> addresses) throws RemoteException {
61 63
         for (URI address : addresses) {
62
-            main.getServerManager().connectToAddress(address);
64
+            serverManager.get().connectToAddress(address);
63 65
         }
64 66
     }
65 67
 
@@ -106,9 +108,7 @@ public class RemoteServer implements RemoteInterface {
106 108
                 } else {
107 109
                     return iface;
108 110
                 }
109
-            } catch (RemoteException ex) {
110
-                continue;
111
-            } catch (NotBoundException ex) {
111
+            } catch (RemoteException | NotBoundException ex) {
112 112
                 continue;
113 113
             }
114 114
         }

+ 2
- 0
src/com/dmdirc/plugins/PluginInfo.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.Main;
26 26
 import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.actions.CoreActionType;
29
+import com.dmdirc.actions.wrappers.PerformWrapper;
29 30
 import com.dmdirc.commandparser.CommandManager;
30 31
 import com.dmdirc.config.Identity;
31 32
 import com.dmdirc.config.IdentityManager;
@@ -177,6 +178,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
177 178
         injector.addParameter(WindowManager.class, WindowManager.getWindowManager());
178 179
         injector.addParameter(StatusBarManager.getStatusBarManager());
179 180
         injector.addParameter(PreferencesManager.class, PreferencesManager.getPreferencesManager());
181
+        injector.addParameter(PerformWrapper.class, PerformWrapper.getPerformWrapper());
180 182
 
181 183
         return injector;
182 184
     }

+ 17
- 7
src/com/dmdirc/ui/core/util/URLHandler.java View File

@@ -22,8 +22,8 @@
22 22
 
23 23
 package com.dmdirc.ui.core.util;
24 24
 
25
+import com.dmdirc.ServerManager;
25 26
 import com.dmdirc.config.ConfigManager;
26
-import com.dmdirc.config.IdentityManager;
27 27
 import com.dmdirc.interfaces.ui.UIController;
28 28
 import com.dmdirc.logger.ErrorLevel;
29 29
 import com.dmdirc.logger.Logger;
@@ -47,6 +47,10 @@ public class URLHandler {
47 47
     private final UIController controller;
48 48
     /** Config manager. */
49 49
     private final ConfigManager config;
50
+    /** Server manager to use to connect to servers. */
51
+    private final ServerManager serverManager;
52
+    /** Status bar manager to use to show messages. */
53
+    private final StatusBarManager statusBarManager;
50 54
     /** Desktop handler. */
51 55
     private final Desktop desktop;
52 56
 
@@ -55,9 +59,15 @@ public class URLHandler {
55 59
      *
56 60
      * @param controller The UI controller to show dialogs etc on
57 61
      */
58
-    public URLHandler(final UIController controller) {
62
+    public URLHandler(
63
+            final UIController controller,
64
+            final ConfigManager globalConfig,
65
+            final ServerManager serverManager,
66
+            final StatusBarManager statusBarManager) {
59 67
         this.controller = controller;
60
-        this.config = IdentityManager.getIdentityManager().getGlobalConfiguration();
68
+        this.config = globalConfig;
69
+        this.serverManager = serverManager;
70
+        this.statusBarManager = statusBarManager;
61 71
         this.desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
62 72
     }
63 73
 
@@ -152,19 +162,19 @@ public class URLHandler {
152 162
         final String command = config.getOption("protocol", uri.getScheme().toLowerCase());
153 163
 
154 164
         if ("DMDIRC".equals(command)) {
155
-            StatusBarManager.getStatusBarManager().setMessage(
165
+            statusBarManager.setMessage(
156 166
                     new StatusMessage("Connecting to: " + uri.toString(),
157 167
                     config));
158
-            controller.getMain().getServerManager().connectToAddress(uri);
168
+            serverManager.connectToAddress(uri);
159 169
         } else if ("BROWSER".equals(command)) {
160
-            StatusBarManager.getStatusBarManager().setMessage(
170
+            statusBarManager.setMessage(
161 171
                     new StatusMessage("Opening: " + uri.toString(),
162 172
                     config));
163 173
             execBrowser(uri);
164 174
         } else if ("MAIL".equals(command)) {
165 175
             execMail(uri);
166 176
         } else {
167
-            StatusBarManager.getStatusBarManager().setMessage(
177
+            statusBarManager.setMessage(
168 178
                     new StatusMessage("Opening: " + uri.toString(),
169 179
                     config));
170 180
             execApp(substituteParams(uri, command));

Loading…
Cancel
Save