瀏覽代碼

Remove plugin (un)loaded actions.

Depends-On: I413a3f6f72999262bf4426de082cc8c9946a6f90
Change-Id: I84f07c00e0589ff25ae1b4a01f5671488b847925
Reviewed-on: http://gerrit.dmdirc.com/3450
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Greg Holmes 10 年之前
父節點
當前提交
6e444ebec1

+ 2
- 0
src/com/dmdirc/actions/CoreActionType.java 查看文件

@@ -220,8 +220,10 @@ public enum CoreActionType implements ActionType {
220 220
     /** Query nick change. */
221 221
     QUERY_NICKCHANGE(QueryEvents.QUERY_EVENT_WITH_ARG, "Query: user changed nicks"),
222 222
     /** Plugin loaded. */
223
+    @Deprecated
223 224
     PLUGIN_LOADED(PluginEvents.PLUGIN_EVENT, "Plugin loaded"),
224 225
     /** Plugin unloaded. */
226
+    @Deprecated
225 227
     PLUGIN_UNLOADED(PluginEvents.PLUGIN_EVENT, "Plugin unloaded"),
226 228
     /** Plugins have been refreshed. */
227 229
     PLUGIN_REFRESH(PluginEvents.PLUGIN_EVENT, "Plugins refreshed"),

+ 12
- 0
src/com/dmdirc/events/PluginEvent.java 查看文件

@@ -22,9 +22,21 @@
22 22
 
23 23
 package com.dmdirc.events;
24 24
 
25
+import com.dmdirc.plugins.PluginInfo;
26
+
25 27
 /**
26 28
  * Base class for all plugin events.
27 29
  */
28 30
 public abstract class PluginEvent extends DMDircEvent {
29 31
 
32
+    private PluginInfo plugin;
33
+
34
+    public PluginEvent(final PluginInfo plugin) {
35
+        this.plugin = plugin;
36
+    }
37
+
38
+    public PluginInfo getPlugin() {
39
+        return plugin;
40
+    }
41
+
30 42
 }

+ 35
- 0
src/com/dmdirc/events/PluginLoadedEvent.java 查看文件

@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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
+
23
+package com.dmdirc.events;
24
+
25
+import com.dmdirc.plugins.PluginInfo;
26
+
27
+/**
28
+ * Fired when a plugin is loaded.
29
+ */
30
+public class PluginLoadedEvent extends PluginEvent {
31
+
32
+    public PluginLoadedEvent(final PluginInfo plugin) {
33
+        super(plugin);
34
+    }
35
+}

+ 35
- 0
src/com/dmdirc/events/PluginUnloadedEvent.java 查看文件

@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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
+
23
+package com.dmdirc.events;
24
+
25
+import com.dmdirc.plugins.PluginInfo;
26
+
27
+/**
28
+ * Fired when a plugin is loaded.
29
+ */
30
+public class PluginUnloadedEvent extends PluginEvent {
31
+
32
+    public PluginUnloadedEvent(final PluginInfo plugin) {
33
+        super(plugin);
34
+    }
35
+}

+ 13
- 6
src/com/dmdirc/plugins/PluginInfo.java 查看文件

@@ -22,10 +22,10 @@
22 22
 
23 23
 package com.dmdirc.plugins;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26
-import com.dmdirc.actions.CoreActionType;
27 25
 import com.dmdirc.config.ConfigFileBackedConfigProvider;
28 26
 import com.dmdirc.config.InvalidIdentityFileException;
27
+import com.dmdirc.events.PluginLoadedEvent;
28
+import com.dmdirc.events.PluginUnloadedEvent;
29 29
 import com.dmdirc.interfaces.config.ConfigProvider;
30 30
 import com.dmdirc.interfaces.config.IdentityController;
31 31
 import com.dmdirc.logger.ErrorLevel;
@@ -34,6 +34,8 @@ import com.dmdirc.util.SimpleInjector;
34 34
 import com.dmdirc.util.resourcemanager.ResourceManager;
35 35
 import com.dmdirc.util.validators.ValidationResponse;
36 36
 
37
+import com.google.common.eventbus.EventBus;
38
+
37 39
 import java.io.File;
38 40
 import java.io.IOException;
39 41
 import java.io.InputStream;
@@ -91,12 +93,15 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
91 93
     private final Map<String, ExportInfo> exports = new HashMap<>();
92 94
     /** List of configuration providers. */
93 95
     private final List<ConfigProvider> configProviders = new ArrayList<>();
96
+    /** Event bus to post plugin loaded events to. */
97
+    private final EventBus eventBus;
94 98
 
95 99
     /**
96 100
      * Create a new PluginInfo.
97 101
      *
98 102
      * @param metadata            The plugin's metadata information
99 103
      * @param injectorInitialiser The initialiser to use for the plugin's injector.
104
+     * @param eventBus            Event bus to post event loaded events on.
100 105
      * @param identityController  The identity controller to add and remove settings from.
101 106
      * @param objectGraph         The object graph to give to plugins for DI purposes.
102 107
      *
@@ -105,10 +110,12 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
105 110
     public PluginInfo(
106 111
             final PluginMetaData metadata,
107 112
             final Provider<PluginInjectorInitialiser> injectorInitialiser,
113
+            final EventBus eventBus,
108 114
             final IdentityController identityController,
109 115
             final ObjectGraph objectGraph) throws PluginException {
110 116
         this.injectorInitialiser = injectorInitialiser;
111 117
         this.objectGraph = objectGraph;
118
+        this.eventBus = eventBus;
112 119
         this.identityController = identityController;
113 120
         this.filename = new File(metadata.getPluginUrl().getPath()).getName();
114 121
         this.metaData = metadata;
@@ -627,8 +634,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
627 634
             loadClass(metaData.getMainClass());
628 635
 
629 636
             if (isLoaded()) {
630
-                ActionManager.getActionManager().triggerEvent(
631
-                        CoreActionType.PLUGIN_LOADED, null, this);
637
+                //TODO plugin loading shouldnt be done from here, event bus shouldn't be here.
638
+                eventBus.post(new PluginLoadedEvent(this));
632 639
             }
633 640
 
634 641
             isLoading = false;
@@ -846,8 +853,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
846 853
                     Logger.appError(ErrorLevel.MEDIUM, lastError, e);
847 854
                 }
848 855
 
849
-                ActionManager.getActionManager().triggerEvent(
850
-                        CoreActionType.PLUGIN_UNLOADED, null, this);
856
+                //TODO plugin unloading shouldnt be done from here, event bus shouldn't be here.
857
+                eventBus.post(new PluginUnloadedEvent(this));
851 858
                 synchronized (provides) {
852 859
                     for (Service service : provides) {
853 860
                         service.delProvider(this);

+ 4
- 1
src/com/dmdirc/plugins/PluginManager.java 查看文件

@@ -78,6 +78,8 @@ public class PluginManager implements ServiceManager {
78 78
     private final GlobalClassLoader globalClassLoader;
79 79
     /** The graph to pass to plugins for DI purposes. */
80 80
     private final ObjectGraph objectGraph;
81
+    /** Event bus to pass to plugin info for plugin loaded events. */
82
+    private final EventBus eventBus;
81 83
 
82 84
     /**
83 85
      * Creates a new instance of PluginManager.
@@ -105,6 +107,7 @@ public class PluginManager implements ServiceManager {
105 107
         this.directory = directory;
106 108
         this.globalClassLoader = new GlobalClassLoader(this);
107 109
         this.objectGraph = objectGraph;
110
+        this.eventBus = eventBus;
108 111
 
109 112
         eventBus.register(this);
110 113
     }
@@ -264,7 +267,7 @@ public class PluginManager implements ServiceManager {
264 267
                             + "!/META-INF/plugin.config"),
265 268
                     new URL("file:" + getDirectory() + filename));
266 269
             metadata.load();
267
-            final PluginInfo pluginInfo = new PluginInfo(metadata, initialiserProvider,
270
+            final PluginInfo pluginInfo = new PluginInfo(metadata, initialiserProvider, eventBus,
268 271
                     identityController, objectGraph);
269 272
             final PluginInfo existing = getPluginInfoByName(metadata.getName());
270 273
             if (existing != null) {

Loading…
取消
儲存