Search in sources :

Example 6 with PublicPlugin

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);
    }
}
Also used : PluginDependency(org.jivesoftware.spark.plugin.PluginDependency) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) DocumentException(org.dom4j.DocumentException) MalformedURLException(java.net.MalformedURLException) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Plugin(org.jivesoftware.spark.plugin.Plugin)

Example 7 with PublicPlugin

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);
        }
    }
}
Also used : PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin)

Aggregations

PublicPlugin (org.jivesoftware.spark.plugin.PublicPlugin)7 DocumentException (org.dom4j.DocumentException)4 MalformedURLException (java.net.MalformedURLException)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 Node (org.dom4j.Node)2 SAXReader (org.dom4j.io.SAXReader)2 PluginManager (org.jivesoftware.spark.PluginManager)2 Plugin (org.jivesoftware.spark.plugin.Plugin)2 PluginDependency (org.jivesoftware.spark.plugin.PluginDependency)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 JarFile (java.util.jar.JarFile)1 ZipFile (java.util.zip.ZipFile)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1 VerticalFlowLayout (org.jivesoftware.spark.component.VerticalFlowLayout)1 SwingWorker (org.jivesoftware.spark.util.SwingWorker)1 EasySSLProtocolSocketFactory (org.jivesoftware.sparkimpl.updater.EasySSLProtocolSocketFactory)1