use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.
the class PluginManager method initializePlugins.
/**
* Loads and initalizes all Plugins.
*
* @see Plugin
*/
public void initializePlugins() {
try {
int j;
boolean dependencyFound;
// Dependency check
for (int i = 0; i < publicPlugins.size(); i++) {
// if dependencies are available, check these
if ((publicPlugins.get(i)).getDependency().size() > 0) {
List<PluginDependency> dependencies = (publicPlugins.get(i)).getDependency();
// go trough all dependencies
for (PluginDependency dependency : dependencies) {
j = 0;
dependencyFound = false;
// look for the specific plugin
for (PublicPlugin plugin : publicPlugins) {
if (plugin.getName() != null && plugin.getName().equals(dependency.getName())) {
// if the version is compatible then reorder
if (dependency.compareVersion(plugin.getVersion())) {
dependencyFound = true;
// when depended Plugin hadn't been installed yet
if (j > i) {
// find the position of plugins-List because it has more entries
int counter = 0, x = 0, z = 0;
for (Plugin plug : plugins) {
// find the position of the aim-object
if (plug.getClass().toString().substring(6).equals(publicPlugins.get(j).getPluginClass())) {
x = counter;
} else // find the change-position
if (plug.getClass().toString().substring(6).equals(publicPlugins.get(i).getPluginClass())) {
z = counter;
}
counter++;
}
// change the order
publicPlugins.add(i, publicPlugins.get(j));
publicPlugins.remove(j + 1);
plugins.add(z, plugins.get(x));
plugins.remove(x + 1);
// start again, to check the other dependencies
i--;
}
} else // else don't load the plugin and show an error
{
Log.error("Depended Plugin " + dependency.getName() + " hasn't the right version (" + dependency.getVersion() + "<>" + plugin.getVersion());
}
break;
}
j++;
}
// If the depended Plugin wasn't found, then show error.
if (!dependencyFound) {
Log.error("Depended Plugin " + dependency.getName() + " is missing for the Plugin " + (publicPlugins.get(i)).getName());
// find the posiion of plugins-List because it has more entries
int counter = 0;
for (Plugin plug : plugins) {
// find the delete-position
if (plug.getClass().toString().substring(6).equals(publicPlugins.get(i).getPluginClass())) {
break;
}
counter++;
}
// delete the Plugin, because the depended Plugin is missing
publicPlugins.remove(i);
plugins.remove(counter);
i--;
break;
}
}
}
}
EventQueue.invokeLater(() -> {
for (Plugin plugin : plugins) {
long start = System.currentTimeMillis();
Log.debug("Trying to initialize " + plugin);
try {
plugin.initialize();
long end = System.currentTimeMillis();
Log.debug("Took " + (end - start) + " ms. to load " + plugin);
} catch (Throwable e) {
Log.error("An exception occurred while initializing plugin " + plugin, e);
}
}
});
} catch (Exception e) {
Log.error("An exception occurred while initializing plugins.", e);
}
}
use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.
the class PluginManager method removePublicPlugin.
/**
* Removes and uninstall a plugin from Spark.
*
* @param plugin the plugin to uninstall.
*/
public void removePublicPlugin(PublicPlugin plugin) {
for (PublicPlugin publicPlugin : getPublicPlugins()) {
if (plugin.getName().equals(publicPlugin.getName())) {
uninstall(plugin.getPluginDir());
publicPlugins.remove(plugin);
}
}
}
Aggregations