Browse Source

Overhauled plugins system. (Fixes issue 479)

Fixed issue 495 (Configure plugins menu doesn't disable untill mouse over)


git-svn-id: http://svn.dmdirc.com/trunk@2614 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Shane Mc Cormack 16 years ago
parent
commit
61510ce5fe
44 changed files with 897 additions and 716 deletions
  1. 51
    0
      createPluginJar.sh
  2. 1
    5
      src/com/dmdirc/actions/CoreActionType.java
  3. 2
    2
      src/com/dmdirc/actions/metatypes/PluginEvents.java
  4. 3
    40
      src/com/dmdirc/addons/audio/AudioPlugin.java
  5. 8
    0
      src/com/dmdirc/addons/audio/plugin.info
  6. 0
    6
      src/com/dmdirc/addons/compileall.sh
  7. 7
    21
      src/com/dmdirc/addons/dcop/DcopPlugin.java
  8. 8
    0
      src/com/dmdirc/addons/dcop/plugin.info
  9. 2
    27
      src/com/dmdirc/addons/dns/DNSPlugin.java
  10. 8
    0
      src/com/dmdirc/addons/dns/plugin.info
  11. 3
    49
      src/com/dmdirc/addons/identd/IdentdPlugin.java
  12. 8
    0
      src/com/dmdirc/addons/identd/plugin.info
  13. 2
    28
      src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java
  14. 8
    0
      src/com/dmdirc/addons/lagdisplay/plugin.info
  15. 8
    4
      src/com/dmdirc/addons/logging/LoggingCommand.java
  16. 3
    40
      src/com/dmdirc/addons/logging/LoggingPlugin.java
  17. 8
    0
      src/com/dmdirc/addons/logging/plugin.info
  18. 8
    20
      src/com/dmdirc/addons/mediasources/dcop/DcopMediaSourcePlugin.java
  19. 8
    0
      src/com/dmdirc/addons/mediasources/plugin.info
  20. 5
    26
      src/com/dmdirc/addons/nickcolours/NickColourPlugin.java
  21. 8
    0
      src/com/dmdirc/addons/nickcolours/plugin.info
  22. 10
    0
      src/com/dmdirc/addons/nowplaying/plugin.info
  23. 23
    47
      src/com/dmdirc/addons/nowplaying/plugin/NowPlayingPlugin.java
  24. 2
    24
      src/com/dmdirc/addons/osdplugin/OsdPlugin.java
  25. 8
    0
      src/com/dmdirc/addons/osdplugin/plugin.info
  26. 2
    26
      src/com/dmdirc/addons/redirectplugin/RedirectPlugin.java
  27. 8
    0
      src/com/dmdirc/addons/redirectplugin/plugin.info
  28. 4
    26
      src/com/dmdirc/addons/systray/SystrayPlugin.java
  29. 8
    0
      src/com/dmdirc/addons/systray/plugin.info
  30. 3
    28
      src/com/dmdirc/addons/timeplugin/TimePlugin.java
  31. 10
    0
      src/com/dmdirc/addons/timeplugin/plugin.info
  32. 3
    40
      src/com/dmdirc/addons/windowstatus/WindowStatusPlugin.java
  33. 8
    0
      src/com/dmdirc/addons/windowstatus/plugin.info
  34. 6
    5
      src/com/dmdirc/commandparser/commands/global/Ifplugin.java
  35. 4
    3
      src/com/dmdirc/commandparser/commands/global/LoadPlugin.java
  36. 5
    7
      src/com/dmdirc/commandparser/commands/global/ReloadPlugin.java
  37. 7
    66
      src/com/dmdirc/plugins/Plugin.java
  38. 28
    40
      src/com/dmdirc/plugins/PluginClassLoader.java
  39. 62
    0
      src/com/dmdirc/plugins/PluginException.java
  40. 370
    0
      src/com/dmdirc/plugins/PluginInfo.java
  41. 126
    110
      src/com/dmdirc/plugins/PluginManager.java
  42. 16
    10
      src/com/dmdirc/ui/swing/MainFrame.java
  43. 5
    4
      src/com/dmdirc/ui/swing/components/PluginCellRenderer.java
  44. 20
    12
      src/com/dmdirc/ui/swing/dialogs/PluginDialog.java

+ 51
- 0
createPluginJar.sh View File

@@ -0,0 +1,51 @@
1
+#!/bin/bash
2
+# This script will create a plugin jar file for a given plugin.
3
+
4
+if [ "${1}" = "" -o "${2}" = "" ]; then
5
+	echo "Usage Example: ${0} com.dmdirc.addons.windowstatus WindowStatusPlugin"
6
+	echo "The above would create WindowStatusPlugin.jar in the plugins/ folder of the current dir"
7
+	exit;
8
+fi
9
+
10
+pluginname=${1}
11
+foldername=${pluginname//.//}
12
+
13
+echo "Creating ${2}.jar for ${pluginname} (${foldername})"
14
+
15
+if [ ! -e src/${foldername}/plugin.info ]; then
16
+	echo "no plugin.info found";
17
+	exit 0;
18
+fi
19
+
20
+echo "Building dmdirc"
21
+
22
+echo "looking for classes"
23
+srcdir=${PWD}
24
+TMPDIR=`mktemp -d`
25
+echo "Using temp dir: ${TMPDIR}"
26
+cd $TMPDIR
27
+
28
+mkdir META-INF
29
+cp ${srcdir}/src/${foldername}/plugin.info META-INF/
30
+foo=`echo $foldername | sed -e 's/\/[^\/]*$//g'`
31
+mkdir -p $foo
32
+cd ${foo}
33
+ln -s ${srcdir}/build/classes/${foldername} .
34
+cd $TMPDIR
35
+mkdir -p ${srcdir}/plugins/
36
+rm -Rf ${srcdir}/plugins/${2}.jar
37
+jar -cvf ${srcdir}/src/${foldername}/${2}.jar META-INF/plugin.info
38
+bit=""
39
+while [ 1 -eq 1 ]; do
40
+	bit=${bit}/*
41
+	ls ${foo}${bit}/*
42
+	if [ ${?} -ne 0 ]; then
43
+		break;
44
+	else
45
+		for thisfile in `ls -1 ${foo}${bit}/*.class`; do
46
+			jar -uvf ${srcdir}/src/${foldername}/${2}.jar ${thisfile}
47
+		done
48
+	fi
49
+done
50
+
51
+echo "done";

+ 1
- 5
src/com/dmdirc/actions/CoreActionType.java View File

@@ -174,11 +174,7 @@ public enum CoreActionType implements ActionType {
174 174
     /** Plugin loaded. */
175 175
     PLUGIN_LOADED(PluginEvents.PLUGIN_EVENT, "Plugin loaded"),
176 176
     /** Plugin unloaded. */
177
-    PLUGIN_UNLOADED(PluginEvents.PLUGIN_EVENT, "Plugin unloaded"),
178
-    /** Plugin activated. */
179
-    PLUGIN_ACTIVATED(PluginEvents.PLUGIN_EVENT, "Plugin activated"),
180
-    /** Plugin deactivated. */
181
-    PLUGIN_DEACTIVATED(PluginEvents.PLUGIN_EVENT, "Plugin deactivated");
177
+    PLUGIN_UNLOADED(PluginEvents.PLUGIN_EVENT, "Plugin unloaded");
182 178
     
183 179
     /** The type of this action. */
184 180
     private final ActionMetaType type;

+ 2
- 2
src/com/dmdirc/actions/metatypes/PluginEvents.java View File

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.actions.metatypes;
24 24
 
25 25
 import com.dmdirc.actions.ActionMetaType;
26
-import com.dmdirc.plugins.Plugin;
26
+import com.dmdirc.plugins.PluginInfo;
27 27
 
28 28
 /**
29 29
  * Defines plugin-related events.
@@ -33,7 +33,7 @@ import com.dmdirc.plugins.Plugin;
33 33
 public enum PluginEvents implements ActionMetaType {
34 34
     
35 35
     /** Plugin event type. */
36
-    PLUGIN_EVENT(new String[]{"plugin"}, Plugin.class);
36
+    PLUGIN_EVENT(new String[]{"plugin"}, PluginInfo.class);
37 37
     
38 38
     private String[] argNames;
39 39
     private Class[] argTypes;

+ 3
- 40
src/com/dmdirc/addons/audio/AudioPlugin.java View File

@@ -41,54 +41,17 @@ public final class AudioPlugin extends Plugin {
41 41
 	
42 42
 	/**
43 43
 	 * Called when the plugin is loaded.
44
-	 *
45
-	 * @return false if the plugin can not be loaded
46
-	 */
47
-	public boolean onLoad() {
48
-		return true;
49
-	}
50
-	
51
-	/**
52
-	 * Called when this plugin is activated.
53 44
 	 */
54
-	public void onActivate() {
45
+	public void onLoad() {
55 46
 		command = new AudioCommand();
56 47
 	}
57 48
 	
58 49
 	/**
59
-	 * Called when this plugin is deactivated.
50
+	 * Called when this plugin is Unloaded
60 51
 	 */
61
-	public void onDeactivate() {
52
+	public void onUnload() {
62 53
 		CommandManager.unregisterCommand(command);
63 54
 	}
64
-
65
-	/**
66
-	 * Get the plugin version.
67
-	 *
68
-	 * @return Plugin Version
69
-	 */
70
-	public String getVersion() { return "0.1"; }
71
-	
72
-	/**
73
-	 * Get the plugin Author.
74
-	 *
75
-	 * @return Author of plugin
76
-	 */
77
-	public String getAuthor() { return "Shane <shane@dmdirc.com>"; }
78
-	
79
-	/**
80
-	 * Get the plugin Description.
81
-	 *
82
-	 * @return Description of plugin
83
-	 */
84
-	public String getDescription() { return "Allows playing audio files"; }
85
-	
86
-	/**
87
-	 * Get the name of the plugin (used in "Manage Plugins" dialog).
88
-	 *
89
-	 * @return Name of plugin
90
-	 */
91
-	public String toString() { return "Audio Plugin"; }
92 55
 	
93 56
 	/**
94 57
 	 * Get SVN Version information.

+ 8
- 0
src/com/dmdirc/addons/audio/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.audio.AudioPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Shane <shane@dmdirc.com>
5
+description=Allows playing audio files
6
+name=audio
7
+nicename=Audio Plugin
8
+minversion=0

+ 0
- 6
src/com/dmdirc/addons/compileall.sh View File

@@ -1,6 +0,0 @@
1
-#!/bin/sh
2
-# Quick script to recompile all plugins
3
-rm ./*/*.class
4
-rm ./*/*/*.class
5
-cd ../../../
6
-javac -Xlint:all com/dmdirc/addons/*/*.java com/dmdirc/addons/*/*/*.java

+ 7
- 21
src/com/dmdirc/addons/dcop/DcopPlugin.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.dcop;
24 24
 
25 25
 import com.dmdirc.plugins.Plugin;
26
+import com.dmdirc.commandparser.CommandManager;
26 27
 
27 28
 import java.io.BufferedReader;
28 29
 import java.io.IOException;
@@ -36,6 +37,8 @@ import java.util.List;
36 37
  * @author chris
37 38
  */
38 39
 public final class DcopPlugin extends Plugin {
40
+    /** The DcopCommand we created */
41
+    private DcopCommand command = null;
39 42
     
40 43
     /** Creates a new instance of DcopPlugin. */
41 44
     public DcopPlugin() {
@@ -78,34 +81,17 @@ public final class DcopPlugin extends Plugin {
78 81
     }
79 82
     
80 83
     /** {@inheritDoc}. */
81
-    public boolean onLoad() {
82
-        new DcopCommand();
83
-        
84
-        return true;
85
-    }
86
-    
87
-    /** {@inheritDoc}. */
88
-    public String getVersion() {
89
-        return "0.2";
90
-    }
91
-    
92
-    /** {@inheritDoc}. */
93
-    public String getAuthor() {
94
-        return "Chris <chris@dmdirc.com>";
84
+    public void onLoad() {
85
+        command = new DcopCommand();
95 86
     }
96 87
     
97 88
     /** {@inheritDoc}. */
98
-    public String getDescription() {
99
-        return "Provides commands to interface with DCOP applications";
89
+    public void onUnload() {
90
+        CommandManager.unregisterCommand(command);
100 91
     }
101 92
     
102 93
     /** {@inheritDoc}. */
103 94
     public boolean isConfigurable() {
104 95
         return false;
105 96
     }
106
-    
107
-    /** {@inheritDoc}. */
108
-    public String toString() {
109
-        return "DCOP Plugin";
110
-    }
111 97
 }

+ 8
- 0
src/com/dmdirc/addons/dcop/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.dcop.DcopPlugin
2
+version=3
3
+friendlyversion=0.3
4
+author=Chris <chris@dmdirc.com>
5
+description=Provides commands to interface with DCOP applications
6
+name=dcop
7
+nicename=DCOP Plugin
8
+minversion=0

+ 2
- 27
src/com/dmdirc/addons/dns/DNSPlugin.java View File

@@ -45,40 +45,15 @@ public final class DNSPlugin extends Plugin {
45 45
     }
46 46
     
47 47
     /** {@inheritDoc} */
48
-    public boolean onLoad() {
49
-        return true;
50
-    }
51
-    
52
-    /** {@inheritDoc} */
53
-    public void onActivate() {
48
+    public void onLoad() {
54 49
         command = new DNSCommand();
55 50
     }
56 51
     
57 52
     /** {@inheritDoc} */
58
-    public void onDeactivate() {
53
+    public void onUnload() {
59 54
         CommandManager.unregisterCommand(command);
60 55
     }
61 56
     
62
-    /** {@inheritDoc} */
63
-    public String getVersion() {
64
-        return "0.1";
65
-    }
66
-    
67
-    /** {@inheritDoc} */
68
-    public String getAuthor() {
69
-        return "Greboid <greg@dmdirc.com>";
70
-    }
71
-    
72
-    /** {@inheritDoc} */
73
-    public String getDescription() {
74
-        return "Provides a DNS command and method to the client.";
75
-    }
76
-    
77
-    /** {@inheritDoc} */
78
-    public String toString() {
79
-        return "DNS plugin";
80
-    }
81
-    
82 57
     /**
83 58
      * Returns the IP(s) for a hostname.
84 59
      *

+ 8
- 0
src/com/dmdirc/addons/dns/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.dns.DNSPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Greboid <greg@dmdirc.com>
5
+description=Provides a DNS command and method to the client
6
+name=dns
7
+nicename=DNS Plugin
8
+minversion=0

+ 3
- 49
src/com/dmdirc/addons/identd/IdentdPlugin.java View File

@@ -56,10 +56,8 @@ public class IdentdPlugin extends Plugin implements EventPlugin, PreferencesInte
56 56
 	
57 57
 	/**
58 58
 	 * Called when the plugin is loaded.
59
-	 *
60
-	 * @return false if the plugin can not be loaded
61 59
 	 */
62
-	public boolean onLoad() {
60
+	public void onLoad() {
63 61
 		// Set defaults
64 62
 		Properties defaults = new Properties();
65 63
 		defaults.setProperty(getDomain() + ".general.useUsername", "false");
@@ -77,14 +75,6 @@ public class IdentdPlugin extends Plugin implements EventPlugin, PreferencesInte
77 75
 		defaults.setProperty("identity.name", "Identd Plugin Defaults");
78 76
 		IdentityManager.addIdentity(new Identity(defaults));
79 77
 		
80
-		return true;
81
-	}
82
-	
83
-	
84
-	/**
85
-	 * Called when this plugin is Activated.
86
-	 */
87
-	public void onActivate() {
88 78
 		myServer = new IdentdServer(this);
89 79
 		if (IdentityManager.getGlobalConfig().getOptionBool(getDomain(), "advanced.alwaysOn")) {
90 80
 			myServer.startServer();
@@ -92,49 +82,13 @@ public class IdentdPlugin extends Plugin implements EventPlugin, PreferencesInte
92 82
 	}
93 83
 	
94 84
 	/**
95
-	 * Called when this plugin is deactivated.
85
+	 * Called when this plugin is unloaded.
96 86
 	 */
97
-	public void onDeactivate() {
87
+	public void onUnload() {
98 88
 		myServer.stopServer();
99 89
 		servers.clear();
100 90
 	}
101 91
 	
102
-	/**
103
-	 * Get the plugin version.
104
-	 *
105
-	 * @return Plugin Version
106
-	 */
107
-	public String getVersion() {
108
-		return "0.1";
109
-	}
110
-	
111
-	/**
112
-	 * Get the plugin Author.
113
-	 *
114
-	 * @return Author of plugin
115
-	 */
116
-	public String getAuthor() {
117
-		return "Shane <shane@dmdirc.com>";
118
-	}
119
-	
120
-	/**
121
-	 * Get the plugin Description.
122
-	 *
123
-	 * @return Description of plugin
124
-	 */
125
-	public String getDescription() {
126
-		return "Answers ident requests from IRC servers";
127
-	}
128
-	
129
-	/**
130
-	 * Get the name of the plugin (used in "Manage Plugins" dialog).
131
-	 *
132
-	 * @return Name of plugin
133
-	 */
134
-	public String toString() {
135
-		return "Identd";
136
-	}
137
-	
138 92
 	/**
139 93
 	 * Process an event of the specified type.
140 94
 	 *

+ 8
- 0
src/com/dmdirc/addons/identd/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.identd.IdentdPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Shane <shane@dmdirc.com>
5
+description=Answers ident requests from IRC servers
6
+name=identd
7
+nicename=Identd Plugin
8
+minversion=0

+ 2
- 28
src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java View File

@@ -74,36 +74,15 @@ public final class LagDisplayPlugin extends Plugin implements EventPlugin,
74 74
     }
75 75
     
76 76
     /** {@inheritDoc} */
77
-    public boolean onLoad() {
78
-        
79
-        return true;
80
-    }
81
-    
82
-    /** {@inheritDoc} */
83
-    public void onActivate() {
77
+    public void onLoad() {
84 78
         Main.getUI().getStatusBar().addComponent(panel);
85 79
     }
86 80
     
87 81
     /** {@inheritDoc} */
88
-    public void onDeactivate() {
82
+    public void onUnload() {
89 83
         Main.getUI().getStatusBar().removeComponent(panel);
90 84
     }
91 85
     
92
-    /** {@inheritDoc} */
93
-    public String getVersion() {
94
-        return "0.2";
95
-    }
96
-    
97
-    /** {@inheritDoc} */
98
-    public String getAuthor() {
99
-        return "Chris <chris@dmdirc.com>";
100
-    }
101
-    
102
-    /** {@inheritDoc} */
103
-    public String getDescription() {
104
-        return "Displays the server lag in the status bar";
105
-    }
106
-    
107 86
     /** {@inheritDoc} */
108 87
     public boolean isConfigurable() {
109 88
         return false;
@@ -113,11 +92,6 @@ public final class LagDisplayPlugin extends Plugin implements EventPlugin,
113 92
     public void showConfig() {
114 93
     }
115 94
     
116
-    /** {@inheritDoc}. */
117
-    public String toString() {
118
-        return "Lag Displayer";
119
-    }
120
-    
121 95
     /** {@inheritDoc} */
122 96
     public void processEvent(final ActionType type, final StringBuffer format, final Object... arguments) {
123 97
         if (!useAlternate && type.equals(CoreActionType.SERVER_GOTPING)) {

+ 8
- 0
src/com/dmdirc/addons/lagdisplay/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.lagdisplay.LagDisplayPlugin
2
+version=3
3
+friendlyversion=0.3
4
+author=Chris <chris@dmdirc.com>
5
+description=Displays the server lag in the status bar
6
+name=laddisplay
7
+nicename=Lag Displayer
8
+minversion=0

+ 8
- 4
src/com/dmdirc/addons/logging/LoggingCommand.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 28
 import com.dmdirc.commandparser.commands.ServerCommand;
29 29
 import com.dmdirc.plugins.Plugin;
30
+import com.dmdirc.plugins.PluginInfo;
30 31
 import com.dmdirc.plugins.PluginManager;
31 32
 import com.dmdirc.ui.input.AdditionalTabTargets;
32 33
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -57,7 +58,12 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
57 58
 	 * @param args The user supplied arguments
58 59
 	 */
59 60
 	public void execute(final InputWindow origin, final Server server, final boolean isSilent, final String... args) {
60
-		final Plugin gotPlugin = PluginManager.getPluginManager().getPlugin("com.dmdirc.addons.logging.LoggingPlugin");
61
+		final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("LoggingPlugin");
62
+		if (pluginInfo == null) { 
63
+			sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
64
+			return;
65
+		}
66
+		final Plugin gotPlugin = pluginInfo.getPlugin();
61 67
 		
62 68
 		if (gotPlugin == null || !(gotPlugin instanceof LoggingPlugin)) {
63 69
 			sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
@@ -70,10 +76,8 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
70 76
 			if (args[0].equalsIgnoreCase("config")) {
71 77
 				plugin.showConfig();
72 78
 			} else if (args[0].equalsIgnoreCase("reload")) {
73
-				boolean wasActive = plugin.isActive();
74
-				if (PluginManager.getPluginManager().reloadPlugin("com.dmdirc.addons.logging.LoggingPlugin")) {
79
+				if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
75 80
 					sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin reloaded.");
76
-					PluginManager.getPluginManager().getPlugin("com.dmdirc.addons.logging.LoggingPlugin").setActive(wasActive);
77 81
 				} else {
78 82
 					sendLine(origin, isSilent, FORMAT_ERROR, "Plugin failed to reload.");
79 83
 				}

+ 3
- 40
src/com/dmdirc/addons/logging/LoggingPlugin.java View File

@@ -84,10 +84,8 @@ public final class LoggingPlugin extends Plugin implements EventPlugin, Preferen
84 84
 	
85 85
 	/**
86 86
 	 * Called when the plugin is loaded.
87
-	 *
88
-	 * @return false if the plugin can not be loaded
89 87
 	 */
90
-	public boolean onLoad() {
88
+	public void onLoad() {
91 89
 		// Set defaults
92 90
 		Properties defaults = new Properties();
93 91
 		defaults.setProperty(MY_DOMAIN + ".general.directory", Main.getConfigDir() + "logs" + System.getProperty("file.separator"));
@@ -119,20 +117,13 @@ public final class LoggingPlugin extends Plugin implements EventPlugin, Preferen
119 117
 			}
120 118
 		}
121 119
 		
122
-		return true;
123
-	}
124
-	
125
-	/**
126
-	 * Called when this plugin is activated.
127
-	 */
128
-	public void onActivate() {
129 120
 		command = new LoggingCommand();
130 121
 	}
131 122
 	
132 123
 	/**
133
-	 * Called when this plugin is deactivated.
124
+	 * Called when this plugin is unloaded.
134 125
 	 */
135
-	public void onDeactivate() {
126
+	public void onUnload() {
136 127
 		CommandManager.unregisterCommand(command);
137 128
 		
138 129
 		BufferedWriter file;
@@ -257,34 +248,6 @@ public final class LoggingPlugin extends Plugin implements EventPlugin, Preferen
257 248
 	 */
258 249
 	public void configCancelled() { }
259 250
 	
260
-	/**
261
-	 * Get the plugin version.
262
-	 *
263
-	 * @return Plugin Version
264
-	 */
265
-	public String getVersion() { return "0.3"; }
266
-	
267
-	/**
268
-	 * Get the plugin Author.
269
-	 *
270
-	 * @return Author of plugin
271
-	 */
272
-	public String getAuthor() { return "Shane <shane@dmdirc.com>"; }
273
-	
274
-	/**
275
-	 * Get the plugin Description.
276
-	 *
277
-	 * @return Description of plugin
278
-	 */
279
-	public String getDescription() { return "Allows logging of conversations"; }
280
-	
281
-	/**
282
-	 * Get the name of the plugin (used in "Manage Plugins" dialog).
283
-	 *
284
-	 * @return Name of plugin
285
-	 */
286
-	public String toString() { return "Logging Plugin"; }
287
-	
288 251
 	/**
289 252
 	 * Process an event of the specified type.
290 253
 	 *

+ 8
- 0
src/com/dmdirc/addons/logging/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.logging.LoggingPlugin
2
+version=4
3
+friendlyversion=0.4
4
+author=Shane <shane@dmdirc.com>
5
+description=Allows logging of conversations
6
+name=logging
7
+nicename=Logging Plugin
8
+minversion=0

+ 8
- 20
src/com/dmdirc/addons/mediasources/dcop/DcopMediaSourcePlugin.java View File

@@ -57,31 +57,19 @@ public class DcopMediaSourcePlugin extends Plugin
57 57
     }
58 58
     
59 59
     /** {@inheritDoc} */
60
-    public boolean onLoad() {
61
-        if (Arrays.asList(PluginManager.getPluginManager().getNames()).
62
-                contains("com.dmdirc.addons.dcop.dcopplugin")) {
63
-            return true;
64
-        }
65
-        return false;
66
-    }
67
-    
68
-    /** {@inheritDoc} */
69
-    public String getVersion() {
70
-        return "0.1";
60
+    public void onLoad() {
71 61
     }
72 62
     
73 63
     /** {@inheritDoc} */
74
-    public String getAuthor() {
75
-        return "Greboid <greboid@dmdirc.com>";
64
+    public void onUnload() {
76 65
     }
77 66
     
78 67
     /** {@inheritDoc} */
79
-    public String getDescription() {
80
-        return "Provides DCOP media sources for the now playing plugin";
81
-    }
82
-    
83
-    /** {@inheritDoc} */
84
-    public String toString() {
85
-        return "DCOP media sources";
68
+    public boolean checkPrerequisites() {
69
+        if (Arrays.asList(PluginManager.getPluginManager().getMainClassNames()).
70
+                contains("com.dmdirc.addons.dcop.DcopPlugin")) {
71
+            return true;
72
+        }
73
+        return false;
86 74
     }
87 75
 }

+ 8
- 0
src/com/dmdirc/addons/mediasources/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.mediasources.dcop.DcopMediaSourcePlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Greboid <greg@dmdirc.com>
5
+description=Provides DCOP media sources for the now playing plugin
6
+name=dcopmediasource
7
+nicename=DCOP Media Sources
8
+minversion=0

+ 5
- 26
src/com/dmdirc/addons/nickcolours/NickColourPlugin.java View File

@@ -217,17 +217,16 @@ public final class NickColourPlugin extends Plugin implements EventPlugin, Prefe
217 217
     }
218 218
     
219 219
     /** {@inheritDoc} */
220
-    public boolean onLoad() {
221
-        return true;
222
-    }
223
-    
224
-    /** {@inheritDoc} */
225
-    public void onActivate() {
220
+    public void onLoad() {
226 221
         if (IdentityManager.getGlobalConfig().hasOption(DOMAIN, "randomcolours")) {
227 222
             randColours =(String[]) IdentityManager.getGlobalConfig().getOptionList(DOMAIN, "randomcolours").toArray();
228 223
         }
229 224
     }
230 225
     
226
+    /** {@inheritDoc} */
227
+    public void onUnload() {
228
+    }
229
+    
231 230
     /** {@inheritDoc} */
232 231
     public boolean isConfigurable() {
233 232
         return true;
@@ -301,24 +300,4 @@ public final class NickColourPlugin extends Plugin implements EventPlugin, Prefe
301 300
         // Do nothing
302 301
     }
303 302
     
304
-    /** {@inheritDoc} */
305
-    public String getVersion() {
306
-        return "0.5";
307
-    }
308
-    
309
-    /** {@inheritDoc} */
310
-    public String getAuthor() {
311
-        return "Chris <chris@dmdirc.com>";
312
-    }
313
-    
314
-    /** {@inheritDoc} */
315
-    public String getDescription() {
316
-        return "Provides various nick colouring tools";
317
-    }
318
-    
319
-    /** {@inheritDoc} */
320
-    public String toString() {
321
-        return "Nick Colour Plugin";
322
-    }
323
-    
324 303
 }

+ 8
- 0
src/com/dmdirc/addons/nickcolours/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.nickcolours.NickColourPlugin
2
+version=6
3
+friendlyversion=0.6
4
+author=Chris <chris@dmdirc.com>
5
+description=Provides various nick colouring tools
6
+name=nickcolour
7
+nicename=Nick Colour Plugin
8
+minversion=0

+ 10
- 0
src/com/dmdirc/addons/nowplaying/plugin.info View File

@@ -0,0 +1,10 @@
1
+mainclass=com.dmdirc.addons.nowplaying.plugin.NowPlayingPlugin
2
+version=3
3
+friendlyversion=0.3
4
+author=Chris <chris@dmdirc.com>
5
+description=Adds a nowplaying command
6
+name=nowplaying
7
+nicename=Now Playing Command
8
+minversion=0
9
+persistant-com.dmdirc.addons.nowplaying.MediaSource=true
10
+persistant-com.dmdirc.addons.nowplaying.MediaSourceManager=true

+ 23
- 47
src/com/dmdirc/addons/nowplaying/plugin/NowPlayingPlugin.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.commandparser.CommandManager;
31 31
 import com.dmdirc.config.IdentityManager;
32 32
 import com.dmdirc.plugins.EventPlugin;
33 33
 import com.dmdirc.plugins.Plugin;
34
+import com.dmdirc.plugins.PluginInfo;
34 35
 import com.dmdirc.plugins.PluginManager;
35 36
 import com.dmdirc.ui.interfaces.PreferencesInterface;
36 37
 import com.dmdirc.ui.interfaces.PreferencesPanel;
@@ -63,19 +64,13 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
63 64
     }
64 65
     
65 66
     /** {@inheritDoc} */
66
-    public boolean onLoad() {
67
-        return true;
68
-    }
69
-    
70
-    /** {@inheritDoc} */
71
-    @Override
72
-    protected void onActivate() {
67
+    public void onLoad() {
73 68
         sources.clear();
74 69
         
75 70
         loadSettings();
76 71
         
77
-        for (Plugin target : PluginManager.getPluginManager().getPlugins()) {
78
-            if (target.isActive()) {
72
+        for (PluginInfo target : PluginManager.getPluginManager().getPluginInfos()) {
73
+            if (target.isLoaded()) {
79 74
                 addPlugin(target);
80 75
             }
81 76
         }
@@ -84,33 +79,12 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
84 79
     }
85 80
     
86 81
     /** {@inheritDoc} */
87
-    @Override
88
-    protected void onDeactivate() {
82
+    public void onUnload() {
89 83
         sources.clear();
90 84
         
91 85
         CommandManager.unregisterCommand(command);
92 86
     }
93 87
     
94
-    /** {@inheritDoc} */
95
-    public String getVersion() {
96
-        return "0.2";
97
-    }
98
-    
99
-    /** {@inheritDoc} */
100
-    public String getAuthor() {
101
-        return "Chris <chris@dmdirc.com>";
102
-    }
103
-    
104
-    /** {@inheritDoc} */
105
-    public String getDescription() {
106
-        return "Adds a nowplaying command";
107
-    }
108
-    
109
-    /** {@inheritDoc} */
110
-    public String toString() {
111
-        return "Now playing command";
112
-    }
113
-    
114 88
     /** {@inheritDoc} */
115 89
     public boolean isConfigurable() {
116 90
         return true;
@@ -158,10 +132,10 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
158 132
     /** {@inheritDoc} */
159 133
     public void processEvent(final ActionType type, final StringBuffer format,
160 134
             final Object... arguments) {
161
-        if (type == CoreActionType.PLUGIN_ACTIVATED) {
162
-            addPlugin((Plugin) arguments[0]);
163
-        } else if (type == CoreActionType.PLUGIN_DEACTIVATED) {
164
-            removePlugin((Plugin) arguments[0]);
135
+        if (type == CoreActionType.PLUGIN_LOADED) {
136
+            addPlugin((PluginInfo) arguments[0]);
137
+        } else if (type == CoreActionType.PLUGIN_UNLOADED) {
138
+            removePlugin((PluginInfo) arguments[0]);
165 139
         }
166 140
     }
167 141
     
@@ -171,16 +145,17 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
171 145
      *
172 146
      * @param target The plugin to be tested
173 147
      */
174
-    private void addPlugin(final Plugin target) {
175
-        if (target instanceof MediaSource) {
176
-            sources.add((MediaSource) target);
177
-            addSourceToOrder((MediaSource) target);
148
+    private void addPlugin(final PluginInfo target) {
149
+        final Plugin targetPlugin = target.getPlugin();
150
+        if (targetPlugin instanceof MediaSource) {
151
+            sources.add((MediaSource) targetPlugin);
152
+            addSourceToOrder((MediaSource) targetPlugin);
178 153
         }
179 154
         
180
-        if (target instanceof MediaSourceManager) {
181
-            sources.addAll(((MediaSourceManager) target).getSources());
155
+        if (targetPlugin instanceof MediaSourceManager) {
156
+            sources.addAll(((MediaSourceManager) targetPlugin).getSources());
182 157
             
183
-            for (MediaSource source : ((MediaSourceManager) target).getSources()) {
158
+            for (MediaSource source : ((MediaSourceManager) targetPlugin).getSources()) {
184 159
                 addSourceToOrder(source);
185 160
             }
186 161
         }
@@ -204,13 +179,14 @@ public class NowPlayingPlugin extends Plugin implements EventPlugin,
204 179
      *
205 180
      * @param target The plugin to be tested
206 181
      */
207
-    private void removePlugin(final Plugin target) {
208
-        if (target instanceof MediaSource) {
209
-            sources.remove(target);
182
+    private void removePlugin(final PluginInfo target) {
183
+        final Plugin targetPlugin = target.getPlugin();
184
+        if (targetPlugin instanceof MediaSource) {
185
+            sources.remove(targetPlugin);
210 186
         }
211 187
         
212
-        if (target instanceof MediaSourceManager) {
213
-            sources.removeAll(((MediaSourceManager) target).getSources());
188
+        if (targetPlugin instanceof MediaSourceManager) {
189
+            sources.removeAll(((MediaSourceManager) targetPlugin).getSources());
214 190
         }
215 191
     }
216 192
     

+ 2
- 24
src/com/dmdirc/addons/osdplugin/OsdPlugin.java View File

@@ -71,32 +71,15 @@ public final class OsdPlugin extends Plugin implements PreferencesInterface {
71 71
     }
72 72
     
73 73
     /** {@inheritDoc}. */
74
-    public boolean onLoad() {
74
+    public void onLoad() {
75 75
         command = new OsdCommand();
76
-        
77
-        return true;
78 76
     }
79 77
     
80 78
     /** {@inheritDoc}. */
81 79
     public void onUnload() {
82 80
         CommandManager.unregisterCommand(command);
83 81
     }
84
-    
85
-    /** {@inheritDoc}. */
86
-    public String getVersion() {
87
-        return "0.1";
88
-    }
89
-    
90
-    /** {@inheritDoc}. */
91
-    public String getAuthor() {
92
-        return "Chris <chris@dmdirc.com>";
93
-    }
94
-    
95
-    /** {@inheritDoc}. */
96
-    public String getDescription() {
97
-        return "Provides command to show on screen display";
98
-    }
99
-    
82
+
100 83
     /** {@inheritDoc}. */
101 84
     public boolean isConfigurable() {
102 85
         return true;
@@ -176,9 +159,4 @@ public final class OsdPlugin extends Plugin implements PreferencesInterface {
176 159
     public void configCancelled() {
177 160
         osdWindow.dispose();
178 161
     }
179
-    
180
-    /** {@inheritDoc}. */
181
-    public String toString() {
182
-        return "OSD Plugin";
183
-    }
184 162
 }

+ 8
- 0
src/com/dmdirc/addons/osdplugin/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.osdplugin.OsdPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Chris <chris@dmdirc.com>
5
+description=Provides command to show on screen display
6
+name=osd
7
+nicename=OSD Plugin
8
+minversion=0

+ 2
- 26
src/com/dmdirc/addons/redirectplugin/RedirectPlugin.java View File

@@ -44,37 +44,13 @@ public final class RedirectPlugin extends Plugin {
44 44
     }
45 45
     
46 46
     /** {@inheritDoc} */
47
-    public boolean onLoad() {
48
-        return true;
49
-    }
50
-    
51
-    /** {@inheritDoc} */
52
-    public void onActivate() {
47
+    public void onLoad() {
53 48
         CommandManager.registerCommand(command);
54 49
     }
55 50
     
56 51
     /** {@inheritDoc}. */
57
-    public void onDeactivate() {
52
+    public void onUnload() {
58 53
         CommandManager.unregisterCommand(command);
59 54
     }
60 55
     
61
-    /** {@inheritDoc} */
62
-    public String getVersion() {
63
-        return "0.1";
64
-    }
65
-    
66
-    /** {@inheritDoc} */
67
-    public String getAuthor() {
68
-        return "Chris <chris@dmdirc.com>";
69
-    }
70
-    
71
-    /** {@inheritDoc} */
72
-    public String getDescription() {
73
-        return "Adds commands to redirect command output to channels";
74
-    }
75
-    
76
-    /** {@inheritDoc}. */
77
-    public String toString() {
78
-        return "Redirect Plugin";
79
-    }
80 56
 }

+ 8
- 0
src/com/dmdirc/addons/redirectplugin/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.redirectplugin.RedirectPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Chris <chris@dmdirc.com>
5
+description=Adds commands to redirect command output to channels
6
+name=redirect
7
+nicename=Redirect Plugin
8
+minversion=0

+ 4
- 26
src/com/dmdirc/addons/systray/SystrayPlugin.java View File

@@ -83,9 +83,7 @@ public final class SystrayPlugin extends Plugin implements ActionListener,
83 83
      * @param type The type of notification
84 84
      */
85 85
     public void notify(final String title, final String message, final TrayIcon.MessageType type) {
86
-        if (isActive()) {
87
-            icon.displayMessage(title, Styliser.stipControlCodes(message), type);
88
-        }
86
+        icon.displayMessage(title, Styliser.stipControlCodes(message), type);
89 87
     }
90 88
     
91 89
     /**
@@ -107,12 +105,12 @@ public final class SystrayPlugin extends Plugin implements ActionListener,
107 105
     }
108 106
     
109 107
     /** {@inheritDoc} */
110
-    public boolean onLoad() {
108
+    public boolean checkPrerequisites() {
111 109
         return SystemTray.isSupported();
112 110
     }
113 111
     
114 112
     /** {@inheritDoc} */
115
-    public void onActivate() {
113
+    public void onLoad() {
116 114
         try {
117 115
             SystemTray.getSystemTray().add(icon);
118 116
             command = new PopupCommand(this);
@@ -122,31 +120,11 @@ public final class SystrayPlugin extends Plugin implements ActionListener,
122 120
     }
123 121
     
124 122
     /** {@inheritDoc}. */
125
-    public void onDeactivate() {
123
+    public void onUnload() {
126 124
         SystemTray.getSystemTray().remove(icon);
127 125
         command.unregister();
128 126
     }
129 127
     
130
-    /** {@inheritDoc} */
131
-    public String getVersion() {
132
-        return "0.1";
133
-    }
134
-    
135
-    /** {@inheritDoc} */
136
-    public String getAuthor() {
137
-        return "Chris <chris@dmdirc.com>";
138
-    }
139
-    
140
-    /** {@inheritDoc} */
141
-    public String getDescription() {
142
-        return "Adds a system tray icon";
143
-    }
144
-    
145
-    /** {@inheritDoc}. */
146
-    public String toString() {
147
-        return "Systray Plugin";
148
-    }
149
-    
150 128
     /** {@inheritDoc} */
151 129
     public void mouseClicked(final MouseEvent e) {
152 130
         if (e.getButton() == MouseEvent.BUTTON1) {

+ 8
- 0
src/com/dmdirc/addons/systray/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.systray.SystrayPlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Chris <chris@dmdirc.com>
5
+description=Adds a system tray icon
6
+name=systram
7
+nicename=Systray Plugin
8
+minversion=0

+ 3
- 28
src/com/dmdirc/addons/timeplugin/TimePlugin.java View File

@@ -51,17 +51,12 @@ public final class TimePlugin  extends Plugin {
51 51
     }
52 52
     
53 53
     /** {@inheritDoc} */
54
-    public boolean onLoad() {
54
+    public void onLoad() {
55 55
         if (!registered) {
56 56
             ActionManager.registerActionTypes(TimeActionType.values());
57 57
             registered = true;
58 58
         }
59
-        
60
-        return true;
61
-    }
62
-    
63
-    /** {@inheritDoc} */
64
-    public void onActivate() {
59
+
65 60
         final int offset = 60 - Calendar.getInstance().get(Calendar.SECOND);
66 61
         
67 62
         timer = new Timer("Time plugin timer");
@@ -92,30 +87,10 @@ public final class TimePlugin  extends Plugin {
92 87
     
93 88
     
94 89
     /** {@inheritDoc} */
95
-    public void onDeactivate() {
90
+    public void onUnload() {
96 91
         timer.cancel();
97 92
         timer = null;
98 93
         
99 94
         CommandManager.unregisterCommand(command);
100 95
     }
101
-    
102
-    /** {@inheritDoc} */
103
-    public String getVersion() {
104
-        return "0.1";
105
-    }
106
-    
107
-    /** {@inheritDoc} */
108
-    public String getAuthor() {
109
-        return "Chris <chris@dmdirc.com>";
110
-    }
111
-    
112
-    /** {@inheritDoc} */
113
-    public String getDescription() {
114
-        return "Provides time-related actions and commands";
115
-    }
116
-    
117
-    /** {@inheritDoc} */
118
-    public String toString() {
119
-        return "Time Plugin";
120
-    }
121 96
 }

+ 10
- 0
src/com/dmdirc/addons/timeplugin/plugin.info View File

@@ -0,0 +1,10 @@
1
+mainclass=com.dmdirc.addons.timeplugin.TimePlugin
2
+version=2
3
+friendlyversion=0.2
4
+author=Chris <chris@dmdirc.com>
5
+description=Provides time-based actions and commands
6
+name=timeplugin
7
+nicename=Time Plugin
8
+minversion=0
9
+persistant-com.dmdirc.addons.timeplugin.TimeActionMetaType=true
10
+persistant-com.dmdirc.addons.timeplugin.TimeActionType=true

+ 3
- 40
src/com/dmdirc/addons/windowstatus/WindowStatusPlugin.java View File

@@ -76,10 +76,8 @@ public final class WindowStatusPlugin extends Plugin implements EventPlugin, Pre
76 76
 	
77 77
 	/**
78 78
 	 * Called when the plugin is loaded.
79
-	 *
80
-	 * @return false if the plugin can not be loaded
81 79
 	 */
82
-	public boolean onLoad() {
80
+	public void onLoad() {
83 81
 		// Set defaults
84 82
 		Properties defaults = new Properties();
85 83
 		defaults.setProperty(MY_DOMAIN + ".channel.shownone", "true");
@@ -88,52 +86,17 @@ public final class WindowStatusPlugin extends Plugin implements EventPlugin, Pre
88 86
 		defaults.setProperty("identity.name", "WindowStatus Plugin Defaults");
89 87
 		IdentityManager.addIdentity(new Identity(defaults));
90 88
 		
91
-		return true;
92
-	}
93
-	
94
-	/**
95
-	 * Called when this plugin is Activated.
96
-	 */
97
-	public void onActivate() {
98 89
 		Main.getUI().getStatusBar().addComponent(panel);
99 90
 		updateStatus();
100 91
 	}
101 92
 	
102 93
 	/**
103
-	 * Called when this plugin is deactivated.
94
+	 * Called when this plugin is unloaded.
104 95
 	 */
105
-	public void onDeactivate() {
96
+	public void onUnload() {
106 97
 		Main.getUI().getStatusBar().removeComponent(panel);
107 98
 	}
108 99
 	
109
-	/**
110
-	 * Get the plugin version.
111
-	 *
112
-	 * @return Plugin Version
113
-	 */
114
-	public String getVersion() { return "0.4"; }
115
-	
116
-	/**
117
-	 * Get the plugin Author.
118
-	 *
119
-	 * @return Author of plugin
120
-	 */
121
-	public String getAuthor() { return "Shane <shane@dmdirc.com>"; }
122
-	
123
-	/**
124
-	 * Get the plugin Description.
125
-	 *
126
-	 * @return Description of plugin
127
-	 */
128
-	public String getDescription() { return "Displays information related to the current window in the status bar."; }
129
-	
130
-	/**
131
-	 * Get the name of the plugin (used in "Manage Plugins" dialog).
132
-	 *
133
-	 * @return Name of plugin
134
-	 */
135
-	public String toString() { return "WindowStatus Plugin"; }
136
-	
137 100
 	/**
138 101
 	 * Process an event of the specified type.
139 102
 	 *

+ 8
- 0
src/com/dmdirc/addons/windowstatus/plugin.info View File

@@ -0,0 +1,8 @@
1
+mainclass=com.dmdirc.addons.windowstatus.WindowStatusPlugin
2
+version=5
3
+friendlyversion=0.5
4
+author=Shane <shane@dmdirc.com>
5
+description=Displays information related to the current window in the status bar.
6
+name=windowstatus
7
+nicename=WindowStatus Plugin
8
+minversion=0

+ 6
- 5
src/com/dmdirc/commandparser/commands/global/Ifplugin.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.commandparser.commands.GlobalCommand;
27 27
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
29 29
 import com.dmdirc.plugins.Plugin;
30
+import com.dmdirc.plugins.PluginInfo;
30 31
 import com.dmdirc.plugins.PluginManager;
31 32
 import com.dmdirc.ui.input.AdditionalTabTargets;
32 33
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -62,11 +63,11 @@ public final class Ifplugin extends GlobalCommand implements IntelligentCommand
62 63
         
63 64
         final String pname = args[0].substring(negative ? 1 : 0);
64 65
         
65
-        final Plugin plugin = PluginManager.getPluginManager().getPlugin(pname);
66
+        final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName(pname);
66 67
         
67 68
         boolean result = true;
68 69
         
69
-        if (plugin == null || !plugin.isActive()) {
70
+        if (pluginInfo == null || !pluginInfo.isLoaded()) {
70 71
             result = false;
71 72
         }
72 73
         
@@ -111,9 +112,9 @@ public final class Ifplugin extends GlobalCommand implements IntelligentCommand
111 112
         if (arg == 0) {
112 113
             res.setIncludeNormal(false);
113 114
 
114
-            for (Plugin possPlugin : PluginManager.getPluginManager().getPossiblePlugins()) {
115
-                res.add(possPlugin.getClass().getCanonicalName());
116
-                res.add("!" + possPlugin.getClass().getCanonicalName());
115
+            for (PluginInfo possPlugin : PluginManager.getPluginManager().getPossiblePluginInfos()) {
116
+                res.add(possPlugin.getName());
117
+                res.add("!" + possPlugin.getName());
117 118
             }            
118 119
         }
119 120
         

+ 4
- 3
src/com/dmdirc/commandparser/commands/global/LoadPlugin.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.commandparser.CommandManager;
26 26
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 28
 import com.dmdirc.plugins.Plugin;
29
+import com.dmdirc.plugins.PluginInfo;
29 30
 import com.dmdirc.plugins.PluginManager;
30 31
 import com.dmdirc.ui.input.AdditionalTabTargets;
31 32
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -51,7 +52,7 @@ public final class LoadPlugin extends GlobalCommand implements IntelligentComman
51 52
     public void execute(final InputWindow origin, final boolean isSilent,
52 53
             final String... args) {
53 54
         if (PluginManager.getPluginManager().addPlugin(args[0])) {
54
-            PluginManager.getPluginManager().getPlugin(args[0]).setActive(true);
55
+            PluginManager.getPluginManager().getPluginInfo(args[0]).loadPlugin();
55 56
             sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin loaded.");
56 57
         } else {
57 58
             sendLine(origin, isSilent, FORMAT_ERROR, "Plugin Loading failed");
@@ -91,8 +92,8 @@ public final class LoadPlugin extends GlobalCommand implements IntelligentComman
91 92
         if (arg == 0) {
92 93
             res.setIncludeNormal(false);
93 94
             
94
-            for (Plugin possPlugin : PluginManager.getPluginManager().getPossiblePlugins()) {
95
-                res.add(possPlugin.getClass().getCanonicalName());
95
+            for (PluginInfo possPlugin : PluginManager.getPluginManager().getPossiblePluginInfos()) {
96
+                res.add(possPlugin.getFilename());
96 97
             }
97 98
         }
98 99
         

+ 5
- 7
src/com/dmdirc/commandparser/commands/global/ReloadPlugin.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.commandparser.CommandManager;
26 26
 import com.dmdirc.commandparser.commands.GlobalCommand;
27 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 28
 import com.dmdirc.plugins.Plugin;
29
+import com.dmdirc.plugins.PluginInfo;
29 30
 import com.dmdirc.plugins.PluginManager;
30 31
 import com.dmdirc.ui.input.AdditionalTabTargets;
31 32
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -49,15 +50,12 @@ public final class ReloadPlugin extends GlobalCommand implements IntelligentComm
49 50
     /** {@inheritDoc} */
50 51
     public void execute(final InputWindow origin, final boolean isSilent,
51 52
             final String... args) {
52
-        Plugin plugin = PluginManager.getPluginManager().getPlugin(args[0]);
53
+        PluginInfo plugin = PluginManager.getPluginManager().getPluginInfoByName(args[0]);
53 54
         if (plugin == null) {
54 55
             sendLine(origin, isSilent, FORMAT_ERROR, "Plugin Reloading failed - Plugin not loaded");
55 56
         } else {
56
-            final boolean isActive = plugin.isActive();
57
-            plugin = null;
58
-            if (PluginManager.getPluginManager().reloadPlugin(args[0])) {
57
+            if (PluginManager.getPluginManager().reloadPlugin(plugin.getFilename())) {
59 58
                 sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin Reloaded.");
60
-                PluginManager.getPluginManager().getPlugin(args[0]).setActive(isActive);
61 59
             } else {
62 60
                 sendLine(origin, isSilent, FORMAT_ERROR, "Plugin Reloading failed");
63 61
             }
@@ -97,8 +95,8 @@ public final class ReloadPlugin extends GlobalCommand implements IntelligentComm
97 95
         if (arg == 0) {
98 96
             res.setIncludeNormal(false);
99 97
             
100
-            for (Plugin possPlugin : PluginManager.getPluginManager().getPlugins()) {
101
-                res.add(possPlugin.getClass().getCanonicalName());
98
+            for (PluginInfo possPlugin : PluginManager.getPluginManager().getPossiblePluginInfos()) {
99
+                res.add(possPlugin.getName());
102 100
             }
103 101
         }
104 102
         

+ 7
- 66
src/com/dmdirc/plugins/Plugin.java View File

@@ -40,52 +40,21 @@ public abstract class Plugin implements Comparable<Plugin> {
40 40
 
41 41
 	/**
42 42
 	 * Called when the plugin is loaded.
43
-	 *
44
-	 * @return false if the plugin can not be loaded
45 43
 	 */
46
-	public abstract boolean onLoad();
44
+	public abstract void onLoad();
47 45
 	
48 46
 	/**
49
-	 * Called when the plugin is about to be unloaded.
50
-	 */
51
-	public void onUnload() { }
52
-
53
-	/**
54
-	 * Change the active state of this plugin.
55
-	 * (Non-Active Plugins will not recieve Events)
47
+	 * Check any further Prerequisites for this plugin to load that can not be
48
+	 * checked using metainfo.
56 49
 	 *
57
-	 * @param newState True if activating, else False.
50
+	 * @return true if the plugin can be used, else false.
58 51
 	 */
59
-	public final void setActive(boolean newState) {
60
-		if (isActive != newState) {
61
-			isActive = newState;
62
-			if (isActive) {
63
-				ActionManager.processEvent(CoreActionType.PLUGIN_ACTIVATED, null, this);
64
-				onActivate();
65
-			} else {
66
-				ActionManager.processEvent(CoreActionType.PLUGIN_DEACTIVATED, null, this);
67
-				onDeactivate();
68
-			}
69
-		}
70
-	}
52
+	public boolean checkPrerequisites() { return true; }
71 53
 	
72 54
 	/**
73
-	 * Check to see if a plugin is active.
74
-	 * (Non-Active Plugins will not recieve Events)
75
-	 *
76
-	 * @return True if active, else False.
77
-	 */
78
-	public final boolean isActive() { return isActive; }
79
-	
80
-	/**
81
-	 * Called when this plugin becomes active.
82
-	 */
83
-	protected void onActivate() { }
84
-	
85
-	/**
86
-	 * Called when this plugin is deactivated.
55
+	 * Called when the plugin is about to be unloaded.
87 56
 	 */
88
-	protected void onDeactivate() { }
57
+	public abstract void onUnload();
89 58
 	
90 59
 	/**
91 60
 	 * Called to see if the plugin has configuration options (via dialog).
@@ -99,34 +68,6 @@ public abstract class Plugin implements Comparable<Plugin> {
99 68
 	 */
100 69
 	public void showConfig() { }
101 70
 	
102
-	/**
103
-	 * Get the plugin version
104
-	 *
105
-	 * @return Plugin Version
106
-	 */
107
-	public abstract String getVersion();
108
-	
109
-	/**
110
-	 * Get the plugin Author.
111
-	 *
112
-	 * @return Author of plugin
113
-	 */
114
-	public abstract String getAuthor();
115
-	
116
-	/**
117
-	 * Get the plugin Description.
118
-	 *
119
-	 * @return Description of plugin
120
-	 */
121
-	public abstract String getDescription();
122
-	
123
-	/**
124
-	 * Get the name of the plugin (used in "Manage Plugins" dialog).
125
-	 *
126
-	 * @return Name of plugin
127
-	 */
128
-	public abstract String toString();
129
-
130 71
 	/**
131 72
 	 * Compares this object with the specified object for order.
132 73
 	 * Returns a negative integer, zero, or a positive integer as per String.compareTo();

+ 28
- 40
src/com/dmdirc/plugins/PluginClassLoader.java View File

@@ -23,25 +23,22 @@
23 23
  */
24 24
 package com.dmdirc.plugins;
25 25
 
26
-import java.io.FileInputStream;
27
-import java.io.DataInputStream;
28
-import java.io.File;
26
+import com.dmdirc.util.resourcemanager.ResourceManager;
27
+
29 28
 import java.io.IOException;
30 29
 
31 30
 public class PluginClassLoader extends ClassLoader {
32
-	/** Directory where plugins are stored. */
33
-	String myDir;
34
-	
35
-	/** Name of the package I am loading. */
36
-	String myPackage = "";
31
+	/** The plugin Info object for the plugin we are loading */
32
+	final PluginInfo pluginInfo;
37 33
 	
38 34
 	/**
39 35
 	 * Create a new PluginClassLoader.
40 36
 	 *
41 37
 	 * @param directory Directory where plugins are stored.
42 38
 	 */
43
-	public PluginClassLoader(String directory) {
44
-		myDir = directory;
39
+	public PluginClassLoader(final PluginInfo info) {
40
+		super();
41
+		pluginInfo = info;
45 42
 	}
46 43
 	
47 44
 	/**
@@ -52,28 +49,36 @@ public class PluginClassLoader extends ClassLoader {
52 49
 	 * @throws ClassNotFoundException if the class to be loaded could not be found.
53 50
 	 */
54 51
 	public Class< ? > loadClass(final String name) throws ClassNotFoundException {
52
+		ResourceManager res;
53
+		try {
54
+			res = pluginInfo.getResourceManager();
55
+		} catch (IOException ioe) {
56
+			throw new ClassNotFoundException("Error with resourcemanager", ioe);
57
+		}
58
+	
55 59
 		Class< ? > loadedClass = null;
56 60
 
57
-		// Check to make sure we only load things in our own package!
61
+		final String fileName = name.replace('.', '/')+".class";
58 62
 		try {
59
-			if (myPackage.isEmpty()) {
60
-				int i = name.lastIndexOf('.');
61
-				if (i != -1) { myPackage = name.substring(0, i); }
62
-				else { return getParent().loadClass(name); }
63
+			if (pluginInfo.isPersistant(name) || !res.resourceExists(fileName)) {
64
+				return getParent().loadClass(name);
63 65
 			}
64
-			if (!name.startsWith(myPackage)) { return getParent().loadClass(name); }
65 66
 		} catch (NoClassDefFoundError e) {
66
-			throw new ClassNotFoundException("Error loading '"+name+"' (wanted by '"+myPackage+"' in '"+myDir+"') -> "+e.getMessage(), e);
67
+			throw new ClassNotFoundException("Error loading '"+name+"' (wanted by "+pluginInfo.getName()+") -> "+e.getMessage(), e);
67 68
 		}
68 69
 		
70
+		
71
+		// Don't duplicate a class
72
+		Class existing = findLoadedClass(name);
73
+		if (existing != null) { return existing; }
74
+		
69 75
 		// We are ment to be loading this one!
70
-		final String fileName = myDir + File.separator + name.replace(myDir+".", "").replace('.', File.separatorChar) + ".class";
71 76
 		byte[] data = null;
72
-
73
-		try {
74
-			data = loadClassData(fileName);
75
-		} catch (IOException e) {
76
-			throw new ClassNotFoundException(e.getMessage());
77
+		
78
+		if (res.resourceExists(fileName)) {
79
+			data = res.getResourceBytes(fileName);
80
+		} else {
81
+			throw new ClassNotFoundException("Resource '"+name+"' (wanted by "+pluginInfo.getName()+") does not exist.");
77 82
 		}
78 83
 		
79 84
 		try {
@@ -90,21 +95,4 @@ public class PluginClassLoader extends ClassLoader {
90 95
 		
91 96
 		return loadedClass;
92 97
 	}
93
-	
94
-	/**
95
-	 * Load the class from the .class file
96
-	 *
97
-	 * @param filename Filename to load from
98
-	 * @throws IOException when the file doesn't exist or can't be read
99
- 	 */
100
-	public byte[] loadClassData(String filename) throws IOException {
101
-		final File file = new File(filename);
102
-		final byte[] fileBuffer = new byte[(int)file.length()];
103
-		final DataInputStream fileInput = new DataInputStream(new FileInputStream(file));
104
-		
105
-		fileInput.readFully(fileBuffer);
106
-		fileInput.close();
107
-		
108
-		return fileBuffer;
109
-	}
110 98
 }

+ 62
- 0
src/com/dmdirc/plugins/PluginException.java View File

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id: PluginException.java 2022 2007-09-12 00:35:14Z ShaneMcC $
23
+ */
24
+
25
+package com.dmdirc.plugins;
26
+
27
+/**
28
+ * Plugin Exception.
29
+ *
30
+ * @author            Shane Mc Cormack
31
+ * @version           $Id: PluginException.java 2022 2007-09-12 00:35:14Z ShaneMcC $
32
+ */
33
+public class PluginException extends Exception {
34
+	/**
35
+	 * A version number for this class. It should be changed whenever the class
36
+	 * structure is changed (or anything else that would prevent serialized
37
+	 * objects being unserialized with the new class).
38
+	 */
39
+	private static final long serialVersionUID = 1;
40
+	
41
+	/**
42
+	 * Create a new PluginException Exception.
43
+	 *
44
+	 * @param message Reason for exception
45
+	 */
46
+	public PluginException(final String message) { super(message); }
47
+	
48
+	/**
49
+	 * Create a new PluginException Exception.
50
+	 *
51
+	 * @param message Reason for exception
52
+	 * @param cause Cause of Exception
53
+	 */
54
+	public PluginException(final String message, final Throwable cause) { super(message, cause); }
55
+	
56
+	/**
57
+	 * Get SVN Version information.
58
+	 *
59
+	 * @return SVN Version String
60
+	 */
61
+	public static String getSvnInfo() { return "$Id: PluginException.java 2022 2007-09-12 00:35:14Z ShaneMcC $"; }	
62
+}

+ 370
- 0
src/com/dmdirc/plugins/PluginInfo.java View File

@@ -0,0 +1,370 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ *
22
+ * SVN: $Id$
23
+ */
24
+package com.dmdirc.plugins;
25
+
26
+import com.dmdirc.actions.ActionManager;
27
+import com.dmdirc.actions.ActionType;
28
+import com.dmdirc.actions.CoreActionType;
29
+import com.dmdirc.util.resourcemanager.ResourceManager;
30
+import com.dmdirc.logger.Logger;
31
+import com.dmdirc.logger.ErrorLevel;
32
+
33
+import java.io.IOException;
34
+import java.lang.reflect.Constructor;
35
+import java.lang.reflect.InvocationTargetException;
36
+import java.util.Properties;
37
+
38
+public class PluginInfo implements Comparable<PluginInfo> {
39
+	/** Plugin Meta Data */
40
+	private Properties metaData = new Properties();
41
+	/** File that this plugin was loaded from */
42
+	private final String filename;
43
+	/** The actual Plugin from this jar */
44
+	private Plugin plugin = null;
45
+	/** The classloader used for this Plugin */
46
+	private PluginClassLoader classloader = null;
47
+	/** The resource manager used by this pluginInfo */
48
+	private ResourceManager myResourceManager = null;
49
+	
50
+	/**
51
+	 * Create a new PluginInfo.
52
+	 *
53
+	 * @param filename File that this plugin is stored in.
54
+	 * @throws PluginException if there is an error loading the Plugin
55
+	 */
56
+	public PluginInfo(final String filename) throws PluginException {
57
+		this.filename = filename;
58
+		
59
+		ResourceManager res;
60
+		try {
61
+			res = getResourceManager();
62
+		} catch (IOException ioe) {
63
+			throw new PluginException("Plugin "+filename+" failed to load, error with resourcemanager", ioe);
64
+		}
65
+		
66
+		try {
67
+			if (res.resourceExists("META-INF/plugin.info")) {
68
+				metaData.load(res.getResourceInputStream("META-INF/plugin.info"));
69
+			} else {
70
+				throw new PluginException("Plugin "+filename+" failed to load, plugin.info doesn't exist in jar");
71
+			}
72
+		} catch (Exception e) {
73
+			throw new PluginException("Plugin "+filename+" failed to load, plugin.info failed to open - "+e.getMessage(), e);
74
+		}
75
+		
76
+		if (getVersion() < 0) {
77
+			throw new PluginException("Plugin "+filename+" failed to load, incomplete plugin.info (Missing or invalid 'version')");
78
+		} else if(getAuthor().equals("")) {
79
+			throw new PluginException("Plugin "+filename+" failed to load, incomplete plugin.info (Missing 'author')");
80
+		} else if(getName().equals("")) {
81
+			throw new PluginException("Plugin "+filename+" failed to load, incomplete plugin.info (Missing 'name')");
82
+		} else if(getMinVersion().equals("")) {
83
+			throw new PluginException("Plugin "+filename+" failed to load, incomplete plugin.info (Missing 'minversion')");
84
+		} else if(getMainClass().equals("")) {
85
+			throw new PluginException("Plugin "+filename+" failed to load, incomplete plugin.info (Missing 'mainclass')");
86
+		}
87
+		
88
+		final String mainClass = getMainClass().replace('.', '/')+".class";
89
+		if (!res.resourceExists(mainClass)) {
90
+			throw new PluginException("Plugin "+filename+" failed to load, main class file ("+mainClass+") not found in jar.");
91
+		}
92
+		
93
+		if (isPersistant()) { loadEntirePlugin(); }
94
+		
95
+		myResourceManager = null;
96
+	}
97
+
98
+	/**
99
+	 * Get the resource manager for this plugin
100
+	 *
101
+	 * @throws IOException if there is any problem getting a ResourceManager for this plugin
102
+	 */
103
+	protected synchronized ResourceManager getResourceManager() throws IOException {
104
+		if (myResourceManager == null) {
105
+			final String directory = PluginManager.getPluginManager().getDirectory();
106
+			myResourceManager = ResourceManager.getResourceManager("jar://"+directory+filename);
107
+		}
108
+		return myResourceManager;
109
+	}
110
+	
111
+	/**
112
+	 * Are the requirements for this plugin met?
113
+	 *
114
+	 * @throws PluginException if requirements to load plugin are not met.
115
+	 */
116
+	public void checkRequirements() throws PluginException {
117
+		// This needs to parse getMetaInfo("requirements"); when I decide on the
118
+		// syntax.
119
+		// Also needs to check min/max version.
120
+	}
121
+	
122
+	/**
123
+	 * Is this plugin loaded?
124
+	 */
125
+	public boolean isLoaded() {
126
+		return (plugin != null);
127
+	}
128
+	
129
+	/**
130
+	 * Load entire plugin.
131
+	 * This loads all files in the jar immediately.
132
+	 *
133
+	 * @throws PluginException if there is an error with the resourcemanager
134
+	 */
135
+	private void loadEntirePlugin() throws PluginException {
136
+		// Load the main "Plugin" from the jar
137
+		loadPlugin();
138
+
139
+		// Now load all the rest.
140
+		try {
141
+			ResourceManager res = getResourceManager();
142
+			
143
+			for (final String filename : res.getResourcesStartingWith("")) {
144
+				String classname = filename.replace('.', '/');
145
+				if (classname.matches("^.*\\.class$")) {
146
+					classname = classname.replaceAll("\\.class$", "");
147
+					loadClass(classname);
148
+				}
149
+			}
150
+			
151
+		} catch (IOException ioe) {
152
+			throw new PluginException("Plugin "+filename+" failed to load, error with resourcemanager", ioe);
153
+		}
154
+		myResourceManager = null;
155
+	}
156
+	
157
+	/**
158
+	 * Load the plugin files.
159
+	 */
160
+	public void loadPlugin() {
161
+		if (isLoaded()) {
162
+			Logger.userError(ErrorLevel.LOW, "Tried to load Plugin that was already loaded.");
163
+			return;
164
+		}
165
+		loadClass(getMainClass());
166
+		if (isLoaded()) {
167
+			ActionManager.processEvent(CoreActionType.PLUGIN_LOADED, null, this);
168
+		}
169
+		myResourceManager = null;
170
+	}
171
+	
172
+	/**
173
+	 * Load the given classname.
174
+	 *
175
+	 * @param classname Class to load
176
+	 */
177
+	private void loadClass(final String classname) {
178
+		try {
179
+			classloader = new PluginClassLoader(this);
180
+			
181
+			final Class<?> c = classloader.loadClass(classname);
182
+			final Constructor<?> constructor = c.getConstructor(new Class[] {});
183
+		
184
+			final Object temp = constructor.newInstance(new Object[] {});
185
+			
186
+			if (temp instanceof Plugin) {
187
+				if (((Plugin) temp).checkPrerequisites()) {
188
+					plugin = (Plugin) temp;
189
+					plugin.onLoad();
190
+				} else {
191
+					Logger.userError(ErrorLevel.LOW, "Prerequisites for plugin not met. ('"+filename+":"+getMainClass()+"')");
192
+				}
193
+			}
194
+		} catch (ClassNotFoundException cnfe) {
195
+			Logger.userError(ErrorLevel.LOW, "Class not found ('"+filename+":"+getMainClass()+"')", cnfe);
196
+		} catch (NoSuchMethodException nsme) {
197
+			Logger.userError(ErrorLevel.LOW, "Constructor missing ('"+filename+":"+getMainClass()+"')", nsme);
198
+		} catch (IllegalAccessException iae) {
199
+			Logger.userError(ErrorLevel.LOW, "Unable to access constructor ('"+filename+":"+getMainClass()+"')", iae);
200
+		} catch (InvocationTargetException ite) {
201
+			Logger.userError(ErrorLevel.LOW, "Unable to invoke target ('"+filename+":"+getMainClass()+"')", ite);
202
+		} catch (InstantiationException ie) {
203
+			Logger.userError(ErrorLevel.LOW, "Unable to instantiate plugin ('"+filename+":"+getMainClass()+"')", ie);
204
+		} catch (NoClassDefFoundError ncdf) {
205
+			Logger.userError(ErrorLevel.LOW, "Unable to instantiate plugin ('"+filename+":"+getMainClass()+"'): Unable to find class: " + ncdf.getMessage(), ncdf);
206
+		}
207
+	}
208
+	
209
+	/**
210
+	 * Unload the plugin if possible.
211
+	 */
212
+	public void unloadPlugin() {
213
+		if (!isPersistant() && isLoaded()) {
214
+			plugin.onUnload();
215
+			ActionManager.processEvent(CoreActionType.PLUGIN_UNLOADED, null, this);
216
+			plugin = null;
217
+			classloader = null;
218
+		}
219
+	}
220
+	
221
+	/**
222
+	 * Get the main Class
223
+	 *
224
+	 * @return Main Class to begin loading.
225
+	 */
226
+	public String getMainClass() { return metaData.getProperty("mainclass",""); }
227
+	
228
+	/**
229
+	 * Get the Plugin for this plugin.
230
+	 *
231
+	 * @return Plugin
232
+	 */
233
+	public Plugin getPlugin() { return plugin; }
234
+	
235
+	/**
236
+	 * Get the PluginClassLoader for this plugin.
237
+	 *
238
+	 * @return PluginClassLoader
239
+	 */
240
+	private PluginClassLoader getPluginClassLoader() { return classloader; }	
241
+	
242
+	/**
243
+	 * Get the plugin friendly version
244
+	 *
245
+	 * @return Plugin friendly Version
246
+	 */
247
+	public String getFriendlyVersion() { return metaData.getProperty("version",""); }
248
+	
249
+	/**
250
+	 * Get the plugin version
251
+	 *
252
+	 * @return Plugin Version
253
+	 */
254
+	public int getVersion() {
255
+		try {
256
+			return Integer.parseInt(metaData.getProperty("version",""));
257
+		} catch (NumberFormatException nfe) {
258
+			return -1;
259
+		}
260
+	}
261
+	
262
+	/**
263
+	 * Is this a persistant plugin?
264
+	 *
265
+	 * @return true if persistant, else false
266
+	 */
267
+	public boolean isPersistant() {
268
+		final String persistance = metaData.getProperty("persistant","no");
269
+		return persistance.equalsIgnoreCase("true") || persistance.equalsIgnoreCase("yes");
270
+	}
271
+	
272
+	/**
273
+	 * Is this a persistant class?
274
+	 *
275
+	 * @param classname class to check persistance of
276
+	 * @return true if file (or whole plugin) is persistant, else false
277
+	 */
278
+	public boolean isPersistant(final String classname) {
279
+		if (isPersistant()) {
280
+			return true;
281
+		} else {
282
+			final String persistance = metaData.getProperty("persistant-"+classname,"no");
283
+			return persistance.equalsIgnoreCase("true") || persistance.equalsIgnoreCase("yes");
284
+		}
285
+	}
286
+	
287
+	/**
288
+	 * Get the plugin Filename.
289
+	 *
290
+	 * @return Filename of plugin
291
+	 */
292
+	public String getFilename() { return filename; }
293
+	
294
+	/**
295
+	 * Get the plugin Author.
296
+	 *
297
+	 * @return Author of plugin
298
+	 */
299
+	public String getAuthor() { return getMetaInfo("author",""); }
300
+	
301
+	/**
302
+	 * Get the plugin Description.
303
+	 *
304
+	 * @return Description of plugin
305
+	 */
306
+	public String getDescription() { return getMetaInfo("description",""); }
307
+	
308
+	/**
309
+	 * Get the minimum dmdirc version required to run the plugin.
310
+	 *
311
+	 * @return minimum dmdirc version required to run the plugin.
312
+	 */
313
+	public String getMinVersion() { return getMetaInfo("minversion",""); }
314
+	
315
+	/**
316
+	 * Get the (optional) maximum dmdirc version on which this plugin can run
317
+	 *
318
+	 * @return optional maximum dmdirc version on which this plugin can run
319
+	 */
320
+	public String getMaxVersion() { return getMetaInfo("maxversion",""); }
321
+	
322
+	/**
323
+	 * Get the name of the plugin. (Used to identify the plugin)
324
+	 *
325
+	 * @return Name of plugin
326
+	 */
327
+	public String getName() { return getMetaInfo("name",""); }
328
+	
329
+	/**
330
+	 * Get the nice name of the plugin. (Displayed to users)
331
+	 *
332
+	 * @return Nice Name of plugin
333
+	 */
334
+	public String getNiceName() { return getMetaInfo("nicename",getName()); }
335
+	
336
+	/**
337
+	 * String Representation of this plugin
338
+	 *
339
+	 * @return String Representation of this plugin
340
+	 */
341
+	public String toString() { return getNiceName()+" - "+filename; }
342
+	
343
+	/**
344
+	 * Get misc meta-information
345
+	 *
346
+	 * @param metainfo The metainfo to return
347
+	 * @return Misc Meta Info (or "" if not found);
348
+	 */
349
+	public String getMetaInfo(final String metainfo) { return metaData.getProperty(metainfo,""); }
350
+	
351
+	/**
352
+	 * Get misc meta-information
353
+	 *
354
+	 * @param metainfo The metainfo to return
355
+	 * @param fallback Fallback value if requested value is not found
356
+	 * @return Misc Meta Info (or fallback if not found);
357
+	 */
358
+	public String getMetaInfo(final String metainfo, final String fallback) { return metaData.getProperty(metainfo,fallback); }
359
+	
360
+	/**
361
+	 * Compares this object with the specified object for order.
362
+	 * Returns a negative integer, zero, or a positive integer as per String.compareTo();
363
+	 *
364
+	 * @param o Object to compare to
365
+	 * @return a negative integer, zero, or a positive integer.
366
+	 */
367
+	public int compareTo(PluginInfo o) {
368
+		return toString().compareTo(o.toString());
369
+	}
370
+}

+ 126
- 110
src/com/dmdirc/plugins/PluginManager.java View File

@@ -24,8 +24,6 @@
24 24
 package com.dmdirc.plugins;
25 25
 
26 26
 import java.io.File;
27
-import java.lang.reflect.Constructor;
28
-import java.lang.reflect.InvocationTargetException;
29 27
 import java.util.ArrayList;
30 28
 import java.util.Hashtable;
31 29
 import java.util.LinkedList;
@@ -43,7 +41,7 @@ public class PluginManager {
43 41
 	/**
44 42
 	 * List of known plugins.
45 43
 	 */
46
-	private final Hashtable<String,Plugin> knownPlugins = new Hashtable<String,Plugin>();
44
+	private final Hashtable<String,PluginInfo> knownPlugins = new Hashtable<String,PluginInfo>();
47 45
 	
48 46
 	/**
49 47
 	 * Directory where plugins are stored.
@@ -72,7 +70,7 @@ public class PluginManager {
72 70
 			for (String plugin : autoLoadList) {
73 71
 				plugin = plugin.trim();
74 72
 				if (!plugin.isEmpty() && plugin.charAt(0) != '#' && addPlugin(plugin)) {
75
-					getPlugin(plugin).setActive(true);
73
+					getPluginInfo(plugin).loadPlugin();
76 74
 				}
77 75
 			}
78 76
 		}
@@ -93,21 +91,22 @@ public class PluginManager {
93 91
 	/**
94 92
 	 * Add a new plugin.
95 93
 	 *
96
-	 * @param className Class Name of Plugin object
94
+	 * @param filename Filename of Plugin jar
97 95
 	 * @return True if loaded, false if failed to load or if already loaded.
98 96
 	 */
99
-	public boolean addPlugin(final String className) {
100
-		if (knownPlugins.containsKey(className.toLowerCase())) { return false; }
97
+	public boolean addPlugin(final String filename) {
98
+		if (knownPlugins.containsKey(filename.toLowerCase())) { return false; }
101 99
 		try {
102
-			final Plugin plugin = loadPlugin(className);
103
-			if (plugin == null) { return false; }
104
-			if (plugin.onLoad()) {
105
-				knownPlugins.put(className.toLowerCase(), plugin);
106
-				ActionManager.processEvent(CoreActionType.PLUGIN_LOADED, null, plugin);
100
+			final PluginInfo pluginInfo = new PluginInfo(filename);
101
+			try {
102
+				pluginInfo.checkRequirements();
103
+				knownPlugins.put(filename.toLowerCase(), pluginInfo);
107 104
 				return true;
105
+			} catch (PluginException e) {
106
+				Logger.userError(ErrorLevel.MEDIUM, "Plugin requirements not met: "+e.getMessage(), e);
108 107
 			}
109 108
 		} catch (Exception e) {
110
-			Logger.userError(ErrorLevel.MEDIUM, "Error loading "+className+" - "+e.getMessage());
109
+			Logger.userError(ErrorLevel.MEDIUM, e.getMessage(), e);
111 110
 		}
112 111
 		return false;
113 112
 	}
@@ -115,36 +114,38 @@ public class PluginManager {
115 114
 	/**
116 115
 	 * Remove a plugin.
117 116
 	 *
118
-	 * @param className Class name of plugin
117
+	 * @param filename Filename of Plugin jar
119 118
 	 * @return True if removed.
120 119
 	 */
121
-	public boolean delPlugin(final String className) {
122
-		if (!knownPlugins.containsKey(className.toLowerCase())) { return false; }
123
-		Plugin plugin = getPlugin(className);
120
+	public boolean delPlugin(final String filename) {
121
+		if (!knownPlugins.containsKey(filename.toLowerCase())) { return false; }
122
+		
123
+		PluginInfo pluginInfo = getPluginInfo(filename);
124 124
 		try {
125
-			plugin.setActive(false);
126
-			ActionManager.processEvent(CoreActionType.PLUGIN_UNLOADED, null, plugin);
127
-			plugin.onUnload();
125
+			ActionManager.processEvent(CoreActionType.PLUGIN_UNLOADED, null, pluginInfo);
126
+			pluginInfo.unloadPlugin();
128 127
 		} catch (Exception e) {
129
-			Logger.userError(ErrorLevel.MEDIUM, "Error in onUnload() for '"+className+"' - "+e.getMessage());
128
+			Logger.userError(ErrorLevel.MEDIUM, e.getMessage(), e);
130 129
 		}
131
-		knownPlugins.remove(className.toLowerCase());
132
-		plugin = null;
130
+		knownPlugins.remove(filename.toLowerCase());
131
+		pluginInfo = null;
133 132
 		return true;
134 133
 	}
135 134
 	
136 135
 	/**
137 136
 	 * Reload a plugin.
138 137
 	 *
139
-	 * @param className Class name of plugin
138
+	 * @param filename Filename of Plugin jar
140 139
 	 * @return True if reloaded.
141 140
 	 */
142
-	public boolean reloadPlugin(final String className) {
143
-		if (!knownPlugins.containsKey(className.toLowerCase())) { return false; }
144
-		final boolean wasActive = getPlugin(className).isActive();
145
-		delPlugin(className);
146
-		final boolean result = addPlugin(className);
147
-		if (result) { getPlugin(className).setActive(wasActive); }
141
+	public boolean reloadPlugin(final String filename) {
142
+		if (!knownPlugins.containsKey(filename.toLowerCase())) { return false; }
143
+		final boolean wasLoaded = getPluginInfo(filename).isLoaded();
144
+		delPlugin(filename);
145
+		final boolean result = addPlugin(filename);
146
+		if (wasLoaded) {
147
+			getPluginInfo(filename).loadPlugin();
148
+		}
148 149
 		return result;
149 150
 		
150 151
 	}
@@ -153,7 +154,7 @@ public class PluginManager {
153 154
 	 * Reload all plugins.
154 155
 	 */
155 156
 	public void reloadAllPlugins() {
156
-		for (String pluginName : getNames()) {
157
+		for (String pluginName : getFilenames()) {
157 158
 			reloadPlugin(pluginName);
158 159
 		}
159 160
 	}
@@ -161,12 +162,37 @@ public class PluginManager {
161 162
 	/**
162 163
 	 * Get a plugin instance.
163 164
 	 *
164
-	 * @param className Class name of plugin
165
-	 * @return Plugin instance, or null
165
+	 * @param filename File name of plugin jar
166
+	 * @return PluginInfo instance, or null
166 167
 	 */
167
-	public Plugin getPlugin(final String className) {
168
-		if (!knownPlugins.containsKey(className.toLowerCase())) { return null; }
169
-		return knownPlugins.get(className.toLowerCase());
168
+	public PluginInfo getPluginInfo(final String filename) {
169
+		if (!knownPlugins.containsKey(filename.toLowerCase())) { return null; }
170
+		return knownPlugins.get(filename.toLowerCase());
171
+	}
172
+	
173
+	/**
174
+	 * Get a plugin instance by plugin name.
175
+	 *
176
+	 * @param name Name of plugin to find.
177
+	 * @return PluginInfo instance, or null
178
+	 */
179
+	public PluginInfo getPluginInfoByName(final String name) {
180
+		for (String pluginName : knownPlugins.keySet()) {
181
+			final PluginInfo pluginInfo = knownPlugins.get(pluginName);
182
+			if (pluginInfo.getName().equalsIgnoreCase(name)) {
183
+				return pluginInfo;
184
+			}
185
+		}
186
+		return null;
187
+	}
188
+	
189
+	/**
190
+	 * Get directory where plugins are stored.
191
+	 *
192
+	 * @return Directory where plugins are stored.
193
+	 */
194
+	public String getDirectory() {
195
+		return myDir;
170 196
 	}
171 197
 	
172 198
 	/**
@@ -178,7 +204,36 @@ public class PluginManager {
178 204
 		final String[] result = new String[knownPlugins.size()];
179 205
 		int i = 0;
180 206
 		for (String name : knownPlugins.keySet()) {
181
-			result[i++] = name;
207
+			result[i++] = knownPlugins.get(name).getName();
208
+		}
209
+		return result;
210
+	}
211
+	
212
+	/**
213
+	 * Get string[] of known plugin file names.
214
+	 *
215
+	 * @return string[] of known plugin file names.
216
+	 */
217
+	public String[] getFilenames() {
218
+		final String[] result = new String[knownPlugins.size()];
219
+		int i = 0;
220
+		for (String name : knownPlugins.keySet()) {
221
+			result[i++] = knownPlugins.get(name).getFilename();
222
+		}
223
+		return result;
224
+	}
225
+	
226
+	
227
+	/**
228
+	 * Get string[] of known plugin mainclass names.
229
+	 *
230
+	 * @return string[] of known plugin mainclass names.
231
+	 */
232
+	public String[] getMainClassNames() {
233
+		final String[] result = new String[knownPlugins.size()];
234
+		int i = 0;
235
+		for (String name : knownPlugins.keySet()) {
236
+			result[i++] = knownPlugins.get(name).getMainClass();
182 237
 		}
183 238
 		return result;
184 239
 	}
@@ -186,12 +241,12 @@ public class PluginManager {
186 241
 	/**
187 242
 	 * Retrieves a list of all installed plugins.
188 243
 	 * Any file under the main plugin directory (~/.DMDirc/plugins or similar)
189
-	 * that matches *Plugin.class is deemed to be a valid plugin.
244
+	 * that matches *.jar is deemed to be a valid plugin.
190 245
 	 *
191 246
 	 * @return A list of all installed plugins
192 247
 	 */
193
-	public List<Plugin> getPossiblePlugins() {
194
-		final ArrayList<Plugin> res = new ArrayList<Plugin>();
248
+	public List<PluginInfo> getPossiblePluginInfos() {
249
+		final ArrayList<PluginInfo> res = new ArrayList<PluginInfo>();
195 250
 		
196 251
 		final LinkedList<File> dirs = new LinkedList<File>();
197 252
 		
@@ -205,18 +260,21 @@ public class PluginManager {
205 260
 				for (File file : dir.listFiles()) {
206 261
 					dirs.add(file);
207 262
 				}
208
-			} else if (dir.isFile() && dir.getName().matches("^.*Plugin\\.class$")) {
263
+			} else if (dir.isFile() && dir.getName().matches("^.*\\.jar$")) {
209 264
 				String target = dir.getPath();
210
-				// Remove the plugin dir & .class suffix
211
-				target = target.substring(myDir.length(), target.length() - 6);
212
-				// Change / (or \) to .
213
-				target = target.replace(File.separatorChar, '.');
265
+//				// Remove the plugin dir & .class suffix
266
+//				target = target.substring(myDir.length(), target.length() - 6);
267
+//				// Change / (or \) to .
268
+//				target = target.replace(File.separatorChar, '.');
269
+
270
+				// Remove the plugin dir
271
+				target = target.substring(myDir.length(), target.length());
214 272
 				addPlugin(target);
215 273
 			}
216 274
 		}
217 275
 		
218 276
 		for (String name : knownPlugins.keySet()) {
219
-			res.add(getPlugin(name));
277
+			res.add(getPluginInfo(name));
220 278
 		}
221 279
 		
222 280
 		return res;
@@ -225,92 +283,47 @@ public class PluginManager {
225 283
 	/**
226 284
 	 * Update the autoLoadList
227 285
 	 *
228
-	 * @param plugin to add/remove (Decided automatically based on isActive())
286
+	 * @param plugin to add/remove (Decided automatically based on isLoaded())
229 287
 	 */
230
-	public void updateAutoLoad(final Plugin plugin) {
288
+	public void updateAutoLoad(final PluginInfo plugin) {
231 289
 		if (IdentityManager.getGlobalConfig().hasOption("plugins", "autoload")) {
232 290
 			final String[] autoLoadList = IdentityManager.getGlobalConfig().getOption("plugins", "autoload").split("\n");
233 291
 			final StringBuffer newAutoLoadList = new StringBuffer();
234 292
 			boolean found = false;
235 293
 			for (String pluginName : autoLoadList) {
236 294
 				pluginName = pluginName.trim();
237
-				if (pluginName.equals(plugin.getClass().getName())) {
295
+				if (pluginName.equals(plugin.getFilename())) {
238 296
 					found = true;
239
-					if (plugin.isActive()) {
297
+					if (plugin.isLoaded()) {
240 298
 						newAutoLoadList.append(pluginName+"\n");
241 299
 					}
242 300
 				} else if (!pluginName.isEmpty()) {
243 301
 					newAutoLoadList.append(pluginName+"\n");
244 302
 				}
245 303
 			}
246
-			if (!found && plugin.isActive()) {
247
-				newAutoLoadList.append(plugin.getClass().getName()+"\n");
304
+			if (!found && plugin.isLoaded()) {
305
+				newAutoLoadList.append(plugin.getFilename()+"\n");
248 306
 			}
249 307
 			IdentityManager.getConfigIdentity().setOption("plugins", "autoload", newAutoLoadList.toString());
250
-		} else if (plugin.isActive()) {
251
-			IdentityManager.getConfigIdentity().setOption("plugins", "autoload", plugin.getClass().getName());
308
+		} else if (plugin.isLoaded()) {
309
+			IdentityManager.getConfigIdentity().setOption("plugins", "autoload", plugin.getFilename());
252 310
 		}
253 311
 	}
254 312
 	
255 313
 	/**
256
-	 * Get Plugin[] of known plugins.
314
+	 * Get PluginInfo[] of known plugins.
257 315
 	 *
258
-	 * @return Plugin[] of known plugins.
316
+	 * @return PluginInfo[] of known plugins.
259 317
 	 */
260
-	public Plugin[] getPlugins() {
261
-		final Plugin[] result = new Plugin[knownPlugins.size()];
318
+	public PluginInfo[] getPluginInfos() {
319
+		final PluginInfo[] result = new PluginInfo[knownPlugins.size()];
262 320
 		int i = 0;
263 321
 		for (String name : knownPlugins.keySet()) {
264
-			result[i++] = getPlugin(name);
322
+			result[i++] = getPluginInfo(name);
265 323
 		}
266 324
 		return result;
267 325
 	}
268 326
 	
269
-	
270
-	/**
271
-	 * Load a plugin with a given className
272
-	 *
273
-	 * @param className Class Name of plugin to load.
274
-	 * @return Loaded plugin or null
275
-	 */
276
-	private Plugin loadPlugin(final String className) {
277
-		Plugin result;
278
-		try {
279
-			final ClassLoader cl = new PluginClassLoader(myDir);
280
-			
281
-			final Class<?> c = cl.loadClass(className);
282
-			final Constructor<?> constructor = c.getConstructor(new Class[] {});
283
-		
284
-			final Object temp = constructor.newInstance(new Object[] {});
285
-			
286
-			if (temp instanceof Plugin) {
287
-				result = (Plugin) temp;
288
-			} else {
289
-				result = null;
290
-			}
291
-		} catch (ClassNotFoundException cnfe) {
292
-			Logger.userError(ErrorLevel.LOW, "Class not found ('"+className+"')");
293
-			result = null;
294
-		} catch (NoSuchMethodException nsme) {
295
-			Logger.userError(ErrorLevel.LOW, "Constructor missing ('"+className+"')");
296
-			result = null;
297
-		} catch (IllegalAccessException iae) {
298
-			Logger.userError(ErrorLevel.LOW, "Unable to access constructor ('"+className+"')");
299
-			result = null;
300
-		} catch (InvocationTargetException ite) {
301
-			Logger.userError(ErrorLevel.LOW, "Unable to invoke target ('"+className+"')");
302
-			result = null;
303
-		} catch (InstantiationException ie) {
304
-			Logger.userError(ErrorLevel.LOW, "Unable to instantiate plugin ('"+className+"')");
305
-			result = null;
306
-		} catch (NoClassDefFoundError ncdf) {
307
-			Logger.userError(ErrorLevel.LOW, "Unable to instantiate plugin ('"+className+"'): Unable to find class: " + ncdf.getMessage());
308
-			result = null;
309
-		}
310
-		
311
-		return result;
312
-	}
313
-
314 327
 	/**
315 328
 	 * Send an event of the specified type to plugins.
316 329
 	 *
@@ -320,12 +333,15 @@ public class PluginManager {
320 333
 	 */
321 334
 	public void processEvent(final ActionType type, final StringBuffer format, final Object ... arguments) {
322 335
 		for (String pluginName : knownPlugins.keySet()) {
323
-			final Plugin plugin = knownPlugins.get(pluginName);
324
-			if (plugin instanceof EventPlugin && plugin.isActive()) {
325
-				try {
326
-					((EventPlugin)plugin).processEvent(type, format, arguments);
327
-				} catch (Exception e) {
328
-					Logger.userError(ErrorLevel.LOW, "Error with processEvent for "+pluginName+" ("+type+") - "+e.getMessage());
336
+			final PluginInfo pluginInfo = knownPlugins.get(pluginName);
337
+			if (pluginInfo.isLoaded()) {
338
+				final Plugin plugin = pluginInfo.getPlugin();
339
+				if (plugin instanceof EventPlugin) {
340
+					try {
341
+						((EventPlugin)plugin).processEvent(type, format, arguments);
342
+					} catch (Exception e) {
343
+						Logger.userError(ErrorLevel.LOW, "Error with processEvent for "+pluginName+" ("+type+") - "+e.getMessage(), e);
344
+					}
329 345
 				}
330 346
 			}
331 347
 		}

+ 16
- 10
src/com/dmdirc/ui/swing/MainFrame.java View File

@@ -33,6 +33,7 @@ import com.dmdirc.config.IdentityManager;
33 33
 import com.dmdirc.logger.ErrorLevel;
34 34
 import com.dmdirc.logger.Logger;
35 35
 import com.dmdirc.plugins.Plugin;
36
+import com.dmdirc.plugins.PluginInfo;
36 37
 import com.dmdirc.plugins.PluginManager;
37 38
 import com.dmdirc.ui.WindowManager;
38 39
 import com.dmdirc.ui.interfaces.FrameManager;
@@ -770,6 +771,7 @@ public final class MainFrame extends JFrame implements WindowListener,
770 771
                 //Ignore
771 772
             }
772 773
         });
774
+        pluginsMenu.addMenuListener(configureMenu.getMenuListeners()[0]);
773 775
 
774 776
         menuBar.add(fileMenu);
775 777
         menuBar.add(settingsMenu);
@@ -785,18 +787,21 @@ public final class MainFrame extends JFrame implements WindowListener,
785 787
      * @param menu Menu to populate
786 788
      */
787 789
     private void populateConfigurePluginsMenu(final JMenu menu) {
788
-        final Plugin[] plugins =
789
-                PluginManager.getPluginManager().getPlugins();
790
+        final PluginInfo[] plugins =
791
+                PluginManager.getPluginManager().getPluginInfos();
790 792
         pluginList.clear();
791 793
         menu.removeAll();
792 794
 
793
-        for (Plugin plugin : plugins) {
794
-            if (plugin.isConfigurable() && plugin.isActive()) {
795
-                final JMenuItem mi = new JMenuItem(plugin.toString());
796
-                mi.setActionCommand("configurePlugin");
797
-                mi.addActionListener(this);
798
-                menu.add(mi);
799
-                pluginList.put(mi, plugin.getClass().getName());
795
+        for (PluginInfo pluginInfo : plugins) {
796
+            if (pluginInfo.isLoaded()) {
797
+                Plugin plugin = pluginInfo.getPlugin();
798
+                if (plugin.isConfigurable()) {
799
+                    final JMenuItem mi = new JMenuItem(pluginInfo.getNiceName());
800
+                    mi.setActionCommand("configurePlugin");
801
+                    mi.addActionListener(this);
802
+                    menu.add(mi);
803
+                    pluginList.put(mi, pluginInfo.getFilename());
804
+                }
800 805
             }
801 806
         }
802 807
         
@@ -944,7 +949,8 @@ public final class MainFrame extends JFrame implements WindowListener,
944 949
             ServerManager.getServerManager().joinDevChat();
945 950
         } else if (e.getActionCommand().equals("configurePlugin")) {
946 951
             PluginManager.getPluginManager().
947
-                    getPlugin(pluginList.get(e.getSource())).showConfig();
952
+                    getPluginInfo(pluginList.get(e.getSource())).getPlugin().
953
+                    showConfig();
948 954
         } else if (e.getActionCommand().equals("feedback")) {
949 955
             FeedbackDialog.showFeedbackDialog();
950 956
         }

+ 5
- 4
src/com/dmdirc/ui/swing/components/PluginCellRenderer.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.ui.swing.components;
24 24
 
25 25
 import com.dmdirc.plugins.Plugin;
26
+import com.dmdirc.plugins.PluginInfo;
26 27
 import static com.dmdirc.ui.swing.UIUtilities.SMALL_BORDER;
27 28
 
28 29
 import java.awt.BorderLayout;
@@ -55,7 +56,7 @@ public final class PluginCellRenderer implements ListCellRenderer {
55 56
             final boolean cellHasFocus) {
56 57
         
57 58
         final JPanel res = new JPanel();
58
-        final Plugin plugin = (Plugin) value;
59
+        final PluginInfo plugin = (PluginInfo) value;
59 60
         
60 61
         res.setLayout(new BorderLayout());
61 62
         
@@ -70,17 +71,17 @@ public final class PluginCellRenderer implements ListCellRenderer {
70 71
         
71 72
         Color foreground;
72 73
         
73
-        if (plugin.isActive()) {
74
+        if (plugin.isLoaded()) {
74 75
             foreground = Color.BLACK;
75 76
         } else {
76 77
             foreground = Color.GRAY;
77 78
         }
78 79
         
79
-        final JLabel name = new JLabel(plugin.toString());
80
+        final JLabel name = new JLabel(plugin.getNiceName());
80 81
         name.setFont(name.getFont().deriveFont(Font.BOLD));
81 82
         name.setForeground(foreground);
82 83
         
83
-        final JLabel version = new JLabel("v" + plugin.getVersion());
84
+        final JLabel version = new JLabel("v" + plugin.getFriendlyVersion());
84 85
         version.setForeground(foreground);
85 86
         version.setHorizontalAlignment(JLabel.CENTER);
86 87
         

+ 20
- 12
src/com/dmdirc/ui/swing/dialogs/PluginDialog.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.ui.swing.dialogs;
25 25
 import com.dmdirc.util.BrowserLauncher;
26 26
 import com.dmdirc.Main;
27 27
 import com.dmdirc.plugins.Plugin;
28
+import com.dmdirc.plugins.PluginInfo;
28 29
 import com.dmdirc.plugins.PluginManager;
29 30
 import com.dmdirc.ui.swing.MainFrame;
30 31
 import com.dmdirc.ui.swing.components.PluginCellRenderer;
@@ -218,11 +219,11 @@ public final class PluginDialog extends StandardDialog implements
218 219
     
219 220
     /** Populates the plugins list with plugins from the plugin manager. */
220 221
     private void populateList() {
221
-        final List<Plugin> list = PluginManager.getPluginManager().getPossiblePlugins();
222
+        final List<PluginInfo> list = PluginManager.getPluginManager().getPossiblePluginInfos();
222 223
         Collections.sort(list);
223 224
         
224 225
         ((DefaultListModel) pluginList.getModel()).clear();
225
-        for (Plugin plugin : list) {
226
+        for (PluginInfo plugin : list) {
226 227
             ((DefaultListModel) pluginList.getModel()).addElement(plugin);
227 228
         }
228 229
         if (((DefaultListModel) pluginList.getModel()).size() > 0) {
@@ -248,23 +249,24 @@ public final class PluginDialog extends StandardDialog implements
248 249
         if (e.getSource() == myOkButton) {
249 250
             dispose();
250 251
         } else if (e.getSource() == configureButton && selectedPlugin >= 0) {
251
-            final Plugin plugin = (Plugin) pluginList.getSelectedValue();
252
-            if (plugin.isConfigurable()) {
252
+            final PluginInfo pluginInfo = (PluginInfo) pluginList.getSelectedValue();
253
+            final Plugin plugin = pluginInfo.getPlugin();
254
+            if (plugin != null && plugin.isConfigurable()) {
253 255
                 plugin.showConfig();
254 256
             }
255 257
         } else if (e.getSource() == toggleButton && selectedPlugin >= 0) {
256
-            final Plugin plugin = (Plugin) pluginList.getSelectedValue();
257
-            if (plugin.isActive()) {
258
-                plugin.setActive(false);
258
+            final PluginInfo pluginInfo = (PluginInfo) pluginList.getSelectedValue();
259
+            if (pluginInfo.isLoaded()) {
260
+                pluginInfo.unloadPlugin();
259 261
                 toggleButton.setText("Enable");
260 262
                 configureButton.setEnabled(false);
261 263
             } else {
262
-                plugin.setActive(true);
264
+                pluginInfo.loadPlugin();
263 265
                 toggleButton.setText("Disable");
264
-                configureButton.setEnabled(plugin.isConfigurable());
266
+                configureButton.setEnabled(pluginInfo.getPlugin().isConfigurable());
265 267
             }
266 268
             
267
-            PluginManager.getPluginManager().updateAutoLoad(plugin);
269
+            PluginManager.getPluginManager().updateAutoLoad(pluginInfo);
268 270
             
269 271
             pluginList.repaint();
270 272
         }
@@ -275,11 +277,17 @@ public final class PluginDialog extends StandardDialog implements
275 277
         if (!selectionEvent.getValueIsAdjusting()) {
276 278
             final int selected = ((JList) selectionEvent.getSource()).getSelectedIndex();
277 279
             if (selected >= 0) {
278
-                final Plugin plugin = (Plugin) ((JList) selectionEvent.getSource()).getSelectedValue();
279
-                if (plugin.isActive()) {
280
+                final PluginInfo pluginInfo = (PluginInfo) ((JList) selectionEvent.getSource()).getSelectedValue();
281
+                final Plugin plugin = pluginInfo.getPlugin();
282
+                if (pluginInfo.isLoaded()) {
280 283
                     configureButton.setEnabled(plugin.isConfigurable());
284
+                    pluginInfo.loadPlugin();
285
+                    if (pluginInfo.isPersistant()) {
286
+                        toggleButton.setEnabled(false);
287
+                    }
281 288
                     toggleButton.setText("Disable");
282 289
                 } else {
290
+                    pluginInfo.unloadPlugin();
283 291
                     configureButton.setEnabled(false);
284 292
                     toggleButton.setText("Enable");
285 293
                 }

Loading…
Cancel
Save