Search in sources :

Example 1 with PublicPlugin

use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.

the class PluginViewer method loadInstalledPlugins.

private void loadInstalledPlugins() {
    PluginManager pluginManager = PluginManager.getInstance();
    List<PublicPlugin> plugins = pluginManager.getPublicPlugins();
    for (Object plugin1 : plugins) {
        PublicPlugin plugin = (PublicPlugin) plugin1;
        final SparkPlugUI ui = new SparkPlugUI(plugin);
        ui.useLocalIcon();
        installedPanel.add(ui);
        addSparkPlugUIListener(ui);
    }
}
Also used : PluginManager(org.jivesoftware.spark.PluginManager) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin)

Example 2 with PublicPlugin

use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.

the class PluginViewer method getPluginList.

public Collection<PublicPlugin> getPluginList(InputStream response) {
    final List<PublicPlugin> pluginList = new ArrayList<>();
    SAXReader saxReader = new SAXReader();
    Document pluginXML = null;
    try {
        pluginXML = saxReader.read(response);
    } catch (DocumentException e) {
        Log.error(e);
    }
    List<? extends Node> plugins = pluginXML.selectNodes("/plugins/plugin");
    for (Node plugin1 : plugins) {
        PublicPlugin publicPlugin = new PublicPlugin();
        String clazz;
        String name = null;
        try {
            Element plugin = (Element) plugin1;
            try {
                String version = plugin.selectSingleNode("minSparkVersion").getText();
                if (!isGreaterOrEqual(JiveInfo.getVersion(), version)) {
                    Log.error("Unable to load plugin " + name + " due to min version incompatibility.");
                    continue;
                }
            } catch (Exception e) {
                Log.error("Unable to load plugin " + name + " due to no minSparkVersion.");
                continue;
            }
            name = plugin.selectSingleNode("name").getText();
            clazz = plugin.selectSingleNode("class").getText();
            publicPlugin.setPluginClass(clazz);
            publicPlugin.setName(name);
            try {
                String version = plugin.selectSingleNode("version").getText();
                publicPlugin.setVersion(version);
                String author = plugin.selectSingleNode("author").getText();
                publicPlugin.setAuthor(author);
                Node emailNode = plugin.selectSingleNode("email");
                if (emailNode != null) {
                    publicPlugin.setEmail(emailNode.getText());
                }
                Node descriptionNode = plugin.selectSingleNode("description");
                if (descriptionNode != null) {
                    publicPlugin.setDescription(descriptionNode.getText());
                }
                Node homePageNode = plugin.selectSingleNode("homePage");
                if (homePageNode != null) {
                    publicPlugin.setHomePage(homePageNode.getText());
                }
                Node downloadNode = plugin.selectSingleNode("downloadURL");
                if (downloadNode != null) {
                    String downloadURL = downloadNode.getText();
                    publicPlugin.setDownloadURL(downloadURL);
                }
                Node changeLogNode = plugin.selectSingleNode("changeLog");
                if (changeLogNode != null) {
                    publicPlugin.setChangeLogURL(changeLogNode.getText());
                }
                Node readMeNode = plugin.selectSingleNode("readme");
                if (readMeNode != null) {
                    publicPlugin.setReadMeURL(readMeNode.getText());
                }
                Node smallIcon = plugin.selectSingleNode("smallIcon");
                if (smallIcon != null) {
                    publicPlugin.setSmallIconAvailable(true);
                }
                Node largeIcon = plugin.selectSingleNode("largeIcon");
                if (largeIcon != null) {
                    publicPlugin.setLargeIconAvailable(true);
                }
            } catch (Exception e) {
                Log.error("Error retrieving PluginInformation from xml.", e);
            }
            pluginList.add(publicPlugin);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return pluginList;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Node(org.dom4j.Node) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException)

Example 3 with PublicPlugin

use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.

the class PluginViewer method loadDeactivatedPlugins.

/**
 * Initializes the Deactivated Plugins Tab
 */
private void loadDeactivatedPlugins() {
    deactivatedPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
    if (!Default.getBoolean(Default.DEINSTALL_PLUGINS_DISABLED)) {
        tabbedPane.addTab(Res.getString("tab.deactivated.plugins"), new JScrollPane(deactivatedPanel));
    }
    for (final String s : _deactivatedPlugins) {
        PublicPlugin plg = new PublicPlugin();
        plg.setName(s);
        final SparkPlugUI ui = new SparkPlugUI(plg);
        ui.useLocalIcon();
        deactivatedPanel.add(ui);
        addDeactivatedListener(ui);
    }
}
Also used : PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) VerticalFlowLayout(org.jivesoftware.spark.component.VerticalFlowLayout)

Example 4 with PublicPlugin

use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.

the class PluginViewer method loadAvailablePlugins.

private void loadAvailablePlugins() {
    availablePanel.removeAll();
    availablePanel.invalidate();
    availablePanel.validate();
    availablePanel.repaint();
    JLabel label = new JLabel(Res.getString("message.loading.please.wait"));
    availablePanel.add(label);
    SwingWorker worker = new SwingWorker() {

        Collection<PublicPlugin> pluginList = null;

        public Object construct() {
            // Prepare HTTP post
            final GetMethod post = new GetMethod(retrieveListURL);
            // Get HTTP client
            Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));
            final HttpClient httpclient = new HttpClient();
            if (Default.getBoolean("PLUGIN_REPOSITORY_USE_PROXY")) {
                String proxyHost = System.getProperty("http.proxyHost");
                String proxyPort = System.getProperty("http.proxyPort");
                if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) {
                    try {
                        httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort));
                    } catch (NumberFormatException e) {
                        Log.error(e);
                    }
                }
            }
            try {
                int result = httpclient.executeMethod(post);
                if (result != 200) {
                    return null;
                }
                pluginList = getPluginList(post.getResponseBodyAsStream());
            } catch (Exception ex) {
            // Nothing to do
            }
            return "ok";
        }

        public void finished() {
            final PluginManager pluginManager = PluginManager.getInstance();
            if (pluginList == null) {
                availablePanel.removeAll();
                availablePanel.invalidate();
                availablePanel.validate();
                availablePanel.repaint();
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(availablePanel, Res.getString("message.plugins.not.available"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            Iterator<PublicPlugin> plugs = pluginList.iterator();
            availablePanel.removeAll();
            while (plugs.hasNext()) {
                PublicPlugin plugin = plugs.next();
                if (!pluginManager.isInstalled(plugin)) {
                    SparkPlugUI ui = new SparkPlugUI(plugin);
                    availablePanel.add(ui);
                    addSparkPlugUIListener(ui);
                }
            }
            availablePanel.invalidate();
            availablePanel.validate();
            availablePanel.repaint();
        }
    };
    worker.start();
}
Also used : PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) DocumentException(org.dom4j.DocumentException) EasySSLProtocolSocketFactory(org.jivesoftware.sparkimpl.updater.EasySSLProtocolSocketFactory) PluginManager(org.jivesoftware.spark.PluginManager) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Protocol(org.apache.commons.httpclient.protocol.Protocol)

