Browse Source

Stop ClientInfo being static.

pull/176/head
Greg Holmes 9 years ago
parent
commit
85c2ae537c

+ 1
- 0
.gitignore View File

@@ -1,5 +1,6 @@
1 1
 # DMDirc .gitignore file
2 2
 /build
3
+/generated
3 4
 /dist
4 5
 /lib
5 6
 /etc/clover.license

+ 1
- 0
build.gradle View File

@@ -29,6 +29,7 @@ configurations.all {
29 29
 dependencies {
30 30
     compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0'
31 31
     compile group: 'com.squareup.dagger', name: 'dagger-compiler', version: '1.2.1'
32
+    compile group: 'com.google.auto.value', name: 'auto-value', version: '1.0-rc1'
32 33
 
33 34
     bundle group: 'com.squareup.dagger', name: 'dagger', version: '1.2.1'
34 35
     bundle group: 'com.esotericsoftware.yamlbeans', name: 'yamlbeans', version: '1.08'

+ 9
- 4
src/com/dmdirc/config/ConfigManager.java View File

@@ -61,6 +61,8 @@ class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
61 61
     private final ConfigBinder binder = new ConfigBinder(this);
62 62
     /** The manager to use to fetch global state. */
63 63
     private final IdentityManager manager;
64
+    /** Client info object. */
65
+    private final ClientInfo clientInfo;
64 66
     /** The protocol this manager is for. */
65 67
     private String protocol;
66 68
     /** The ircd this manager is for. */
@@ -84,10 +86,11 @@ class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
84 86
      * @since 0.6.3
85 87
      */
86 88
     ConfigManager(
89
+            final ClientInfo clientInfo,
87 90
             final IdentityManager manager,
88 91
             final String protocol, final String ircd,
89 92
             final String network, final String server) {
90
-        this(manager, protocol, ircd, network, server, "<Unknown>");
93
+        this(clientInfo, manager, protocol, ircd, network, server, "<Unknown>");
91 94
     }
92 95
 
93 96
     /**
@@ -103,11 +106,13 @@ class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
103 106
      * @since 0.6.3
104 107
      */
105 108
     ConfigManager(
109
+            final ClientInfo clientInfo,
106 110
             final IdentityManager manager,
107 111
             final String protocol, final String ircd,
108 112
             final String network, final String server, final String channel) {
109
-        final String chanName = channel + "@" + network;
113
+        final String chanName = channel + '@' + network;
110 114
 
115
+        this.clientInfo = clientInfo;
111 116
         this.manager = manager;
112 117
         this.protocol = protocol;
113 118
         this.ircd = ircd;
@@ -127,7 +132,7 @@ class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
127 132
         doStats(domain, option);
128 133
 
129 134
         if (VERSION_DOMAIN.equals(domain)) {
130
-            final String response = ClientInfo.getVersionConfigSetting(VERSION_DOMAIN, option);
135
+            final String response = clientInfo.getVersionConfigSetting(VERSION_DOMAIN, option);
131 136
             if (response == null || validator.validate(response).isFailure()) {
132 137
                 return null;
133 138
             }
@@ -151,7 +156,7 @@ class ConfigManager extends BaseConfigProvider implements ConfigChangeListener,
151 156
         doStats(domain, option);
152 157
 
153 158
         if (VERSION_DOMAIN.equals(domain)) {
154
-            final String response = ClientInfo.getVersionConfigSetting(VERSION_DOMAIN, option);
159
+            final String response = clientInfo.getVersionConfigSetting(VERSION_DOMAIN, option);
155 160
             return response != null && !validator.validate(response).isFailure();
156 161
         }
157 162
 

+ 6
- 3
src/com/dmdirc/config/ConfigModule.java View File

@@ -32,6 +32,7 @@ import com.dmdirc.logger.ErrorLevel;
32 32
 import com.dmdirc.logger.ErrorManager;
33 33
 import com.dmdirc.logger.Logger;
34 34
 import com.dmdirc.ui.WarningDialog;
35
+import com.dmdirc.util.ClientInfo;
35 36
 
36 37
 import java.awt.GraphicsEnvironment;
37 38
 import java.io.IOException;
@@ -65,11 +66,13 @@ public class ConfigModule {
65 66
             @Directory(DirectoryType.IDENTITIES) final Path identitiesDirectory,
66 67
             @Directory(DirectoryType.ERRORS) final Path errorsDirectory,
67 68
             final CommandLineParser commandLineParser,
68
-            final DMDircMBassador eventBus) {
69
+            final DMDircMBassador eventBus,
70
+            final ClientInfo clientInfo) {
69 71
         final IdentityManager identityManager = new IdentityManager(baseDirectory,
70
-                identitiesDirectory, eventBus);
72
+                identitiesDirectory, eventBus, clientInfo);
71 73
         ErrorManager.getErrorManager()
72
-                .initialise(identityManager.getGlobalConfiguration(), errorsDirectory, eventBus);
74
+                .initialise(identityManager.getGlobalConfiguration(), errorsDirectory, eventBus,
75
+                        clientInfo);
73 76
         identityManager.loadVersionIdentity();
74 77
 
75 78
         try {

+ 13
- 7
src/com/dmdirc/config/IdentityManager.java View File

@@ -33,6 +33,7 @@ import com.dmdirc.interfaces.config.ConfigProviderMigrator;
33 33
 import com.dmdirc.interfaces.config.IdentityController;
34 34
 import com.dmdirc.interfaces.config.IdentityFactory;
35 35
 import com.dmdirc.logger.ErrorLevel;
36
+import com.dmdirc.util.ClientInfo;
36 37
 import com.dmdirc.util.collections.MapList;
37 38
 import com.dmdirc.util.collections.WeakMapList;
38 39
 import com.dmdirc.util.io.ConfigFile;
@@ -91,6 +92,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
91 92
      * specific custom type use their type as the key.
92 93
      */
93 94
     private final MapList<String, ConfigProviderListener> listeners = new WeakMapList<>();
95
+    /** Client info objecty. */
96
+    private final ClientInfo clientInfo;
94 97
     /** The identity file used for the global config. */
95 98
     private ConfigProvider config;
96 99
     /** The identity file used for addon defaults. */
@@ -108,10 +111,11 @@ public class IdentityManager implements IdentityFactory, IdentityController {
108 111
      * @param eventBus            The event bus to post events to
109 112
      */
110 113
     public IdentityManager(final Path baseDirectory, final Path identitiesDirectory,
111
-            final DMDircMBassador eventBus) {
114
+            final DMDircMBassador eventBus, final ClientInfo clientInfo) {
112 115
         this.configDirectory = baseDirectory;
113 116
         this.identitiesDirectory = identitiesDirectory;
114 117
         this.eventBus = eventBus;
118
+        this.clientInfo = clientInfo;
115 119
     }
116 120
 
117 121
     /**
@@ -669,7 +673,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
669 673
     @Override
670 674
     public ConfigProviderMigrator createMigratableConfig(final String protocol,
671 675
             final String ircd, final String network, final String server) {
672
-        final ConfigManager configManager = new ConfigManager(this, protocol, ircd, network, server);
676
+        final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol, ircd,
677
+                network, server);
673 678
         setUpConfigManager(configManager);
674 679
         return new ConfigManagerMigrator(configManager);
675 680
     }
@@ -677,8 +682,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
677 682
     @Override
678 683
     public ConfigProviderMigrator createMigratableConfig(final String protocol,
679 684
             final String ircd, final String network, final String server, final String channel) {
680
-        final ConfigManager configManager = new ConfigManager(this, protocol, ircd, network, server,
681
-                channel);
685
+        final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol, ircd,
686
+                network, server, channel);
682 687
         setUpConfigManager(configManager);
683 688
         return new ConfigManagerMigrator(configManager);
684 689
     }
@@ -686,7 +691,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
686 691
     @Override
687 692
     public AggregateConfigProvider createAggregateConfig(final String protocol, final String ircd,
688 693
             final String network, final String server) {
689
-        final ConfigManager configManager = new ConfigManager(this, protocol, ircd, network, server);
694
+        final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol, ircd,
695
+                network, server);
690 696
         setUpConfigManager(configManager);
691 697
         return configManager;
692 698
     }
@@ -694,8 +700,8 @@ public class IdentityManager implements IdentityFactory, IdentityController {
694 700
     @Override
695 701
     public AggregateConfigProvider createAggregateConfig(final String protocol, final String ircd,
696 702
             final String network, final String server, final String channel) {
697
-        final ConfigManager configManager = new ConfigManager(this, protocol, ircd, network, server,
698
-                channel);
703
+        final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol, ircd,
704
+                network, server, channel);
699 705
         setUpConfigManager(configManager);
700 706
         return configManager;
701 707
     }

+ 5
- 2
src/com/dmdirc/logger/ErrorManager.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.events.UserErrorEvent;
28 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 29
 import com.dmdirc.interfaces.config.ConfigChangeListener;
30 30
 import com.dmdirc.ui.FatalErrorDialog;
31
+import com.dmdirc.util.ClientInfo;
31 32
 import com.dmdirc.util.collections.ListenerList;
32 33
 
33 34
 import java.awt.GraphicsEnvironment;
@@ -74,6 +75,7 @@ public class ErrorManager implements ConfigChangeListener {
74 75
     private AggregateConfigProvider config;
75 76
     /** Directory to store errors in. */
76 77
     private Path errorsDirectory;
78
+    private ClientInfo clientInfo;
77 79
 
78 80
     /** Creates a new instance of ErrorListDialog. */
79 81
     public ErrorManager() {
@@ -89,7 +91,8 @@ public class ErrorManager implements ConfigChangeListener {
89 91
      * @param eventBus     The event bus to listen for error events on.
90 92
      */
91 93
     public void initialise(final AggregateConfigProvider globalConfig, final Path directory,
92
-            final DMDircMBassador eventBus) {
94
+            final DMDircMBassador eventBus, final ClientInfo clientInfo) {
95
+        this.clientInfo = clientInfo;
93 96
         eventBus.subscribe(this);
94 97
         RavenFactory.registerFactory(new DefaultRavenFactory());
95 98
 
@@ -272,7 +275,7 @@ public class ErrorManager implements ConfigChangeListener {
272 275
     protected ProgramError getError(final ErrorLevel level, final String message,
273 276
             final Throwable exception, final String details) {
274 277
         return new ProgramError(nextErrorID.getAndIncrement(), level, message, exception,
275
-                details, new Date());
278
+                details, new Date(), clientInfo);
276 279
     }
277 280
 
278 281
     /**

+ 16
- 11
src/com/dmdirc/logger/ErrorReporter.java View File

@@ -47,6 +47,11 @@ public class ErrorReporter {
47 47
             + "e0a8aa1ecca14568a9f52d052ecf6a30@sentry.dmdirc.com/2?raven.async=false";
48 48
     /** Template to use when sending mode alias reports. */
49 49
     private static final String MODE_ALIAS_TEMPLATE = "%s\n\nConnection headers:\n%s";
50
+    private final ClientInfo clientInfo;
51
+
52
+    public ErrorReporter(final ClientInfo clientInfo) {
53
+        this.clientInfo = clientInfo;
54
+    }
50 55
 
51 56
     /**
52 57
      * Sends an error report caused by some kind of exception.
@@ -141,17 +146,17 @@ public class ErrorReporter {
141 146
     private EventBuilder newEventBuilder() {
142 147
         return new EventBuilder()
143 148
                 .setServerName("")
144
-                .addTag("version", ClientInfo.getVersion())
145
-                .addTag("version.major", ClientInfo.getMajorVersion())
146
-                .addTag("os.name", ClientInfo.getOperatingSystemName())
147
-                .addTag("os.version", ClientInfo.getOperatingSystemVersion())
148
-                .addTag("os.arch", ClientInfo.getOperatingSystemArchitecture())
149
-                .addTag("encoding", ClientInfo.getSystemFileEncoding())
150
-                .addTag("locale", ClientInfo.getSystemDefaultLocale())
151
-                .addTag("jvm.name", ClientInfo.getJavaName())
152
-                .addTag("jvm.vendor", ClientInfo.getJavaVendor())
153
-                .addTag("jvm.version", ClientInfo.getJavaVersion())
154
-                .addTag("jvm.version.major", ClientInfo.getJavaMajorVersion());
149
+                .addTag("version", clientInfo.getVersion())
150
+                .addTag("version.major", clientInfo.getMajorVersion())
151
+                .addTag("os.name", clientInfo.getOperatingSystemName())
152
+                .addTag("os.version", clientInfo.getOperatingSystemVersion())
153
+                .addTag("os.arch", clientInfo.getOperatingSystemArchitecture())
154
+                .addTag("encoding", clientInfo.getSystemFileEncoding())
155
+                .addTag("locale", clientInfo.getSystemDefaultLocale())
156
+                .addTag("jvm.name", clientInfo.getJavaName())
157
+                .addTag("jvm.vendor", clientInfo.getJavaVendor())
158
+                .addTag("jvm.version", clientInfo.getJavaVersion())
159
+                .addTag("jvm.version.major", clientInfo.getJavaMajorVersion());
155 160
     }
156 161
 
157 162
     /**

+ 5
- 2
src/com/dmdirc/logger/ProgramError.java View File

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.logger;
24 24
 
25
+import com.dmdirc.util.ClientInfo;
26
+
25 27
 import java.io.IOException;
26 28
 import java.io.OutputStream;
27 29
 import java.io.PrintWriter;
@@ -84,7 +86,8 @@ public final class ProgramError implements Serializable {
84 86
     public ProgramError(final long id, final ErrorLevel level, final String message,
85 87
             @Nullable final Throwable exception,
86 88
             @Nullable final String details,
87
-            final Date date) {
89
+            final Date date,
90
+            final ClientInfo clientInfo) {
88 91
 
89 92
         if (id < 0) {
90 93
             throw new IllegalArgumentException("ID must be a positive integer: " + id);
@@ -111,7 +114,7 @@ public final class ProgramError implements Serializable {
111 114
         this.lastDate = (Date) date.clone();
112 115
         this.count = new AtomicInteger(1);
113 116
         this.reportStatus = ErrorReportStatus.WAITING;
114
-        this.reporter = new ErrorReporter();
117
+        this.reporter = new ErrorReporter(clientInfo);
115 118
     }
116 119
 
117 120
     /**

+ 7
- 4
src/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModel.java View File

@@ -52,6 +52,7 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
52 52
     private final AggregateConfigProvider config;
53 53
     private final ConnectionManager connectionManager;
54 54
     private final Path configDirectory;
55
+    private final ClientInfo clientInfo;
55 56
     private Optional<String> name;
56 57
     private Optional<String> email;
57 58
     private Optional<String> feedback;
@@ -61,11 +62,13 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
61 62
     @Inject
62 63
     public CoreFeedbackDialogModel(@ClientModule.GlobalConfig final AggregateConfigProvider config,
63 64
             final ConnectionManager connectionManager, final FeedbackSenderFactory feedbackSenderFactory,
64
-            @Directory(DirectoryType.BASE) final Path configDirectory) {
65
+            @Directory(DirectoryType.BASE) final Path configDirectory,
66
+            final ClientInfo clientInfo) {
65 67
         this.connectionManager = connectionManager;
66 68
         this.configDirectory = configDirectory;
67 69
         this.feedbackSenderFactory = feedbackSenderFactory;
68 70
         this.config = config;
71
+        this.clientInfo = clientInfo;
69 72
         this.listeners = new ListenerList();
70 73
         name = Optional.empty();
71 74
         email = Optional.empty();
@@ -194,12 +197,12 @@ public class CoreFeedbackDialogModel implements FeedbackDialogModel {
194 197
             }
195 198
         }
196 199
         if (getIncludeDMDircInfo()) {
197
-            dmdircInfo.append("DMDirc version: ").append(ClientInfo.getVersionInformation())
200
+            dmdircInfo.append("DMDirc version: ").append(clientInfo.getVersionInformation())
198 201
                     .append('\n');
199 202
             dmdircInfo.append("Profile directory: ").append(configDirectory).append('\n');
200
-            dmdircInfo.append("Java version: ").append(ClientInfo.getJavaInformation())
203
+            dmdircInfo.append("Java version: ").append(clientInfo.getJavaInformation())
201 204
                     .append('\n');
202
-            dmdircInfo.append("OS Version: ").append(ClientInfo.getOperatingSystemInformation());
205
+            dmdircInfo.append("OS Version: ").append(clientInfo.getOperatingSystemInformation());
203 206
         }
204 207
         final FeedbackSender sender = feedbackSenderFactory.getFeedbackSender(
205 208
                 name.orElse(""), email.orElse(""), feedback.orElse(""),

+ 31
- 26
src/com/dmdirc/util/ClientInfo.java View File

@@ -29,13 +29,17 @@ import java.io.IOException;
29 29
 import java.lang.management.ManagementFactory;
30 30
 import java.util.Locale;
31 31
 
32
+import javax.inject.Inject;
33
+import javax.inject.Singleton;
34
+
32 35
 import org.slf4j.Logger;
33 36
 import org.slf4j.LoggerFactory;
34 37
 
35 38
 /**
36 39
  * Provides static utility methods to access information about the client and its environment.
37 40
  */
38
-public final class ClientInfo {
41
+@Singleton
42
+public class ClientInfo {
39 43
 
40 44
     private static final Logger LOG = LoggerFactory.getLogger(ClientInfo.class);
41 45
     /** Domain to read version settings from. */
@@ -49,126 +53,127 @@ public final class ClientInfo {
49 53
     /** Fallback value to use if a system property isn't found. */
50 54
     private static final String PROPERTY_FALLBACK = "unknown";
51 55
     /** Lock used to guard access to {@link #versionConfig}. */
52
-    private static final Object VERSION_CONFIG_LOCK = new Object();
56
+    private final Object VERSION_CONFIG_LOCK = new Object();
53 57
     /** Cached config file containing the client's version information. */
54
-    private static ConfigFile versionConfig;
58
+    private ConfigFile versionConfig;
55 59
 
56
-    private ClientInfo() {
60
+    @Inject
61
+    public ClientInfo() {
57 62
         // Shouldn't be initialised.
58 63
     }
59 64
 
60 65
     /**
61 66
      * @return The version of the client.
62 67
      */
63
-    public static String getVersion() {
68
+    public String getVersion() {
64 69
         return getVersionConfigSetting(VERSION_DOMAIN, VERSION_KEY);
65 70
     }
66 71
 
67 72
     /**
68 73
      * @return The major version of the client.
69 74
      */
70
-    public static String getMajorVersion() {
75
+    public String getMajorVersion() {
71 76
         return getVersion().replaceAll("(-|rc|a|b|m).*", "");
72 77
     }
73 78
 
74 79
     /**
75 80
      * @return The channel that this client was built for.
76 81
      */
77
-    public static String getUpdaterChannel() {
82
+    public String getUpdaterChannel() {
78 83
         return getVersionConfigSetting(UPDATER_DOMAIN, UPDATER_CHANNEL_KEY);
79 84
     }
80 85
 
81 86
     /**
82 87
      * @return The name of the operating system the client is running on.
83 88
      */
84
-    public static String getOperatingSystemName() {
89
+    public String getOperatingSystemName() {
85 90
         return System.getProperty("os.name", PROPERTY_FALLBACK);
86 91
     }
87 92
 
88 93
     /**
89 94
      * @return The version of the operating system the client is running on.
90 95
      */
91
-    public static String getOperatingSystemVersion() {
96
+    public String getOperatingSystemVersion() {
92 97
         return System.getProperty("os.version", PROPERTY_FALLBACK);
93 98
     }
94 99
 
95 100
     /**
96 101
      * @return The name of the architecture that the operating system is built for.
97 102
      */
98
-    public static String getOperatingSystemArchitecture() {
103
+    public String getOperatingSystemArchitecture() {
99 104
         return System.getProperty("os.arch", PROPERTY_FALLBACK);
100 105
     }
101 106
 
102 107
     /**
103 108
      * @return The default file encoding used by the system.
104 109
      */
105
-    public static String getSystemFileEncoding() {
110
+    public String getSystemFileEncoding() {
106 111
         return System.getProperty("file.encoding", PROPERTY_FALLBACK);
107 112
     }
108 113
 
109 114
     /**
110 115
      * @return The default locale used by the system.
111 116
      */
112
-    public static String getSystemDefaultLocale() {
117
+    public String getSystemDefaultLocale() {
113 118
         return Locale.getDefault().toString();
114 119
     }
115 120
 
116 121
     /**
117 122
      * @return The name of the JVM running the client.
118 123
      */
119
-    public static String getJavaName() {
124
+    public String getJavaName() {
120 125
         return System.getProperty("java.vm.name", PROPERTY_FALLBACK);
121 126
     }
122 127
 
123 128
     /**
124 129
      * @return The name of the vendor of the JVM running the client.
125 130
      */
126
-    public static String getJavaVendor() {
131
+    public String getJavaVendor() {
127 132
         return System.getProperty("java.vm.vendor", PROPERTY_FALLBACK);
128 133
     }
129 134
 
130 135
     /**
131 136
      * @return The version of the JVM running the client.
132 137
      */
133
-    public static String getJavaVersion() {
138
+    public String getJavaVersion() {
134 139
         return System.getProperty("java.version", PROPERTY_FALLBACK);
135 140
     }
136 141
 
137 142
     /**
138 143
      * @return The major version of the JVM running the client.
139 144
      */
140
-    public static String getJavaMajorVersion() {
145
+    public String getJavaMajorVersion() {
141 146
         return getJavaVersion().replaceAll("_.*", "");
142 147
     }
143 148
 
144 149
     /**
145 150
      * @return The uptime for the client in milliseconds.
146 151
      */
147
-    public static long getUptime() {
152
+    public long getUptime() {
148 153
         return ManagementFactory.getRuntimeMXBean().getUptime();
149 154
     }
150 155
 
151 156
     /**
152 157
      * @return A string containing the DMDirc version and updater channel.
153 158
      */
154
-    public static String getVersionInformation() {
155
-        return getVersion() + " (" + getUpdaterChannel() + ")";
159
+    public String getVersionInformation() {
160
+        return getVersion() + " (" + getUpdaterChannel() + ')';
156 161
     }
157 162
 
158 163
     /**
159 164
      * @return A string containing the JVM name, version, and vendor.
160 165
      */
161
-    public static String getJavaInformation() {
162
-        return getJavaName() + " " + getJavaVersion() + " [" + getJavaVendor() + "]";
166
+    public String getJavaInformation() {
167
+        return getJavaName() + ' ' + getJavaVersion() + " [" + getJavaVendor() + ']';
163 168
     }
164 169
 
165 170
     /**
166 171
      * @return A string containing the OS name, version and architecture, and the default file
167 172
      *         encoding and locale.
168 173
      */
169
-    public static String getOperatingSystemInformation() {
170
-        return getOperatingSystemName() + " "
171
-                + getOperatingSystemVersion() + " "
174
+    public String getOperatingSystemInformation() {
175
+        return getOperatingSystemName() + ' '
176
+                + getOperatingSystemVersion() + ' '
172 177
                 + getOperatingSystemArchitecture() + "; "
173 178
                 + getSystemFileEncoding() + "; "
174 179
                 + getSystemDefaultLocale();
@@ -182,7 +187,7 @@ public final class ClientInfo {
182 187
      *
183 188
      * @return The value of the key within the version config, or {@code null} if it doesn't exist.
184 189
      */
185
-    public static String getVersionConfigSetting(final String domain, final String key) {
190
+    public String getVersionConfigSetting(final String domain, final String key) {
186 191
         return getVersionConfig().getKeyDomain(domain).get(key);
187 192
     }
188 193
 
@@ -194,7 +199,7 @@ public final class ClientInfo {
194 199
      *
195 200
      * @return The client's bundled version config file.
196 201
      */
197
-    private static ConfigFile getVersionConfig() {
202
+    private ConfigFile getVersionConfig() {
198 203
         synchronized (VERSION_CONFIG_LOCK) {
199 204
             if (versionConfig == null) {
200 205
                 LOG.debug("No previous version config cached, creating a new one...");

+ 13
- 6
test/com/dmdirc/config/ConfigManagerTest.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.config;
24 24
 
25 25
 import com.dmdirc.interfaces.config.ConfigChangeListener;
26
+import com.dmdirc.util.ClientInfo;
26 27
 import com.dmdirc.util.validators.PermissiveValidator;
27 28
 
28 29
 import org.junit.Test;
@@ -30,23 +31,29 @@ import org.junit.runner.RunWith;
30 31
 import org.mockito.Mock;
31 32
 import org.mockito.runners.MockitoJUnitRunner;
32 33
 
33
-import static org.junit.Assert.*;
34
-import static org.mockito.Mockito.*;
34
+import static org.junit.Assert.assertEquals;
35
+import static org.junit.Assert.assertNotNull;
36
+import static org.junit.Assert.assertNull;
37
+import static org.mockito.Mockito.anyString;
38
+import static org.mockito.Mockito.mock;
39
+import static org.mockito.Mockito.never;
40
+import static org.mockito.Mockito.verify;
35 41
 
36 42
 @RunWith(MockitoJUnitRunner.class)
37 43
 public class ConfigManagerTest {
38 44
 
39 45
     @Mock private IdentityManager identityManager;
46
+    @Mock private ClientInfo clientInfo;
40 47
 
41 48
     @Test
42 49
     public void testNonExistantOption() {
43
-        assertNull(new ConfigManager(identityManager, "", "", "", "")
50
+        assertNull(new ConfigManager(clientInfo, identityManager, "", "", "", "")
44 51
                 .getOption("unit-test123", "foobar"));
45 52
     }
46 53
 
47 54
     @Test
48 55
     public void testStats() {
49
-        final ConfigManager cm = new ConfigManager(identityManager, "", "", "", "");
56
+        final ConfigManager cm = new ConfigManager(clientInfo, identityManager, "", "", "", "");
50 57
         assertNull(ConfigManager.getStats().get("unit-test123.baz"));
51 58
         cm.hasOption("unit-test123", "baz", new PermissiveValidator<String>());
52 59
         assertNotNull(ConfigManager.getStats().get("unit-test123.baz"));
@@ -56,7 +63,7 @@ public class ConfigManagerTest {
56 63
     @Test
57 64
     public void testDomainListener() {
58 65
         final ConfigChangeListener listener = mock(ConfigChangeListener.class);
59
-        final ConfigManager cm = new ConfigManager(identityManager, "", "", "", "");
66
+        final ConfigManager cm = new ConfigManager(clientInfo, identityManager, "", "", "", "");
60 67
         cm.addChangeListener("unit-test", listener);
61 68
 
62 69
         cm.configChanged("foo", "bar");
@@ -69,7 +76,7 @@ public class ConfigManagerTest {
69 76
     @Test
70 77
     public void testDomainKeyListener() {
71 78
         final ConfigChangeListener listener = mock(ConfigChangeListener.class);
72
-        final ConfigManager cm = new ConfigManager(identityManager, "", "", "", "");
79
+        final ConfigManager cm = new ConfigManager(clientInfo, identityManager, "", "", "", "");
73 80
         cm.addChangeListener("unit-test", "foo", listener);
74 81
 
75 82
         cm.configChanged("foo", "bar");

+ 5
- 3
test/com/dmdirc/config/IdentityManagerTest.java View File

@@ -24,6 +24,7 @@ package com.dmdirc.config;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.interfaces.config.ConfigProvider;
27
+import com.dmdirc.util.ClientInfo;
27 28
 
28 29
 import com.google.common.jimfs.Configuration;
29 30
 import com.google.common.jimfs.Jimfs;
@@ -47,6 +48,7 @@ import static org.junit.Assert.assertNotNull;
47 48
 public class IdentityManagerTest {
48 49
 
49 50
     @Mock private DMDircMBassador eventBus;
51
+    @Mock private ClientInfo clientInfo;
50 52
 
51 53
     private Path baseDirectory;
52 54
     private Path identitiesDirectory;
@@ -62,7 +64,7 @@ public class IdentityManagerTest {
62 64
     @Test
63 65
     public void testLoadsVersionIdentity() throws InvalidIdentityFileException {
64 66
         final IdentityManager identityManager = new IdentityManager(
65
-                baseDirectory, identitiesDirectory, eventBus);
67
+                baseDirectory, identitiesDirectory, eventBus, clientInfo);
66 68
         identityManager.initialise();
67 69
 
68 70
         final ConfigProvider versionSettings = identityManager.getVersionSettings();
@@ -74,7 +76,7 @@ public class IdentityManagerTest {
74 76
     @Test
75 77
     public void testUsesSystemUsernameForProfileNickname() throws InvalidIdentityFileException {
76 78
         final IdentityManager identityManager = new IdentityManager(
77
-                baseDirectory, identitiesDirectory, eventBus);
79
+                baseDirectory, identitiesDirectory, eventBus, clientInfo);
78 80
         identityManager.initialise();
79 81
 
80 82
         System.setProperty("user.name", "Awesome User");
@@ -90,7 +92,7 @@ public class IdentityManagerTest {
90 92
                 identitiesDirectory.resolve("profile"));
91 93
 
92 94
         final IdentityManager identityManager = new IdentityManager(
93
-                baseDirectory, identitiesDirectory, eventBus);
95
+                baseDirectory, identitiesDirectory, eventBus, clientInfo);
94 96
         identityManager.initialise();
95 97
 
96 98
         final List<ConfigProvider> profiles = identityManager.getProvidersByType("profile");

+ 3
- 1
test/com/dmdirc/logger/ErrorReporterTest.java View File

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.logger;
24 24
 
25
+import com.dmdirc.util.ClientInfo;
26
+
25 27
 import java.util.Date;
26 28
 
27 29
 import org.junit.Before;
@@ -66,7 +68,7 @@ public class ErrorReporterTest {
66 68
     @Before
67 69
     public void setUp() {
68 70
         when(ravenFactory.createRavenInstance(Matchers.<Dsn>anyObject())).thenReturn(raven);
69
-        errorReporter = new ErrorReporter();
71
+        errorReporter = new ErrorReporter(new ClientInfo());
70 72
     }
71 73
 
72 74
     @Test

+ 20
- 16
test/com/dmdirc/logger/ProgramErrorTest.java View File

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.logger;
24 24
 
25
+import com.dmdirc.util.ClientInfo;
26
+
25 27
 import java.util.Date;
26 28
 
27 29
 import org.junit.Before;
@@ -38,6 +40,7 @@ import static org.junit.Assert.assertTrue;
38 40
 public class ProgramErrorTest {
39 41
 
40 42
     @Mock private ErrorManager errorManager;
43
+    @Mock private ClientInfo clientInfo;
41 44
 
42 45
     @Before
43 46
     public void setup() {
@@ -46,45 +49,46 @@ public class ProgramErrorTest {
46 49
 
47 50
     @Test(expected = IllegalArgumentException.class)
48 51
     public void testConstructorNegativeID() {
49
-        new ProgramError(-1, ErrorLevel.HIGH, "moo", null, null, new Date());
52
+        new ProgramError(-1, ErrorLevel.HIGH, "moo", null, null, new Date(), clientInfo);
50 53
     }
51 54
 
52 55
     @Test(expected = IllegalArgumentException.class)
53 56
     public void testConstructorNullErrorLevel() {
54
-        new ProgramError(1, null, "moo", null, null, new Date());
57
+        new ProgramError(1, null, "moo", null, null, new Date(), clientInfo);
55 58
     }
56 59
 
57 60
     @Test(expected = IllegalArgumentException.class)
58 61
     public void testConstructorNullMessage() {
59
-        new ProgramError(1, ErrorLevel.HIGH, null, null, null, new Date());
62
+        new ProgramError(1, ErrorLevel.HIGH, null, null, null, new Date(), clientInfo);
60 63
     }
61 64
 
62 65
     @Test(expected = IllegalArgumentException.class)
63 66
     public void testConstructorEmptyMessage() {
64
-        new ProgramError(1, ErrorLevel.HIGH, "", null, null, new Date());
67
+        new ProgramError(1, ErrorLevel.HIGH, "", null, null, new Date(), clientInfo);
65 68
     }
66 69
 
67 70
     @Test(expected = IllegalArgumentException.class)
68 71
     public void testConstructorNullDate() {
69
-        new ProgramError(1, ErrorLevel.HIGH, "moo", null, null, null);
72
+        new ProgramError(1, ErrorLevel.HIGH, "moo", null, null, null, clientInfo);
70 73
     }
71 74
 
72 75
     @Test
73 76
     public void testConstructorGood() {
74
-        new ProgramError(1, ErrorLevel.HIGH, "moo", new UnsupportedOperationException(), null, new Date());
77
+        new ProgramError(1, ErrorLevel.HIGH, "moo", new UnsupportedOperationException(),
78
+                null, new Date(), clientInfo);
75 79
     }
76 80
 
77 81
     @Test
78 82
     public void testGetLevel() {
79 83
         final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
80
-                new UnsupportedOperationException(), null, new Date());
84
+                new UnsupportedOperationException(), null, new Date(), clientInfo);
81 85
         assertEquals(ErrorLevel.HIGH, pe.getLevel());
82 86
     }
83 87
 
84 88
     @Test
85 89
     public void testGetMessage() {
86 90
         final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
87
-                new UnsupportedOperationException(), null, new Date());
91
+                new UnsupportedOperationException(), null, new Date(), clientInfo);
88 92
         assertEquals("moo", pe.getMessage());
89 93
     }
90 94
 
@@ -92,14 +96,14 @@ public class ProgramErrorTest {
92 96
     public void testGetDate() {
93 97
         final Date date = new Date();
94 98
         final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
95
-                new UnsupportedOperationException(), null, date);
99
+                new UnsupportedOperationException(), null, date, clientInfo);
96 100
         assertEquals(date, pe.getDate());
97 101
     }
98 102
 
99 103
     @Test
100 104
     public void testReportStatus() {
101 105
         final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
102
-                new UnsupportedOperationException(), null, new Date());
106
+                new UnsupportedOperationException(), null, new Date(), clientInfo);
103 107
         assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
104 108
         pe.setReportStatus(null);
105 109
         assertEquals(ErrorReportStatus.WAITING, pe.getReportStatus());
@@ -112,7 +116,7 @@ public class ProgramErrorTest {
112 116
     @Test
113 117
     public void testToString() {
114 118
         final ProgramError pe = new ProgramError(1, ErrorLevel.HIGH, "moo",
115
-                new UnsupportedOperationException(), null, new Date());
119
+                new UnsupportedOperationException(), null, new Date(), clientInfo);
116 120
         assertTrue(pe.toString().contains("moo"));
117 121
     }
118 122
 
@@ -120,15 +124,15 @@ public class ProgramErrorTest {
120 124
     public void testEquals() {
121 125
         final Exception ex = new UnsupportedOperationException();
122 126
         final ProgramError pe1 = new ProgramError(10, ErrorLevel.LOW, "moo",
123
-                ex, null, new Date());
127
+                ex, null, new Date(), clientInfo);
124 128
         final ProgramError pe2 = new ProgramError(11, ErrorLevel.LOW, "moo",
125
-                ex, null, new Date());
129
+                ex, null, new Date(), clientInfo);
126 130
         final ProgramError pe3 = new ProgramError(10, ErrorLevel.MEDIUM, "moo",
127
-                ex, null, new Date());
131
+                ex, null, new Date(), clientInfo);
128 132
         final ProgramError pe4 = new ProgramError(10, ErrorLevel.LOW, "bar",
129
-                ex, null, new Date());
133
+                ex, null, new Date(), clientInfo);
130 134
         final ProgramError pe5 = new ProgramError(10, ErrorLevel.LOW, "moo",
131
-                null, "Hello", new Date());
135
+                null, "Hello", new Date(), clientInfo);
132 136
 
133 137
         assertFalse(pe1.equals(null)); // NOPMD
134 138
         assertFalse(pe1.equals("moo"));

+ 12
- 20
test/com/dmdirc/ui/core/feedback/CoreFeedbackDialogModelTest.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.ui.core.feedback;
25 25
 import com.dmdirc.interfaces.ConnectionManager;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 import com.dmdirc.interfaces.ui.FeedbackDialogModelListener;
28
+import com.dmdirc.util.ClientInfo;
28 29
 
29 30
 import java.nio.file.Path;
30 31
 import java.util.Optional;
@@ -45,6 +46,7 @@ public class CoreFeedbackDialogModelTest {
45 46
     @Mock private FeedbackSenderFactory feedbackSenderFactory;
46 47
     @Mock private FeedbackDialogModelListener listener;
47 48
     @Mock private Path path;
49
+    @Mock private ClientInfo clientInfo;
48 50
     private static final String NAME = "Bob Dole";
49 51
     private static final String EMAIL = "bob@dole.com";
50 52
     private static final String FEEDBACK = "DMDirc Rocks.";
@@ -52,8 +54,7 @@ public class CoreFeedbackDialogModelTest {
52 54
     @Test
53 55
     public void testName() {
54 56
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
55
-                connectionManager,
56
-                feedbackSenderFactory, path);
57
+                connectionManager, feedbackSenderFactory, path, clientInfo);
57 58
         assertEquals("testName", Optional.empty(), instance.getName());
58 59
         instance.setName(Optional.ofNullable(NAME));
59 60
         assertEquals("testName", Optional.ofNullable(NAME), instance.getName());
@@ -62,8 +63,7 @@ public class CoreFeedbackDialogModelTest {
62 63
     @Test
63 64
     public void testEmail() {
64 65
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
65
-                connectionManager,
66
-                feedbackSenderFactory, path);
66
+                connectionManager, feedbackSenderFactory, path, clientInfo);
67 67
         assertEquals("testEmail", Optional.empty(), instance.getEmail());
68 68
         instance.setEmail(Optional.ofNullable(EMAIL));
69 69
         assertEquals("testEmail", Optional.ofNullable(EMAIL), instance.getEmail());
@@ -72,8 +72,7 @@ public class CoreFeedbackDialogModelTest {
72 72
     @Test
73 73
     public void testFeedback() {
74 74
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
75
-                connectionManager,
76
-                feedbackSenderFactory, path);
75
+                connectionManager, feedbackSenderFactory, path, clientInfo);
77 76
         assertEquals("testFeedback", Optional.empty(), instance.getFeedback());
78 77
         instance.setFeedback(Optional.ofNullable(FEEDBACK));
79 78
         assertEquals("testFeedback", Optional.ofNullable(FEEDBACK), instance.getFeedback());
@@ -82,8 +81,7 @@ public class CoreFeedbackDialogModelTest {
82 81
     @Test
83 82
     public void testServerInfo() {
84 83
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
85
-                connectionManager,
86
-                feedbackSenderFactory, path);
84
+                connectionManager, feedbackSenderFactory, path, clientInfo);
87 85
         assertEquals("testServerInfo", false, instance.getIncludeServerInfo());
88 86
         instance.setIncludeServerInfo(true);
89 87
         assertEquals("testServerInfo", true, instance.getIncludeServerInfo());
@@ -92,8 +90,7 @@ public class CoreFeedbackDialogModelTest {
92 90
     @Test
93 91
     public void testDMDircInfo() {
94 92
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
95
-                connectionManager,
96
-                feedbackSenderFactory, path);
93
+                connectionManager, feedbackSenderFactory, path, clientInfo);
97 94
         assertEquals("testDMDircInfo", false, instance.getIncludeDMDircInfo());
98 95
         instance.setIncludeDMDircInfo(true);
99 96
         assertEquals("testDMDircInfo", true, instance.getIncludeDMDircInfo());
@@ -107,8 +104,7 @@ public class CoreFeedbackDialogModelTest {
107 104
     @Test
108 105
     public void testNameListener() {
109 106
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
110
-                connectionManager,
111
-                feedbackSenderFactory, path);
107
+                connectionManager, feedbackSenderFactory, path, clientInfo);
112 108
         instance.addListener(listener);
113 109
         instance.setName(Optional.ofNullable("Bob Dole"));
114 110
         verify(listener).nameChanged(Optional.ofNullable("Bob Dole"));
@@ -117,8 +113,7 @@ public class CoreFeedbackDialogModelTest {
117 113
     @Test
118 114
     public void testEmailListener() {
119 115
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
120
-                connectionManager,
121
-                feedbackSenderFactory, path);
116
+                connectionManager, feedbackSenderFactory, path, clientInfo);
122 117
         instance.addListener(listener);
123 118
         instance.setEmail(Optional.ofNullable("bob@dole.com"));
124 119
         verify(listener).emailChanged(Optional.ofNullable("bob@dole.com"));
@@ -127,8 +122,7 @@ public class CoreFeedbackDialogModelTest {
127 122
     @Test
128 123
     public void testFeedbackListener() {
129 124
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
130
-                connectionManager,
131
-                feedbackSenderFactory, path);
125
+                connectionManager, feedbackSenderFactory, path, clientInfo);
132 126
         instance.addListener(listener);
133 127
         instance.setFeedback(Optional.ofNullable("DMDirc Rocks."));
134 128
         verify(listener).feedbackChanged(Optional.ofNullable("DMDirc Rocks."));
@@ -137,8 +131,7 @@ public class CoreFeedbackDialogModelTest {
137 131
     @Test
138 132
     public void testServerInfoListener() {
139 133
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
140
-                connectionManager,
141
-                feedbackSenderFactory, path);
134
+                connectionManager, feedbackSenderFactory, path, clientInfo);
142 135
         instance.addListener(listener);
143 136
         instance.setIncludeServerInfo(true);
144 137
         verify(listener).includeServerInfoChanged(true);
@@ -147,8 +140,7 @@ public class CoreFeedbackDialogModelTest {
147 140
     @Test
148 141
     public void testDMDircInfoListener() {
149 142
         final CoreFeedbackDialogModel instance = new CoreFeedbackDialogModel(config,
150
-                connectionManager,
151
-                feedbackSenderFactory, path);
143
+                connectionManager, feedbackSenderFactory, path, clientInfo);
152 144
         instance.addListener(listener);
153 145
         instance.setIncludeDMDircInfo(true);
154 146
         verify(listener).includeDMDircInfoChanged(true);

Loading…
Cancel
Save