@@ -7,6 +7,10 @@ import org.codeoverflow.chatoverflow.framework.helper.PluginLoader
7
7
import org .codeoverflow .chatoverflow .framework .manager .PluginManagerStub
8
8
9
9
import scala .collection .mutable .ListBuffer
10
+ import scala .concurrent .ExecutionContext .Implicits .global
11
+ import scala .concurrent .duration ._
12
+ import scala .concurrent .{Await , Future }
13
+ import scala .util .Success
10
14
11
15
/**
12
16
* The plugin framework holds all plugin types important from the jar files in the plugin folder.
@@ -62,6 +66,8 @@ class PluginFramework(pluginDirectoryPath: String) extends WithLogger {
62
66
logger warn s " PluginType directory ' $pluginDirectory' does not exist! "
63
67
} else {
64
68
69
+ val futures = ListBuffer [Future [_]]()
70
+
65
71
// Get (new) jar file urls
66
72
val jarFiles = getNewJarFiles(pluginDirectory)
67
73
logger info s " Found ${jarFiles.length} new plugins. "
@@ -81,22 +87,27 @@ class PluginFramework(pluginDirectoryPath: String) extends WithLogger {
81
87
} else {
82
88
83
89
// Try to test the initiation of the plugin
84
- try {
85
- plugin.createPluginInstance(new PluginManagerStub )
86
- logger info s " Successfully tested instantiation of plugin ' ${plugin.getName}' "
87
- pluginTypes += plugin
88
- } catch {
89
- // Note that we catch not only exceptions, but also errors like NoSuchMethodError. Deep stuff
90
- case _ : Error => logger warn s " Error while test init of plugin ' ${plugin.getName}'. "
91
- case _ : Exception => logger warn s " Exception while test init of plugin ' ${plugin.getName}'. "
90
+ futures += plugin.getDependencyFuture andThen {
91
+ case Success (_) =>
92
+ try {
93
+ plugin.createPluginInstance(new PluginManagerStub )
94
+ logger info s " Successfully tested instantiation of plugin ' ${plugin.getName}' "
95
+ pluginTypes += plugin
96
+ } catch {
97
+ // Note that we catch not only exceptions, but also errors like NoSuchMethodError. Deep stuff
98
+ case _ : Error => logger warn s " Error while test init of plugin ' ${plugin.getName}'. "
99
+ case _ : Exception => logger warn s " Exception while test init of plugin ' ${plugin.getName}'. "
100
+ }
92
101
}
93
102
}
94
103
}
95
104
}
96
- }
97
105
98
- logger info s " Loaded ${pluginTypes.length} plugin types in total: " +
99
- s " ${pluginTypes.map(pt => s " ${pt.getName} ( ${pt.getAuthor}) " ).mkString(" , " )}"
106
+ futures.foreach(f => Await .ready(f, 10 .seconds))
107
+
108
+ logger info s " Loaded ${pluginTypes.length} plugin types in total: " +
109
+ s " ${pluginTypes.map(pt => s " ${pt.getName} ( ${pt.getAuthor}) " ).mkString(" , " )}"
110
+ }
100
111
}
101
112
102
113
/**
0 commit comments