|
@@ -22,7 +22,6 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.plugins;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.Main;
|
26
|
25
|
import com.dmdirc.actions.ActionManager;
|
27
|
26
|
import com.dmdirc.actions.CoreActionType;
|
28
|
27
|
import com.dmdirc.config.IdentityManager;
|
|
@@ -54,30 +53,28 @@ import java.util.Map;
|
54
|
53
|
public class PluginManager implements ActionListener, ServiceManager {
|
55
|
54
|
|
56
|
55
|
/** List of known plugins' file names to their corresponding {@link PluginInfo} objects. */
|
57
|
|
- private final Map<String, PluginInfo> knownPlugins = new HashMap<String, PluginInfo>();
|
|
56
|
+ private final Map<String, PluginInfo> knownPlugins = new HashMap<>();
|
58
|
57
|
|
59
|
58
|
/** Set of known plugins' metadata. */
|
60
|
|
- private final Collection<PluginMetaData> plugins = new HashSet<PluginMetaData>();
|
|
59
|
+ private final Collection<PluginMetaData> plugins = new HashSet<>();
|
61
|
60
|
|
62
|
61
|
/** Directory where plugins are stored. */
|
63
|
62
|
private final String myDir;
|
64
|
63
|
|
65
|
64
|
/** Map of services. */
|
66
|
|
- private final Map<String, Map<String, Service>> services = new HashMap<String, Map<String, Service>>();
|
67
|
|
-
|
68
|
|
- /** Parent. */
|
69
|
|
- private final Main main;
|
|
65
|
+ private final Map<String, Map<String, Service>> services = new HashMap<>();
|
70
|
66
|
|
71
|
67
|
/** Global ClassLoader used by plugins from this manager. */
|
72
|
68
|
private final GlobalClassLoader globalClassLoader;
|
73
|
69
|
|
74
|
70
|
/**
|
75
|
71
|
* Creates a new instance of PluginManager.
|
|
72
|
+ *
|
|
73
|
+ * @param identityManager The identity manager to use for configuration options.
|
76
|
74
|
*/
|
77
|
|
- public PluginManager(final IdentityManager identityManager, final Main main) {
|
|
75
|
+ public PluginManager(final IdentityManager identityManager) {
|
78
|
76
|
final String fs = System.getProperty("file.separator");
|
79
|
77
|
myDir = identityManager.getConfigDir() + "plugins" + fs;
|
80
|
|
- this.main = main;
|
81
|
78
|
this.globalClassLoader = new GlobalClassLoader(this);
|
82
|
79
|
ActionManager.getActionManager().registerListener(this,
|
83
|
80
|
CoreActionType.CLIENT_PREFS_OPENED,
|
|
@@ -94,17 +91,6 @@ public class PluginManager implements ActionListener, ServiceManager {
|
94
|
91
|
return globalClassLoader;
|
95
|
92
|
}
|
96
|
93
|
|
97
|
|
- /**
|
98
|
|
- * Get the instance of Main that owns this.
|
99
|
|
- *
|
100
|
|
- * @return main that owns this.
|
101
|
|
- * @Deprecated Global state is bad.
|
102
|
|
- */
|
103
|
|
- @Deprecated
|
104
|
|
- public Main getMain() {
|
105
|
|
- return main;
|
106
|
|
- }
|
107
|
|
-
|
108
|
94
|
/** {@inheritDoc} */
|
109
|
95
|
@Override
|
110
|
96
|
public Service getService(final String type, final String name) {
|
|
@@ -126,7 +112,7 @@ public class PluginManager implements ActionListener, ServiceManager {
|
126
|
112
|
return service;
|
127
|
113
|
}
|
128
|
114
|
} else if (create) {
|
129
|
|
- final Map<String, Service> map = new HashMap<String, Service>();
|
|
115
|
+ final Map<String, Service> map = new HashMap<>();
|
130
|
116
|
final Service service = new Service(type, name);
|
131
|
117
|
map.put(name, service);
|
132
|
118
|
services.put(type, map);
|
|
@@ -190,17 +176,17 @@ public class PluginManager implements ActionListener, ServiceManager {
|
190
|
176
|
// Find the type first
|
191
|
177
|
if (services.containsKey(type)) {
|
192
|
178
|
final Map<String, Service> map = services.get(type);
|
193
|
|
- return new ArrayList<Service>(map.values());
|
|
179
|
+ return new ArrayList<>(map.values());
|
194
|
180
|
}
|
195
|
181
|
|
196
|
|
- return new ArrayList<Service>();
|
|
182
|
+ return new ArrayList<>();
|
197
|
183
|
}
|
198
|
184
|
|
199
|
185
|
/** {@inheritDoc} */
|
200
|
186
|
@Override
|
201
|
187
|
public List<Service> getAllServices() {
|
202
|
188
|
// Find the type first
|
203
|
|
- final List<Service> allServices = new ArrayList<Service>();
|
|
189
|
+ final List<Service> allServices = new ArrayList<>();
|
204
|
190
|
for (Map<String, Service> map : services.values()) {
|
205
|
191
|
allServices.addAll(map.values());
|
206
|
192
|
}
|
|
@@ -411,7 +397,7 @@ public class PluginManager implements ActionListener, ServiceManager {
|
411
|
397
|
synchronized (plugins) {
|
412
|
398
|
plugins.removeAll(newPlugins);
|
413
|
399
|
|
414
|
|
- for (PluginMetaData oldPlugin : new HashSet<PluginMetaData>(plugins)) {
|
|
400
|
+ for (PluginMetaData oldPlugin : new HashSet<>(plugins)) {
|
415
|
401
|
delPlugin(oldPlugin.getRelativeFilename());
|
416
|
402
|
}
|
417
|
403
|
|
|
@@ -428,7 +414,7 @@ public class PluginManager implements ActionListener, ServiceManager {
|
428
|
414
|
* available updates.
|
429
|
415
|
*/
|
430
|
416
|
public void applyUpdates() {
|
431
|
|
- final Deque<File> dirs = new LinkedList<File>();
|
|
417
|
+ final Deque<File> dirs = new LinkedList<>();
|
432
|
418
|
|
433
|
419
|
dirs.add(new File(myDir));
|
434
|
420
|
|
|
@@ -454,11 +440,10 @@ public class PluginManager implements ActionListener, ServiceManager {
|
454
|
440
|
* @return A list of all installed or known plugins
|
455
|
441
|
*/
|
456
|
442
|
public Collection<PluginMetaData> getAllPlugins() {
|
457
|
|
- final Collection<PluginMetaData> res
|
458
|
|
- = new HashSet<PluginMetaData>(plugins.size());
|
|
443
|
+ final Collection<PluginMetaData> res = new HashSet<>(plugins.size());
|
459
|
444
|
|
460
|
|
- final Deque<File> dirs = new LinkedList<File>();
|
461
|
|
- final Collection<String> pluginPaths = new LinkedList<String>();
|
|
445
|
+ final Deque<File> dirs = new LinkedList<>();
|
|
446
|
+ final Collection<String> pluginPaths = new LinkedList<>();
|
462
|
447
|
|
463
|
448
|
dirs.add(new File(myDir));
|
464
|
449
|
|
|
@@ -471,9 +456,9 @@ public class PluginManager implements ActionListener, ServiceManager {
|
471
|
456
|
}
|
472
|
457
|
}
|
473
|
458
|
|
474
|
|
- final MapList<String, String> newServices = new MapList<String, String>();
|
475
|
|
- final Map<String, PluginMetaData> newPluginsByName = new HashMap<String, PluginMetaData>();
|
476
|
|
- final Map<String, PluginMetaData> newPluginsByPath = new HashMap<String, PluginMetaData>();
|
|
459
|
+ final MapList<String, String> newServices = new MapList<>();
|
|
460
|
+ final Map<String, PluginMetaData> newPluginsByName = new HashMap<>();
|
|
461
|
+ final Map<String, PluginMetaData> newPluginsByPath = new HashMap<>();
|
477
|
462
|
|
478
|
463
|
// Initialise all of our metadata objects
|
479
|
464
|
for (String target : pluginPaths) {
|
|
@@ -554,7 +539,7 @@ public class PluginManager implements ActionListener, ServiceManager {
|
554
|
539
|
* @return Collection<PluginInfo> of known plugins.
|
555
|
540
|
*/
|
556
|
541
|
public Collection<PluginInfo> getPluginInfos() {
|
557
|
|
- return new ArrayList<PluginInfo>(knownPlugins.values());
|
|
542
|
+ return new ArrayList<>(knownPlugins.values());
|
558
|
543
|
}
|
559
|
544
|
|
560
|
545
|
/** {@inheritDoc} */
|
|
@@ -568,10 +553,10 @@ public class PluginManager implements ActionListener, ServiceManager {
|
568
|
553
|
if (pi.isLoaded() || pi.isTempLoaded()) {
|
569
|
554
|
try {
|
570
|
555
|
pi.getPlugin().showConfig((PreferencesDialogModel) arguments[0]);
|
571
|
|
- } catch (LinkageError le) {
|
572
|
|
- Logger.userError(ErrorLevel.MEDIUM, "Error with plugin (" + pi.getMetaData().getFriendlyName() + "), unable to show config (" + le + ")", le);
|
573
|
|
- } catch (Exception ex) {
|
574
|
|
- Logger.userError(ErrorLevel.MEDIUM, "Error with plugin (" + pi.getMetaData().getFriendlyName() + "), unable to show config (" + ex + ")", ex);
|
|
556
|
+ } catch (LinkageError | Exception le) {
|
|
557
|
+ Logger.userError(ErrorLevel.MEDIUM,
|
|
558
|
+ "Error with plugin (" + pi.getMetaData().getFriendlyName()
|
|
559
|
+ + "), unable to show config (" + le + ")", le);
|
575
|
560
|
}
|
576
|
561
|
}
|
577
|
562
|
}
|