}
});
if (plugins != null) {
IRed5Plugin red5Plugin = null;
log.debug("{} plugins to launch", plugins.length);
for (File plugin : plugins) {
JarFile jar = null;
Manifest manifest = null;
try {
jar = new JarFile(plugin, false);
manifest = jar.getManifest();
} catch (Exception e1) {
log.warn("Error loading plugin manifest: {}", plugin);
} finally {
jar.close();
}
if (manifest == null) {
continue;
}
Attributes attributes = manifest.getMainAttributes();
if (attributes == null) {
continue;
}
String pluginMainClass = attributes.getValue("Red5-Plugin-Main-Class");
if (pluginMainClass == null || pluginMainClass.length() <= 0) {
continue;
}
// attempt to load the class; since it's in the plugins directory this should work
ClassLoader loader = common.getClassLoader();
Class<?> pluginClass;
String pluginMainMethod = null;
try {
pluginClass = Class.forName(pluginMainClass, true, loader);
} catch (ClassNotFoundException e) {
continue;
}
try {
//handle plug-ins without "main" methods
pluginMainMethod = attributes.getValue("Red5-Plugin-Main-Method");
if (pluginMainMethod == null || pluginMainMethod.length() <= 0) {
//just get an instance of the class
red5Plugin = (IRed5Plugin) pluginClass.newInstance();
} else {
Method method = pluginClass.getMethod(pluginMainMethod, (Class<?>[]) null);
Object o = method.invoke(null, (Object[]) null);
if (o != null && o instanceof IRed5Plugin) {
red5Plugin = (IRed5Plugin) o;
}
}
//register and start
if (red5Plugin != null) {
//set top-level context
red5Plugin.setApplicationContext(applicationContext);
//set server reference
red5Plugin.setServer(server);
//register the plug-in to make it available for lookups
PluginRegistry.register(red5Plugin);
//start the plugin
red5Plugin.doStart();
}
log.info("Loaded plugin: {}", pluginMainClass);
} catch (Throwable t) {
log.warn("Error loading plugin: {}; Method: {}", pluginMainClass, pluginMainMethod);
log.error("", t);