|
@@ -30,8 +30,6 @@ import com.dmdirc.config.InvalidIdentityFileException;
|
30
|
30
|
import com.dmdirc.logger.ErrorLevel;
|
31
|
31
|
import com.dmdirc.logger.Logger;
|
32
|
32
|
import com.dmdirc.updater.Version;
|
33
|
|
-import com.dmdirc.util.ConfigFile;
|
34
|
|
-import com.dmdirc.util.InvalidConfigFileException;
|
35
|
33
|
import com.dmdirc.util.resourcemanager.ResourceManager;
|
36
|
34
|
import com.dmdirc.util.validators.ValidationResponse;
|
37
|
35
|
|
|
@@ -42,6 +40,7 @@ import java.lang.reflect.Constructor;
|
42
|
40
|
import java.lang.reflect.InvocationTargetException;
|
43
|
41
|
import java.net.URL;
|
44
|
42
|
import java.util.ArrayList;
|
|
43
|
+import java.util.Collection;
|
45
|
44
|
import java.util.HashMap;
|
46
|
45
|
import java.util.List;
|
47
|
46
|
import java.util.Map;
|
|
@@ -57,8 +56,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
57
|
56
|
/** A logger for this class. */
|
58
|
57
|
private static final java.util.logging.Logger LOGGER
|
59
|
58
|
= java.util.logging.Logger.getLogger(PluginInfo.class.getName());
|
60
|
|
- /** Plugin Meta Data. */
|
61
|
|
- private volatile ConfigFile metaData;
|
|
59
|
+
|
|
60
|
+ /** The metadata for this plugin. */
|
|
61
|
+ private final PluginMetaData metadata;
|
62
|
62
|
/** URL that this plugin was loaded from. */
|
63
|
63
|
private final URL url;
|
64
|
64
|
/** Filename for this plugin (taken from URL). */
|
|
@@ -91,43 +91,48 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
91
|
91
|
/**
|
92
|
92
|
* Create a new PluginInfo.
|
93
|
93
|
*
|
|
94
|
+ * @param metadata The plugin's metadata information
|
94
|
95
|
* @param url URL to file that this plugin is stored in.
|
95
|
96
|
* @throws PluginException if there is an error loading the Plugin
|
96
|
|
- * @since 0.6
|
|
97
|
+ * @since 0.6.6
|
97
|
98
|
*/
|
98
|
|
- public PluginInfo(final URL url) throws PluginException {
|
99
|
|
- this(url, true);
|
|
99
|
+ public PluginInfo(final PluginMetaData metadata, final URL url) throws PluginException {
|
|
100
|
+ this(metadata, url, true);
|
100
|
101
|
}
|
101
|
102
|
|
102
|
103
|
/**
|
103
|
104
|
* Create a new PluginInfo.
|
104
|
105
|
*
|
|
106
|
+ * @param metadata The plugin's metadata information
|
105
|
107
|
* @param url URL to file that this plugin is stored in.
|
106
|
108
|
* @param load Should this plugin be loaded, or is this just a placeholder? (true for load, false for placeholder)
|
107
|
109
|
* @throws PluginException if there is an error loading the Plugin
|
108
|
|
- * @since 0.6
|
|
110
|
+ * @since 0.6.6
|
109
|
111
|
*/
|
110
|
|
- public PluginInfo(final URL url, final boolean load) throws PluginException {
|
|
112
|
+ public PluginInfo(final PluginMetaData metadata, final URL url, final boolean load) throws PluginException {
|
111
|
113
|
this.url = url;
|
112
|
114
|
this.filename = new File(url.getPath()).getName();
|
|
115
|
+ this.metadata = metadata;
|
113
|
116
|
|
114
|
117
|
ResourceManager res;
|
115
|
118
|
|
116
|
119
|
// Check for updates.
|
117
|
120
|
if (new File(getFullFilename() + ".update").exists() && new File(getFullFilename()).delete()) {
|
118
|
121
|
new File(getFullFilename() + ".update").renameTo(new File(getFullFilename()));
|
|
122
|
+
|
|
123
|
+ updateMetaData();
|
119
|
124
|
}
|
120
|
125
|
|
121
|
126
|
if (!load) {
|
122
|
|
- // Load the metaData if available.
|
123
|
|
- try {
|
124
|
|
- metaData = getConfigFile();
|
125
|
|
- } catch (IOException ioe) {
|
126
|
|
- metaData = null;
|
127
|
|
- }
|
|
127
|
+ // TODO: This is pointless now
|
128
|
128
|
return;
|
129
|
129
|
}
|
130
|
130
|
|
|
131
|
+ if (metadata.hasErrors()) {
|
|
132
|
+ throw new PluginException("Plugin " + filename + " has metadata "
|
|
133
|
+ + "errors: " + metadata.getErrors());
|
|
134
|
+ }
|
|
135
|
+
|
131
|
136
|
try {
|
132
|
137
|
res = getResourceManager();
|
133
|
138
|
} catch (IOException ioe) {
|
|
@@ -135,20 +140,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
135
|
140
|
throw new PluginException("Plugin " + filename + " failed to load. " + lastError, ioe);
|
136
|
141
|
}
|
137
|
142
|
|
138
|
|
- try {
|
139
|
|
- metaData = getConfigFile();
|
140
|
|
- if (metaData == null) {
|
141
|
|
- lastError = "plugin.config doesn't exist in jar";
|
142
|
|
- throw new PluginException("Plugin " + filename + " failed to load. " + lastError);
|
143
|
|
- }
|
144
|
|
- } catch (IOException e) {
|
145
|
|
- lastError = "plugin.config IOException: " + e.getMessage();
|
146
|
|
- throw new PluginException("Plugin " + filename + " failed to load, plugin.config failed to open - " + e.getMessage(), e);
|
147
|
|
- } catch (IllegalArgumentException e) {
|
148
|
|
- lastError = "plugin.config IllegalArgumentException: " + e.getMessage();
|
149
|
|
- throw new PluginException("Plugin " + filename + " failed to load, plugin.config failed to open - " + e.getMessage(), e);
|
150
|
|
- }
|
151
|
|
-
|
152
|
143
|
if (!getVersion().isValid()) {
|
153
|
144
|
lastError = "Incomplete plugin.config (Missing or invalid 'version')";
|
154
|
145
|
throw new PluginException("Plugin " + filename + " failed to load. " + lastError);
|
|
@@ -177,10 +168,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
177
|
168
|
myClasses.add(classname);
|
178
|
169
|
}
|
179
|
170
|
}
|
180
|
|
-
|
181
|
|
- if (isPersistent() && loadAll()) {
|
182
|
|
- loadEntirePlugin();
|
183
|
|
- }
|
184
|
171
|
} else {
|
185
|
172
|
lastError = "One or more requirements not met (" + requirementsError + ")";
|
186
|
173
|
throw new PluginException("Plugin " + filename + " was not loaded. " + lastError);
|
|
@@ -190,28 +177,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
190
|
177
|
getDefaults();
|
191
|
178
|
}
|
192
|
179
|
|
193
|
|
- /**
|
194
|
|
- * Get a ConfigFile object for this plugin.
|
195
|
|
- * This will load a ConfigFile
|
196
|
|
- *
|
197
|
|
- * @return the ConfigFile object for this plugin, or null if the plugin has no config
|
198
|
|
- * @throws IOException if there is an error with the ResourceManager.
|
199
|
|
- */
|
200
|
|
- private ConfigFile getConfigFile() throws IOException {
|
201
|
|
- ConfigFile file = null;
|
202
|
|
- final ResourceManager res = getResourceManager();
|
203
|
|
- if (res.resourceExists("META-INF/plugin.config")) {
|
204
|
|
- try {
|
205
|
|
- file = new ConfigFile(res.getResourceInputStream("META-INF/plugin.config"));
|
206
|
|
- file.read();
|
207
|
|
- } catch (InvalidConfigFileException icfe) {
|
208
|
|
- throw new IOException("Unable to read plugin.config", icfe);
|
209
|
|
- }
|
210
|
|
- }
|
211
|
|
-
|
212
|
|
- return file;
|
213
|
|
- }
|
214
|
|
-
|
215
|
180
|
/**
|
216
|
181
|
* Get the licence for this plugin if it exists.
|
217
|
182
|
*
|
|
@@ -231,46 +196,30 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
231
|
196
|
* Get the defaults, formatters and icons for this plugin.
|
232
|
197
|
*/
|
233
|
198
|
private void getDefaults() {
|
234
|
|
- if (metaData == null) {
|
235
|
|
- return;
|
236
|
|
- }
|
237
|
|
-
|
238
|
199
|
final Identity defaults = IdentityManager.getAddonIdentity();
|
239
|
200
|
final String domain = "plugin-" + getName();
|
240
|
201
|
|
241
|
202
|
LOGGER.finer(getName() + ": Using domain '" + domain + "'");
|
242
|
203
|
|
243
|
|
- if (metaData.isKeyDomain("defaults")) {
|
244
|
|
- final Map<String, String> keysection = metaData.getKeyDomain("defaults");
|
245
|
|
-
|
246
|
|
- for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
247
|
|
- final String key = entry.getKey();
|
248
|
|
- final String value = entry.getValue();
|
|
204
|
+ for (Map.Entry<String, String> entry : metadata.getDefaultSettings().entrySet()) {
|
|
205
|
+ final String key = entry.getKey();
|
|
206
|
+ final String value = entry.getValue();
|
249
|
207
|
|
250
|
|
- defaults.setOption(domain, key, value);
|
251
|
|
- }
|
|
208
|
+ defaults.setOption(domain, key, value);
|
252
|
209
|
}
|
253
|
210
|
|
254
|
|
- if (metaData.isKeyDomain("formatters")) {
|
255
|
|
- final Map<String, String> keysection = metaData.getKeyDomain("formatters");
|
256
|
|
-
|
257
|
|
- for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
258
|
|
- final String key = entry.getKey();
|
259
|
|
- final String value = entry.getValue();
|
|
211
|
+ for (Map.Entry<String, String> entry : metadata.getFormatters().entrySet()) {
|
|
212
|
+ final String key = entry.getKey();
|
|
213
|
+ final String value = entry.getValue();
|
260
|
214
|
|
261
|
|
- defaults.setOption("formatter", key, value);
|
262
|
|
- }
|
|
215
|
+ defaults.setOption("formatter", key, value);
|
263
|
216
|
}
|
264
|
217
|
|
265
|
|
- if (metaData.isKeyDomain("icons")) {
|
266
|
|
- final Map<String, String> keysection = metaData.getKeyDomain("icons");
|
|
218
|
+ for (Map.Entry<String, String> entry : metadata.getIcons().entrySet()) {
|
|
219
|
+ final String key = entry.getKey();
|
|
220
|
+ final String value = entry.getValue();
|
267
|
221
|
|
268
|
|
- for (Map.Entry<String, String> entry : keysection.entrySet()) {
|
269
|
|
- final String key = entry.getKey();
|
270
|
|
- final String value = entry.getValue();
|
271
|
|
-
|
272
|
|
- defaults.setOption("icon", key, value);
|
273
|
|
- }
|
|
222
|
+ defaults.setOption("icon", key, value);
|
274
|
223
|
}
|
275
|
224
|
}
|
276
|
225
|
|
|
@@ -339,7 +288,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
339
|
288
|
}
|
340
|
289
|
|
341
|
290
|
// Get services provided by this plugin
|
342
|
|
- final List<String> providesList = metaData.getFlatDomain("provides");
|
|
291
|
+ final Collection<String> providesList = metadata.getServices();
|
343
|
292
|
if (providesList != null) {
|
344
|
293
|
for (String item : providesList) {
|
345
|
294
|
final String[] bits = item.split(" ");
|
|
@@ -391,19 +340,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
391
|
340
|
* @return true if metaData was reloaded ok, else false.
|
392
|
341
|
*/
|
393
|
342
|
private boolean updateMetaData() {
|
394
|
|
- // Force a new resourcemanager just incase.
|
395
|
|
- try {
|
396
|
|
- getResourceManager(true);
|
397
|
|
- final ConfigFile newMetaData = getConfigFile();
|
398
|
|
- if (newMetaData != null) {
|
399
|
|
- metaData = newMetaData;
|
400
|
|
- return true;
|
401
|
|
- }
|
402
|
|
- } catch (IOException ioe) {
|
403
|
|
- Logger.userError(ErrorLevel.MEDIUM, "There was an error updating the metadata for "+getName(), ioe);
|
404
|
|
- }
|
|
343
|
+ metadata.load();
|
405
|
344
|
|
406
|
|
- return false;
|
|
345
|
+ return !metadata.hasErrors();
|
407
|
346
|
}
|
408
|
347
|
|
409
|
348
|
/**
|
|
@@ -532,7 +471,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
532
|
471
|
* @return True if the test passes, false otherwise
|
533
|
472
|
*/
|
534
|
473
|
protected boolean checkOS(final String desired, final String actualName, final String actualVersion, final String actualArch) {
|
535
|
|
- if (desired.isEmpty()) {
|
|
474
|
+ if (desired == null || desired.isEmpty()) {
|
536
|
475
|
return true;
|
537
|
476
|
}
|
538
|
477
|
|
|
@@ -552,30 +491,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
552
|
491
|
return true;
|
553
|
492
|
}
|
554
|
493
|
|
555
|
|
- /**
|
556
|
|
- * Checks to see if the UI requirements of the plugin are satisfied.
|
557
|
|
- * If the desired string is empty, the test passes.
|
558
|
|
- * Otherwise it is used as a regular expressions against the package of the
|
559
|
|
- * UIController to test what UI is currently in use.
|
560
|
|
- * On failure, the requirementsError field will contain a user-friendly
|
561
|
|
- * error message.
|
562
|
|
- *
|
563
|
|
- * @param desired The desired UI requirements
|
564
|
|
- * @param actual The package of the current UI in use.
|
565
|
|
- * @return True if the test passes, false otherwise
|
566
|
|
- */
|
567
|
|
- protected boolean checkUI(final String desired, final String actual) {
|
568
|
|
- if (desired.isEmpty()) {
|
569
|
|
- return true;
|
570
|
|
- }
|
571
|
|
-
|
572
|
|
- if (!actual.toLowerCase().matches(desired)) {
|
573
|
|
- requirementsError = "Invalid UI. (Wanted: '" + desired + "', actual: '" + actual + "')";
|
574
|
|
- return false;
|
575
|
|
- }
|
576
|
|
- return true;
|
577
|
|
- }
|
578
|
|
-
|
579
|
494
|
/**
|
580
|
495
|
* Checks to see if the file requirements of the plugin are satisfied.
|
581
|
496
|
* If the desired string is empty, the test passes.
|
|
@@ -589,7 +504,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
589
|
504
|
* @return True if the test passes, false otherwise
|
590
|
505
|
*/
|
591
|
506
|
protected boolean checkFiles(final String desired) {
|
592
|
|
- if (desired.isEmpty()) {
|
|
507
|
+ if (desired == null || desired.isEmpty()) {
|
593
|
508
|
return true;
|
594
|
509
|
}
|
595
|
510
|
|
|
@@ -624,7 +539,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
624
|
539
|
* @return True if the test passes, false otherwise
|
625
|
540
|
*/
|
626
|
541
|
protected boolean checkPlugins(final String desired) {
|
627
|
|
- if (desired.isEmpty()) {
|
|
542
|
+ if (desired == null || desired.isEmpty()) {
|
628
|
543
|
return true;
|
629
|
544
|
}
|
630
|
545
|
|
|
@@ -665,15 +580,10 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
665
|
580
|
* @return true/false (Actual error if false is in the requirementsError field)
|
666
|
581
|
*/
|
667
|
582
|
public boolean checkRequirements(final boolean preliminary) {
|
668
|
|
- if (metaData == null) {
|
669
|
|
- // No meta-data, so no requirements.
|
670
|
|
- return true;
|
671
|
|
- }
|
672
|
|
-
|
673
|
|
- if (!checkOS(getKeyValue("requires", "os", ""), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"))
|
674
|
|
- || !checkFiles(getKeyValue("requires", "files", ""))
|
675
|
|
- || (!preliminary && !checkPlugins(getKeyValue("requires", "plugins", "")))
|
676
|
|
- || (!preliminary && !checkServices(metaData.getFlatDomain("required-services")))) {
|
|
583
|
+ if (!checkOS(metadata.getRequirements().get("os"), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"))
|
|
584
|
+ || !checkFiles(metadata.getRequirements().get("files"))
|
|
585
|
+ || (!preliminary && !checkPlugins(metadata.getRequirements().get("plugins")))
|
|
586
|
+ || (!preliminary && !checkServices(metadata.getRequiredServices()))) {
|
677
|
587
|
return false;
|
678
|
588
|
}
|
679
|
589
|
|
|
@@ -687,8 +597,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
687
|
597
|
* @param services Required services
|
688
|
598
|
* @return true if all services are available
|
689
|
599
|
*/
|
690
|
|
- private boolean checkServices(final List<String> services) {
|
691
|
|
- if (services == null || services.size() < 1) {
|
|
600
|
+ private boolean checkServices(final Collection<String> services) {
|
|
601
|
+ if (services == null || services.isEmpty()) {
|
692
|
602
|
return true;
|
693
|
603
|
}
|
694
|
604
|
|
|
@@ -763,7 +673,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
763
|
673
|
* otherwise
|
764
|
674
|
*/
|
765
|
675
|
public boolean isLoaded() {
|
766
|
|
- return (plugin != null) && !tempLoaded;
|
|
676
|
+ return plugin != null && !tempLoaded;
|
767
|
677
|
}
|
768
|
678
|
|
769
|
679
|
/**
|
|
@@ -773,23 +683,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
773
|
683
|
* otherwise
|
774
|
684
|
*/
|
775
|
685
|
public boolean isTempLoaded() {
|
776
|
|
- return (plugin != null) && tempLoaded;
|
777
|
|
- }
|
778
|
|
-
|
779
|
|
- /**
|
780
|
|
- * Load entire plugin.
|
781
|
|
- * This loads all files in the jar immediately.
|
782
|
|
- *
|
783
|
|
- * @throws PluginException if there is an error with the resourcemanager
|
784
|
|
- */
|
785
|
|
- private void loadEntirePlugin() throws PluginException {
|
786
|
|
- // Load the main "Plugin" from the jar
|
787
|
|
- loadPlugin();
|
788
|
|
-
|
789
|
|
- // Now load all the rest.
|
790
|
|
- for (String classname : myClasses) {
|
791
|
|
- loadClass(classname);
|
792
|
|
- }
|
|
686
|
+ return plugin != null && tempLoaded;
|
793
|
687
|
}
|
794
|
688
|
|
795
|
689
|
/**
|
|
@@ -804,7 +698,12 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
804
|
698
|
* Load any required plugins
|
805
|
699
|
*/
|
806
|
700
|
public void loadRequired() {
|
807
|
|
- final String required = getKeyValue("requires", "plugins", "");
|
|
701
|
+ final String required = metadata.getRequirements().get("plugins");
|
|
702
|
+
|
|
703
|
+ if (required == null) {
|
|
704
|
+ return;
|
|
705
|
+ }
|
|
706
|
+
|
808
|
707
|
for (String pluginName : required.split(",")) {
|
809
|
708
|
final String[] data = pluginName.split(":");
|
810
|
709
|
if (!data[0].trim().isEmpty()) {
|
|
@@ -826,8 +725,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
826
|
725
|
* Load the plugin files.
|
827
|
726
|
*/
|
828
|
727
|
public void loadPlugin() {
|
829
|
|
- if (isLoaded() || metaData == null || isLoading) {
|
830
|
|
- lastError = "Not Loading: (" + isLoaded() + "||" + (metaData == null) + "||" + isLoading + ")";
|
|
728
|
+ if (isLoaded() || isLoading) {
|
|
729
|
+ lastError = "Not Loading: (" + isLoaded() + "||" + isLoading + ")";
|
831
|
730
|
return;
|
832
|
731
|
}
|
833
|
732
|
|
|
@@ -912,10 +811,10 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
912
|
811
|
private void loadClass(final String classname) {
|
913
|
812
|
try {
|
914
|
813
|
if (classloader == null) {
|
915
|
|
- if (getKeyValue("requires", "parent", "").isEmpty()) {
|
|
814
|
+ if (metadata.getParent() == null) {
|
916
|
815
|
classloader = new PluginClassLoader(this);
|
917
|
816
|
} else {
|
918
|
|
- final String parentName = getKeyValue("requires", "parent", "");
|
|
817
|
+ final String parentName = metadata.getParent();
|
919
|
818
|
final PluginInfo pi = PluginManager.getPluginManager().getPluginInfoByName(parentName);
|
920
|
819
|
if (pi == null) {
|
921
|
820
|
lastError = "Required parent '" + parentName + "' was not found";
|
|
@@ -1027,12 +926,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1027
|
926
|
* @return true if plugin can be unloaded
|
1028
|
927
|
*/
|
1029
|
928
|
public boolean isUnloadable() {
|
1030
|
|
- if (isPersistent() || (!isLoaded() && !isTempLoaded())) {
|
1031
|
|
- return false;
|
1032
|
|
- } else {
|
1033
|
|
- final String unloadable = getKeyValue("metadata", "unloadable", "true");
|
1034
|
|
- return unloadable.equalsIgnoreCase("yes") || unloadable.equalsIgnoreCase("true") || unloadable.equalsIgnoreCase("1");
|
1035
|
|
- }
|
|
929
|
+ return !isPersistent() && (isTempLoaded() || isLoaded())
|
|
930
|
+ && metadata.isUnloadable();
|
1036
|
931
|
}
|
1037
|
932
|
|
1038
|
933
|
/**
|
|
@@ -1048,8 +943,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1048
|
943
|
child.unloadPlugin(true);
|
1049
|
944
|
}
|
1050
|
945
|
// Delete ourself as a child of our parent.
|
1051
|
|
- if (!parentUnloading && !getKeyValue("requires", "parent", "").isEmpty()) {
|
1052
|
|
- final String parentName = getKeyValue("requires", "parent", "");
|
|
946
|
+ final String parentName = metadata.getParent();
|
|
947
|
+ if (!parentUnloading && parentName != null) {
|
1053
|
948
|
final PluginInfo pi = PluginManager.getPluginManager().getPluginInfoByName(parentName);
|
1054
|
949
|
if (pi != null) {
|
1055
|
950
|
pi.delChild(this);
|
|
@@ -1103,30 +998,15 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1103
|
998
|
return myClasses;
|
1104
|
999
|
}
|
1105
|
1000
|
|
1106
|
|
- /**
|
1107
|
|
- * Get the value of the given key from the given keysection, or fallback.
|
1108
|
|
- *
|
1109
|
|
- * @param section Section to look in
|
1110
|
|
- * @param key Key to check
|
1111
|
|
- * @param fallback Value to use if key doesn't exist.
|
1112
|
|
- * @return Value of the key in the keysection, or the fallback if not present
|
1113
|
|
- */
|
1114
|
|
- public String getKeyValue(final String section, final String key, final String fallback) {
|
1115
|
|
- if (metaData != null && metaData.isKeyDomain(section)) {
|
1116
|
|
- final Map<String, String> keysection = metaData.getKeyDomain(section);
|
1117
|
|
- return keysection.containsKey(key) ? keysection.get(key) : fallback;
|
1118
|
|
- }
|
1119
|
|
-
|
1120
|
|
- return fallback;
|
1121
|
|
- }
|
1122
|
|
-
|
1123
|
1001
|
/**
|
1124
|
1002
|
* Get the main Class
|
1125
|
1003
|
*
|
1126
|
1004
|
* @return Main Class to begin loading.
|
|
1005
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1127
|
1006
|
*/
|
|
1007
|
+ @Deprecated
|
1128
|
1008
|
public String getMainClass() {
|
1129
|
|
- return getKeyValue("metadata", "mainclass", "");
|
|
1009
|
+ return metadata.getMainClass();
|
1130
|
1010
|
}
|
1131
|
1011
|
|
1132
|
1012
|
/**
|
|
@@ -1151,18 +1031,22 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1151
|
1031
|
* Get the plugin friendly version
|
1152
|
1032
|
*
|
1153
|
1033
|
* @return Plugin friendly Version
|
|
1034
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1154
|
1035
|
*/
|
|
1036
|
+ @Deprecated
|
1155
|
1037
|
public String getFriendlyVersion() {
|
1156
|
|
- return getKeyValue("version", "friendly", String.valueOf(getVersion()));
|
|
1038
|
+ return metadata.getFriendlyVersion();
|
1157
|
1039
|
}
|
1158
|
1040
|
|
1159
|
1041
|
/**
|
1160
|
1042
|
* Get the plugin version
|
1161
|
1043
|
*
|
1162
|
1044
|
* @return Plugin Version
|
|
1045
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1163
|
1046
|
*/
|
|
1047
|
+ @Deprecated
|
1164
|
1048
|
public Version getVersion() {
|
1165
|
|
- return new Version(getKeyValue("version", "number", "0"));
|
|
1049
|
+ return metadata.getVersion();
|
1166
|
1050
|
}
|
1167
|
1051
|
|
1168
|
1052
|
/**
|
|
@@ -1175,13 +1059,11 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1175
|
1059
|
* @return Addon Site ID number
|
1176
|
1060
|
* -1 If not present
|
1177
|
1061
|
* -2 If non-integer
|
|
1062
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1178
|
1063
|
*/
|
|
1064
|
+ @Deprecated
|
1179
|
1065
|
public int getAddonID() {
|
1180
|
|
- try {
|
1181
|
|
- return Integer.parseInt(getKeyValue("updates", "id", "-1"));
|
1182
|
|
- } catch (NumberFormatException nfe) {
|
1183
|
|
- return -2;
|
1184
|
|
- }
|
|
1066
|
+ return metadata.getUpdaterId();
|
1185
|
1067
|
}
|
1186
|
1068
|
|
1187
|
1069
|
/**
|
|
@@ -1190,12 +1072,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1190
|
1072
|
* @return true if persistent, else false
|
1191
|
1073
|
*/
|
1192
|
1074
|
public boolean isPersistent() {
|
1193
|
|
- if (metaData != null && metaData.isFlatDomain("persistent")) {
|
1194
|
|
- final List<String> items = metaData.getFlatDomain("persistent");
|
1195
|
|
- return items.contains("*");
|
1196
|
|
- }
|
1197
|
|
-
|
1198
|
|
- return false;
|
|
1075
|
+ return metadata.getPersistentClasses().contains("*");
|
1199
|
1076
|
}
|
1200
|
1077
|
|
1201
|
1078
|
/**
|
|
@@ -1204,12 +1081,7 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1204
|
1081
|
* @return true if this plugin contains any persistent classes, else false
|
1205
|
1082
|
*/
|
1206
|
1083
|
public boolean hasPersistent() {
|
1207
|
|
- if (metaData != null && metaData.isFlatDomain("persistent")) {
|
1208
|
|
- final List<String> items = metaData.getFlatDomain("persistent");
|
1209
|
|
- return !items.isEmpty();
|
1210
|
|
- }
|
1211
|
|
-
|
1212
|
|
- return false;
|
|
1084
|
+ return !metadata.getPersistentClasses().isEmpty();
|
1213
|
1085
|
}
|
1214
|
1086
|
|
1215
|
1087
|
/**
|
|
@@ -1217,8 +1089,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1217
|
1089
|
*
|
1218
|
1090
|
* @return List of all persistent classes in this plugin
|
1219
|
1091
|
*/
|
1220
|
|
- public List<String> getPersistentClasses() {
|
1221
|
|
- final List<String> result = new ArrayList<String>();
|
|
1092
|
+ public Collection<String> getPersistentClasses() {
|
|
1093
|
+ final Collection<String> result = new ArrayList<String>();
|
1222
|
1094
|
|
1223
|
1095
|
if (isPersistent()) {
|
1224
|
1096
|
try {
|
|
@@ -1232,11 +1104,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1232
|
1104
|
} catch (IOException e) {
|
1233
|
1105
|
// Jar no longer exists?
|
1234
|
1106
|
}
|
1235
|
|
- } else if (metaData != null && metaData.isFlatDomain("persistent")) {
|
1236
|
|
- return metaData.getFlatDomain("persistent");
|
1237
|
1107
|
}
|
1238
|
1108
|
|
1239
|
|
- return result;
|
|
1109
|
+ return metadata.getPersistentClasses();
|
1240
|
1110
|
}
|
1241
|
1111
|
|
1242
|
1112
|
/**
|
|
@@ -1248,11 +1118,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1248
|
1118
|
public boolean isPersistent(final String classname) {
|
1249
|
1119
|
if (isPersistent()) {
|
1250
|
1120
|
return true;
|
1251
|
|
- } else if (metaData != null && metaData.isFlatDomain("persistent")) {
|
1252
|
|
- final List<String> items = metaData.getFlatDomain("persistent");
|
1253
|
|
- return items.contains(classname);
|
1254
|
1121
|
} else {
|
1255
|
|
- return false;
|
|
1122
|
+ return metadata.getPersistentClasses().contains(classname);
|
1256
|
1123
|
}
|
1257
|
1124
|
}
|
1258
|
1125
|
|
|
@@ -1293,18 +1160,22 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1293
|
1160
|
* Get the plugin Author.
|
1294
|
1161
|
*
|
1295
|
1162
|
* @return Author of plugin
|
|
1163
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1296
|
1164
|
*/
|
|
1165
|
+ @Deprecated
|
1297
|
1166
|
public String getAuthor() {
|
1298
|
|
- return getKeyValue("metadata", "author", "");
|
|
1167
|
+ return metadata.getAuthor();
|
1299
|
1168
|
}
|
1300
|
1169
|
|
1301
|
1170
|
/**
|
1302
|
1171
|
* Get the plugin Description.
|
1303
|
1172
|
*
|
1304
|
1173
|
* @return Description of plugin
|
|
1174
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1305
|
1175
|
*/
|
|
1176
|
+ @Deprecated
|
1306
|
1177
|
public String getDescription() {
|
1307
|
|
- return getKeyValue("metadata", "description", "");
|
|
1178
|
+ return metadata.getDescription();
|
1308
|
1179
|
}
|
1309
|
1180
|
|
1310
|
1181
|
/**
|
|
@@ -1313,8 +1184,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1313
|
1184
|
* @return minimum dmdirc version required to run the plugin.
|
1314
|
1185
|
*/
|
1315
|
1186
|
public String getMinVersion() {
|
1316
|
|
- final String requiredVersion = getKeyValue("requires", "dmdirc", "");
|
1317
|
|
- if (!requiredVersion.isEmpty()) {
|
|
1187
|
+ final String requiredVersion = metadata.getRequirements().get("dmdirc");
|
|
1188
|
+
|
|
1189
|
+ if (requiredVersion != null) {
|
1318
|
1190
|
final String[] bits = requiredVersion.split("-");
|
1319
|
1191
|
return bits[0];
|
1320
|
1192
|
}
|
|
@@ -1328,8 +1200,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1328
|
1200
|
* @return optional maximum dmdirc version on which this plugin can run
|
1329
|
1201
|
*/
|
1330
|
1202
|
public String getMaxVersion() {
|
1331
|
|
- final String requiredVersion = getKeyValue("requires", "dmdirc", "");
|
1332
|
|
- if (!requiredVersion.isEmpty()) {
|
|
1203
|
+ final String requiredVersion = metadata.getRequirements().get("dmdirc");
|
|
1204
|
+
|
|
1205
|
+ if (requiredVersion != null) {
|
1333
|
1206
|
final String[] bits = requiredVersion.split("-");
|
1334
|
1207
|
if (bits.length > 1) {
|
1335
|
1208
|
return bits[1];
|
|
@@ -1343,18 +1216,22 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1343
|
1216
|
* Get the name of the plugin. (Used to identify the plugin)
|
1344
|
1217
|
*
|
1345
|
1218
|
* @return Name of plugin
|
|
1219
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1346
|
1220
|
*/
|
|
1221
|
+ @Deprecated
|
1347
|
1222
|
public String getName() {
|
1348
|
|
- return getKeyValue("metadata", "name", "");
|
|
1223
|
+ return metadata.getName();
|
1349
|
1224
|
}
|
1350
|
1225
|
|
1351
|
1226
|
/**
|
1352
|
1227
|
* Get the nice name of the plugin. (Displayed to users)
|
1353
|
1228
|
*
|
1354
|
1229
|
* @return Nice Name of plugin
|
|
1230
|
+ * @deprecated Retrieve this from {@link PluginMetaData} directly
|
1355
|
1231
|
*/
|
|
1232
|
+ @Deprecated
|
1356
|
1233
|
public String getNiceName() {
|
1357
|
|
- return getKeyValue("metadata", "nicename", getName());
|
|
1234
|
+ return metadata.getFriendlyName();
|
1358
|
1235
|
}
|
1359
|
1236
|
|
1360
|
1237
|
/**
|
|
@@ -1367,16 +1244,6 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1367
|
1244
|
return getNiceName() + " - " + filename;
|
1368
|
1245
|
}
|
1369
|
1246
|
|
1370
|
|
- /**
|
1371
|
|
- * Does this plugin want all its classes loaded?
|
1372
|
|
- *
|
1373
|
|
- * @return true/false if loadall=true || loadall=yes
|
1374
|
|
- */
|
1375
|
|
- public boolean loadAll() {
|
1376
|
|
- final String loadAll = getKeyValue("metadata", "loadall", "no");
|
1377
|
|
- return loadAll.equalsIgnoreCase("true") || loadAll.equalsIgnoreCase("yes");
|
1378
|
|
- }
|
1379
|
|
-
|
1380
|
1247
|
/** {@inheritDoc} */
|
1381
|
1248
|
@Override
|
1382
|
1249
|
public int compareTo(final PluginInfo o) {
|
|
@@ -1390,24 +1257,22 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
1390
|
1257
|
exports.clear();
|
1391
|
1258
|
|
1392
|
1259
|
// Get exports provided by this plugin
|
1393
|
|
- final List<String> exportsList = metaData.getFlatDomain("exports");
|
1394
|
|
- if (exportsList != null) {
|
1395
|
|
- for (String item : exportsList) {
|
1396
|
|
- final String[] bits = item.split(" ");
|
1397
|
|
- if (bits.length > 2) {
|
1398
|
|
- final String methodName = bits[0];
|
1399
|
|
- final String methodClass = bits[2];
|
1400
|
|
- final String serviceName = (bits.length > 4) ? bits[4] : bits[0];
|
1401
|
|
-
|
1402
|
|
- // Add a provides for this
|
1403
|
|
- final Service service = PluginManager.getPluginManager().getService("export", serviceName, true);
|
1404
|
|
- synchronized (provides) {
|
1405
|
|
- service.addProvider(this);
|
1406
|
|
- provides.add(service);
|
1407
|
|
- }
|
1408
|
|
- // Add is as an export
|
1409
|
|
- exports.put(serviceName, new ExportInfo(methodName, methodClass, this));
|
|
1260
|
+ final Collection<String> exportsList = metadata.getExports();
|
|
1261
|
+ for (String item : exportsList) {
|
|
1262
|
+ final String[] bits = item.split(" ");
|
|
1263
|
+ if (bits.length > 2) {
|
|
1264
|
+ final String methodName = bits[0];
|
|
1265
|
+ final String methodClass = bits[2];
|
|
1266
|
+ final String serviceName = (bits.length > 4) ? bits[4] : bits[0];
|
|
1267
|
+
|
|
1268
|
+ // Add a provides for this
|
|
1269
|
+ final Service service = PluginManager.getPluginManager().getService("export", serviceName, true);
|
|
1270
|
+ synchronized (provides) {
|
|
1271
|
+ service.addProvider(this);
|
|
1272
|
+ provides.add(service);
|
1410
|
1273
|
}
|
|
1274
|
+ // Add is as an export
|
|
1275
|
+ exports.put(serviceName, new ExportInfo(methodName, methodClass, this));
|
1411
|
1276
|
}
|
1412
|
1277
|
}
|
1413
|
1278
|
}
|