Example 5 with PublicPlugin

use of org.jivesoftware.spark.plugin.PublicPlugin in project Spark by igniterealtime.

the class PluginManager method loadPublicPlugin.

/**
 * Loads public plugins.
 *
 * @param pluginDir the directory of the expanded public plugin.
 * @return the new Plugin model for the Public Plugin.
 */
private Plugin loadPublicPlugin(File pluginDir) {
    File pluginFile = new File(pluginDir, "plugin.xml");
    SAXReader saxReader = new SAXReader();
    Document pluginXML = null;
    try {
        pluginXML = saxReader.read(pluginFile);
    } catch (DocumentException e) {
        Log.error("Unable to read plugin XML file from " + pluginDir, e);
    }
    Plugin pluginClass = null;
    List<? extends Node> plugins = pluginXML.selectNodes("/plugin");
    for (Node plugin : plugins) {
        PublicPlugin publicPlugin = new PublicPlugin();
        String clazz = null;
        String name;
        String minVersion;
        try {
            name = plugin.selectSingleNode("name").getText();
            clazz = plugin.selectSingleNode("class").getText();
            try {
                String lower = name.replaceAll("[^0-9a-zA-Z]", "").toLowerCase();
                // Dont load the plugin if its on the Blacklist
                if (_blacklistPlugins.contains(lower) || _blacklistPlugins.contains(clazz) || SettingsManager.getLocalPreferences().getDeactivatedPlugins().contains(name)) {
                    return null;
                }
            } catch (Exception e) {
                Log.warning("An exception occurred while checking the plugin blacklist for " + name, e);
                return null;
            }
            // Check for minimum Spark version
            try {
                minVersion = plugin.selectSingleNode("minSparkVersion").getText();
                String buildNumber = JiveInfo.getVersion();
                boolean ok = buildNumber.compareTo(minVersion) >= 0;
                if (!ok) {
                    return null;
                }
            } catch (Exception e) {
                Log.error("Unable to load plugin " + name + " due to missing <minSparkVersion>-Tag in plugin.xml.");
                return null;
            }
            // Check for minimum Java version
            try {
                String javaversion = plugin.selectSingleNode("java").getText().replaceAll("[^0-9]", "");
                javaversion = javaversion == null ? "0" : javaversion;
                int jv = Integer.parseInt(attachMissingZero(javaversion));
                String myversion = System.getProperty("java.version").replaceAll("[^0-9]", "");
                int mv = Integer.parseInt(attachMissingZero(myversion));
                boolean ok = (mv >= jv);
                if (!ok) {
                    Log.error("Unable to load plugin " + name + " due to old JavaVersion.\n" + "It Requires " + plugin.selectSingleNode("java").getText() + " you have " + System.getProperty("java.version"));
                    return null;
                }
            } catch (NullPointerException e) {
                Log.warning("Plugin " + name + " has no <java>-Tag, consider getting a newer Version");
            }
            // set dependencies
            try {
                List<? extends Node> dependencies = plugin.selectNodes("depends/plugin");
                for (Node depend1 : dependencies) {
                    Element depend = (Element) depend1;
                    PluginDependency dependency = new PluginDependency();
                    dependency.setVersion(depend.selectSingleNode("version").getText());
                    dependency.setName(depend.selectSingleNode("name").getText());
                    publicPlugin.addDependency(dependency);
                }
            } catch (Exception e) {
                Log.warning("An exception occurred during the setting of dependencies while loading plugin " + name, e);
            }
            // Do operating system check.
            boolean operatingSystemOK = isOperatingSystemOK(plugin);
            if (!operatingSystemOK) {
                return null;
            }
            publicPlugin.setPluginClass(clazz);
            publicPlugin.setName(name);
            try {
                String version = plugin.selectSingleNode("version").getText();
                publicPlugin.setVersion(version);
                String author = plugin.selectSingleNode("author").getText();
                publicPlugin.setAuthor(author);
                String email = plugin.selectSingleNode("email").getText();
                publicPlugin.setEmail(email);
                String description = plugin.selectSingleNode("description").getText();
                publicPlugin.setDescription(description);
                String homePage = plugin.selectSingleNode("homePage").getText();
                publicPlugin.setHomePage(homePage);
            } catch (Exception e) {
                Log.debug("An ignorable exception occurred while loading plugin " + name + ": " + e.getMessage());
            }
            try {
                pluginClass = (Plugin) getParentClassLoader().loadClass(clazz).newInstance();
                Log.debug(name + " has been loaded.");
                publicPlugin.setPluginDir(pluginDir);
                publicPlugins.add(publicPlugin);
                registerPlugin(pluginClass);
            } catch (Throwable e) {
                Log.error("Unable to load plugin " + clazz + ".", e);
            }
        } catch (Exception ex) {
            Log.error("Unable to load plugin " + clazz + ".", ex);
        }
    }
    return pluginClass;
}
Also used : PluginDependency(org.jivesoftware.spark.plugin.PluginDependency) SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) Element(org.dom4j.Element) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) MalformedURLException(java.net.MalformedURLException) DocumentException(org.dom4j.DocumentException) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Plugin(org.jivesoftware.spark.plugin.Plugin)

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