Bladeren bron

Make the CommandLineParser less singleton-y.

(That's a word. Sssh.)

Change-Id: I1ff1b5072a7e0504702559cca353aad615ab97ed
Reviewed-on: http://gerrit.dmdirc.com/2680
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 jaren geleden
bovenliggende
commit
37f17e6a18
2 gewijzigde bestanden met toevoegingen van 33 en 20 verwijderingen
  1. 6
    3
      src/com/dmdirc/Main.java
  2. 27
    17
      src/com/dmdirc/commandline/CommandLineParser.java

+ 6
- 3
src/com/dmdirc/Main.java Bestand weergeven

@@ -133,7 +133,10 @@ public class Main implements LifecycleController {
133 133
     public void init(final String[] args) {
134 134
         Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());
135 135
 
136
-        final CommandLineParser clp = new CommandLineParser(this, args);
136
+        final CommandLineParser clp = new CommandLineParser(args);
137
+        if (clp.getConfigDirectory() != null) {
138
+            configdir = clp.getConfigDirectory();
139
+        }
137 140
 
138 141
         try {
139 142
             identityManager.initialise(getConfigDir());
@@ -152,7 +155,7 @@ public class Main implements LifecycleController {
152 155
 
153 156
         ThemeManager.loadThemes();
154 157
 
155
-        clp.applySettings();
158
+        clp.applySettings(identityManager.getGlobalConfigIdentity());
156 159
 
157 160
         new CommandLoader(this, serverManager, pluginManager, identityManager)
158 161
                 .loadCommands(CommandManager.initCommandManager(identityManager, serverManager));
@@ -176,7 +179,7 @@ public class Main implements LifecycleController {
176 179
         actionManager.loadUserActions();
177 180
         actionManager.triggerEvent(CoreActionType.CLIENT_OPENED, null);
178 181
 
179
-        clp.processArguments();
182
+        clp.processArguments(serverManager);
180 183
 
181 184
         GlobalWindow.init();
182 185
 

+ 27
- 17
src/com/dmdirc/commandline/CommandLineParser.java Bestand weergeven

@@ -23,7 +23,9 @@
23 23
 package com.dmdirc.commandline;
24 24
 
25 25
 import com.dmdirc.Main;
26
+import com.dmdirc.ServerManager;
26 27
 import com.dmdirc.commandparser.commands.global.NewServer;
28
+import com.dmdirc.config.Identity;
27 29
 import com.dmdirc.config.IdentityManager;
28 30
 import com.dmdirc.logger.ErrorLevel;
29 31
 import com.dmdirc.logger.Logger;
@@ -60,7 +62,7 @@ public class CommandLineParser {
60 62
     };
61 63
 
62 64
     /** A list of addresses to autoconnect to. */
63
-    private final List<URI> addresses = new ArrayList<URI>();
65
+    private final List<URI> addresses = new ArrayList<>();
64 66
 
65 67
     /** Whether to disable error reporting or not. */
66 68
     private boolean disablereporting;
@@ -68,19 +70,18 @@ public class CommandLineParser {
68 70
     /** The version string passed for the launcher. */
69 71
     private String launcherVersion = "";
70 72
 
73
+    /** The configuration directory. */
74
+    private String configDirectory;
75
+
71 76
     /** The RMI server we're using. */
72 77
     private RemoteInterface server;
73 78
 
74
-    /** Our parent Main. */
75
-    private Main main;
76
-
77 79
     /**
78 80
      * Creates a new instance of CommandLineParser.
79 81
      *
80 82
      * @param arguments The arguments to be parsed
81 83
      */
82
-    public CommandLineParser(final Main main, final String ... arguments) {
83
-        this.main = main;
84
+    public CommandLineParser(final String ... arguments) {
84 85
         boolean inArg = false;
85 86
         char previousArg = '.';
86 87
 
@@ -115,7 +116,7 @@ public class CommandLineParser {
115 116
             }
116 117
         }
117 118
 
118
-        new RemoteServer(main).bind();
119
+        new RemoteServer(Main.mainInstance).bind();
119 120
     }
120 121
 
121 122
     /**
@@ -252,11 +253,8 @@ public class CommandLineParser {
252 253
      * @param address The address the user told us to connect to
253 254
      */
254 255
     private void doConnect(final String address) {
255
-        URI myAddress = null;
256
-
257 256
         try {
258
-            myAddress = NewServer.getURI(address);
259
-            addresses.add(myAddress);
257
+            addresses.add(NewServer.getURI(address));
260 258
         } catch (URISyntaxException ex) {
261 259
             doUnknownArg("Invalid address specified: " + ex.getMessage());
262 260
         }
@@ -293,9 +291,9 @@ public class CommandLineParser {
293 291
      */
294 292
     private void doDirectory(final String dir) {
295 293
         if (dir.endsWith(File.separator)) {
296
-            main.setConfigDir(dir);
294
+            configDirectory = dir;
297 295
         } else {
298
-            main.setConfigDir(dir + File.separator);
296
+            configDirectory = dir + File.separator;
299 297
         }
300 298
     }
301 299
 
@@ -349,12 +347,22 @@ public class CommandLineParser {
349 347
         exit();
350 348
     }
351 349
 
350
+    /**
351
+     * Returns the user-supplied configuration directory.
352
+     *
353
+     * @return The user-supplied config directory, or {@code null} if none
354
+     * was supplied.
355
+     */
356
+    public String getConfigDirectory() {
357
+        return configDirectory;
358
+    }
359
+
352 360
     /**
353 361
      * Applies any applicable settings to the config identity.
354 362
      */
355
-    public void applySettings() {
363
+    public void applySettings(final Identity globalIdentity) {
356 364
         if (disablereporting) {
357
-            IdentityManager.getIdentityManager().getGlobalConfigIdentity().setOption("temp", "noerrorreporting", true);
365
+            globalIdentity.setOption("temp", "noerrorreporting", true);
358 366
         }
359 367
 
360 368
         if (!launcherVersion.isEmpty()) {
@@ -365,10 +373,12 @@ public class CommandLineParser {
365 373
     /**
366 374
      * Processes arguments once the client has been loaded properly.
367 375
      * This allows us to auto-connect to servers, etc.
376
+     *
377
+     * @param serverManager The server manager to use to connect servers.
368 378
      */
369
-    public void processArguments() {
379
+    public void processArguments(final ServerManager serverManager) {
370 380
         for (URI address : addresses)  {
371
-            main.getServerManager().connectToAddress(address);
381
+            serverManager.connectToAddress(address);
372 382
         }
373 383
     }
374 384
 

Laden…
Annuleren
Opslaan