]> jfr.im git - irc/rizon/moo.git/commitdiff
Fix loading plugins
authorAdam <redacted>
Fri, 26 Feb 2016 18:55:43 +0000 (13:55 -0500)
committerAdam <redacted>
Fri, 26 Feb 2016 18:55:43 +0000 (13:55 -0500)
core/src/main/java/net/rizon/moo/plugin/core/CommandPlugins.java
core/src/main/java/net/rizon/moo/plugin/core/CommandReload.java
moo/src/main/java/net/rizon/moo/Moo.java

index ec074f856b0e5548731186ff7b8a33cbd98354ee..7d0491d7f859497bece301cf4cf03cee26b37ab1 100644 (file)
@@ -50,11 +50,12 @@ class CommandPlugins extends Command
 
                        try
                        {
+                               moo.stopPlugins();
                                Plugin p = pluginManager.loadPlugin(pinfo[0], pinfo[1], pinfo[2]);
-                               moo.rebuildInjector();
+                               moo.buildInjector();
                                source.reply("Plugin " + p.getName() + " loaded");
                        }
-                       catch (Throwable ex)
+                       catch (Exception ex)
                        {
                                source.reply("Unable to load plugin " + params[2] + ": " + ex.getMessage());
                                
@@ -71,7 +72,8 @@ class CommandPlugins extends Command
                        else
                        {
                                pluginManager.remove(p);
-                               moo.rebuildInjector();
+                               moo.stopPlugins();
+                               moo.buildInjector();
                                source.reply("Plugin " + p.getName() + " removed");
                        }
                }
@@ -81,25 +83,26 @@ class CommandPlugins extends Command
                        if (p == null)
                        {
                                source.reply("Plugin " + params[2] + " is not loaded");
+                               return;
                        }
-                       else
+
+                       Artifact a = p.getArtifact();
+                       pluginManager.remove(p);
+                       moo.stopPlugins();
+                       moo.buildInjector();
+
+                       try
+                       {
+                               moo.stopPlugins();
+                               p = pluginManager.loadPlugin(a.getGroupId(), a.getArtifactId(), a.getVersion());
+                               moo.buildInjector();
+                               source.reply("Plugin " + p.getName() + " reloaded");
+                       }
+                       catch (Exception ex)
                        {
-                               Artifact a = p.getArtifact();
-                               p.remove();
-                               moo.rebuildInjector();
+                               source.reply("Unable to load plugin " + params[2] + ": " + ex.getMessage());
 
-                               try
-                               {
-                                       p = pluginManager.loadPlugin(a.getGroupId(), a.getArtifactId(), a.getVersion());
-                                       moo.rebuildInjector();
-                                       source.reply("Plugin " + p.getName() + " reloaded");
-                               }
-                               catch (Throwable ex)
-                               {
-                                       source.reply("Unable to load plugin " + params[2] + ": " + ex.getMessage());
-                                       
-                                       logger.warn("Unable to reload plugin " + params[2], ex);
-                               }
+                               logger.warn("Unable to reload plugin " + params[2], ex);
                        }
                }
        }
index 2ac211cd637aed7d3c81d61dc29d4e5b29214cab..2e3b394098fe9988983061e9d7ee93e4d320da93 100644 (file)
@@ -47,7 +47,8 @@ class CommandReload extends Command
                        eventBus.post(new OnReload(source));
 
                        moo.setConf(c);
-                       moo.rebuildInjector();
+                       moo.stopPlugins();
+                       moo.buildInjector();
                        
                        source.reply("Successfully reloaded configuration");
                }
index 55e595a988241a8886808b0f7e83f74aee7cbb54..3f1c63cd2144008d250975077129c74581453ac2 100644 (file)
@@ -235,7 +235,7 @@ public class Moo
                return moo.group.schedule(r, t, unit);
        }
 
-       private void buildInjector()
+       public void buildInjector()
        {
                List<Module> modules = new ArrayList<>();
 
@@ -264,11 +264,9 @@ public class Moo
                        }
        }
 
-       public void rebuildInjector()
+       public void stopPlugins()
        {
                for (Plugin p : pluginManager.getPlugins())
                        p.stop();
-
-               buildInjector();
        }
 }