|
@@ -26,6 +26,7 @@ import com.dmdirc.actions.ActionManager;
|
26
|
26
|
import com.dmdirc.actions.CoreActionType;
|
27
|
27
|
import com.dmdirc.config.Identity;
|
28
|
28
|
import com.dmdirc.config.IdentityManager;
|
|
29
|
+import com.dmdirc.config.InvalidIdentityFileException;
|
29
|
30
|
import com.dmdirc.config.prefs.validator.ValidationResponse;
|
30
|
31
|
import com.dmdirc.util.resourcemanager.ResourceManager;
|
31
|
32
|
import com.dmdirc.util.ConfigFile;
|
|
@@ -49,6 +50,11 @@ import java.util.TimerTask;
|
49
|
50
|
import java.net.URL;
|
50
|
51
|
import java.util.TreeMap;
|
51
|
52
|
|
|
53
|
+/**
|
|
54
|
+ * This class is used to store meta information
|
|
55
|
+ *
|
|
56
|
+ * @author shane
|
|
57
|
+ */
|
52
|
58
|
public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
53
|
59
|
|
54
|
60
|
/** A logger for this class. */
|
|
@@ -96,6 +102,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
96
|
102
|
/** Map of exports */
|
97
|
103
|
private final Map<String, ExportInfo> exports = new HashMap<String, ExportInfo>();
|
98
|
104
|
|
|
105
|
+ /** List of identities */
|
|
106
|
+ private final List<Identity> identities = new ArrayList<Identity>();
|
|
107
|
+
|
99
|
108
|
/**
|
100
|
109
|
* Create a new PluginInfo.
|
101
|
110
|
*
|
|
@@ -195,7 +204,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
195
|
204
|
}
|
196
|
205
|
|
197
|
206
|
updateProvides();
|
198
|
|
- getDefaults();
|
|
207
|
+ loadDefaults();
|
|
208
|
+ loadIdentities();
|
199
|
209
|
}
|
200
|
210
|
|
201
|
211
|
/**
|
|
@@ -248,15 +258,13 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
248
|
258
|
* @throws IOException if there is an error with the ResourceManager.
|
249
|
259
|
*/
|
250
|
260
|
public Map<String, InputStream> getLicenceStreams() throws IOException {
|
251
|
|
- return new TreeMap<String, InputStream>(getResourceManager().
|
252
|
|
- getResourcesStartingWithAsInputStreams(
|
253
|
|
- "META-INF/licences/"));
|
|
261
|
+ return new TreeMap<String, InputStream>(getResourceManager().getResourcesStartingWithAsInputStreams("META-INF/licences/"));
|
254
|
262
|
}
|
255
|
263
|
|
256
|
264
|
/**
|
257
|
265
|
* Get the defaults, formatters and icons for this plugin.
|
258
|
266
|
*/
|
259
|
|
- private void getDefaults() {
|
|
267
|
+ private void loadDefaults() {
|
260
|
268
|
if (metaData == null) {
|
261
|
269
|
return;
|
262
|
270
|
}
|
|
@@ -269,9 +277,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
269
|
277
|
if (metaData.isKeyDomain("defaults")) {
|
270
|
278
|
final Map<String, String> keysection = metaData.getKeyDomain("defaults");
|
271
|
279
|
|
272
|
|
- for (Map.Entry entry : keysection.entrySet()) {
|
273
|
|
- final String key = entry.getKey().toString();
|
274
|
|
- final String value = entry.getValue().toString();
|
|
280
|
+ for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
|
281
|
+ final String key = entry.getKey();
|
|
282
|
+ final String value = entry.getValue();
|
275
|
283
|
|
276
|
284
|
defaults.setOption(domain, key, value);
|
277
|
285
|
}
|
|
@@ -280,9 +288,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
280
|
288
|
if (metaData.isKeyDomain("formatters")) {
|
281
|
289
|
final Map<String, String> keysection = metaData.getKeyDomain("formatters");
|
282
|
290
|
|
283
|
|
- for (Map.Entry entry : keysection.entrySet()) {
|
284
|
|
- final String key = entry.getKey().toString();
|
285
|
|
- final String value = entry.getValue().toString();
|
|
291
|
+ for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
|
292
|
+ final String key = entry.getKey();
|
|
293
|
+ final String value = entry.getValue();
|
286
|
294
|
|
287
|
295
|
defaults.setOption("formatter", key, value);
|
288
|
296
|
}
|
|
@@ -291,15 +299,53 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
291
|
299
|
if (metaData.isKeyDomain("icons")) {
|
292
|
300
|
final Map<String, String> keysection = metaData.getKeyDomain("icons");
|
293
|
301
|
|
294
|
|
- for (Map.Entry entry : keysection.entrySet()) {
|
295
|
|
- final String key = entry.getKey().toString();
|
296
|
|
- final String value = entry.getValue().toString();
|
|
302
|
+ for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
|
303
|
+ final String key = entry.getKey();
|
|
304
|
+ final String value = entry.getValue();
|
297
|
305
|
|
298
|
306
|
defaults.setOption("icon", key, value);
|
299
|
307
|
}
|
300
|
308
|
}
|
301
|
309
|
}
|
302
|
310
|
|
|
311
|
+ /**
|
|
312
|
+ * Try get the identities for this plugin.
|
|
313
|
+ * This will unload any identities previously loaded by this plugin.
|
|
314
|
+ */
|
|
315
|
+ private void loadIdentities() {
|
|
316
|
+ try {
|
|
317
|
+ final Map<String, InputStream> identityStreams = getResourceManager().getResourcesStartingWithAsInputStreams("META-INF/identities/");
|
|
318
|
+
|
|
319
|
+ unloadIdentities();
|
|
320
|
+
|
|
321
|
+ for (Map.Entry<String, InputStream> entry : identityStreams.entrySet()) {
|
|
322
|
+ final String name = entry.getKey();
|
|
323
|
+ final InputStream stream = entry.getValue();
|
|
324
|
+
|
|
325
|
+ try {
|
|
326
|
+ final Identity thisIdentity = new Identity(stream, false);
|
|
327
|
+ identities.add(thisIdentity);
|
|
328
|
+ IdentityManager.addIdentity(thisIdentity);
|
|
329
|
+ } catch (final InvalidIdentityFileException ex) {
|
|
330
|
+ Logger.userError(ErrorLevel.MEDIUM, "Error with identity file '" + name + "' in plugin '" + getName() + "'", ex);
|
|
331
|
+ }
|
|
332
|
+ }
|
|
333
|
+ } catch (final IOException ioe) {
|
|
334
|
+ Logger.userError(ErrorLevel.MEDIUM, "Error finding identities in plugin '" + getName() + "'", ioe);
|
|
335
|
+ }
|
|
336
|
+ }
|
|
337
|
+
|
|
338
|
+ /**
|
|
339
|
+ * Unload any identities loaded by this plugin.
|
|
340
|
+ */
|
|
341
|
+ private void unloadIdentities() {
|
|
342
|
+ for (Identity identity : identities) {
|
|
343
|
+ IdentityManager.removeIdentity(identity);
|
|
344
|
+ }
|
|
345
|
+
|
|
346
|
+ identities.clear();
|
|
347
|
+ }
|
|
348
|
+
|
303
|
349
|
/**
|
304
|
350
|
* Update provides list.
|
305
|
351
|
*/
|
|
@@ -348,7 +394,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
348
|
394
|
}
|
349
|
395
|
updateMetaData();
|
350
|
396
|
updateProvides();
|
351
|
|
- getDefaults();
|
|
397
|
+ loadDefaults();
|
|
398
|
+ loadIdentities();
|
352
|
399
|
} catch (IOException ioe) {
|
353
|
400
|
}
|
354
|
401
|
}
|
|
@@ -597,8 +644,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
597
|
644
|
return true;
|
598
|
645
|
}
|
599
|
646
|
|
600
|
|
- for (String plugin : desired.split(",")) {
|
601
|
|
- final String[] data = plugin.split(":");
|
|
647
|
+ for (String pluginName : desired.split(",")) {
|
|
648
|
+ final String[] data = pluginName.split(":");
|
602
|
649
|
final PluginInfo pi = PluginManager.getPluginManager().getPluginInfoByName(data[0]);
|
603
|
650
|
if (pi == null) {
|
604
|
651
|
requirementsError = "Required plugin '" + data[0] + "' was not found";
|
|
@@ -778,8 +825,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
778
|
825
|
*/
|
779
|
826
|
public void loadRequired() {
|
780
|
827
|
final String required = getKeyValue("requires", "plugins", "");
|
781
|
|
- for (String plugin : required.split(",")) {
|
782
|
|
- final String[] data = plugin.split(":");
|
|
828
|
+ for (String pluginName : required.split(",")) {
|
|
829
|
+ final String[] data = pluginName.split(":");
|
783
|
830
|
if (!data[0].trim().isEmpty()) {
|
784
|
831
|
final PluginInfo pi = PluginManager.getPluginManager().getPluginInfoByName(data[0]);
|
785
|
832
|
|
|
@@ -1003,6 +1050,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1003
|
1050
|
service.delProvider(this);
|
1004
|
1051
|
}
|
1005
|
1052
|
provides.clear();
|
|
1053
|
+ unloadIdentities();
|
1006
|
1054
|
}
|
1007
|
1055
|
tempLoaded = false;
|
1008
|
1056
|
plugin = null;
|
|
@@ -1150,9 +1198,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1150
|
1198
|
try {
|
1151
|
1199
|
ResourceManager res = getResourceManager();
|
1152
|
1200
|
|
1153
|
|
- for (final String filename : res.getResourcesStartingWith("")) {
|
1154
|
|
- if (filename.matches("^.*\\.class$")) {
|
1155
|
|
- result.add(filename.replaceAll("\\.class$", "").replace('/', '.'));
|
|
1201
|
+ for (final String resourceFilename : res.getResourcesStartingWith("")) {
|
|
1202
|
+ if (resourceFilename.matches("^.*\\.class$")) {
|
|
1203
|
+ result.add(resourceFilename.replaceAll("\\.class$", "").replace('/', '.'));
|
1156
|
1204
|
}
|
1157
|
1205
|
}
|
1158
|
1206
|
} catch (IOException e) {
|