From 7becd91a8dfab2c2c39ea82f047e386eb0d1cf3b Mon Sep 17 00:00:00 2001 From: Wolf Posdorfer Date: Wed, 15 Jun 2011 06:37:12 +0000 Subject: [PATCH] the plugin repository can now be configure in default.properties for a sample structure of how the plugin-repository must look like see documentation/sample_plugin_repository.xml git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12484 b35dd754-fafc-0310-a699-88a17e54d16e --- documentation/sample_plugin_repository.xml | 28 +++++++++ .../org/jivesoftware/resource/Default.java | 2 +- .../jivesoftware/resource/default.properties | 10 +++- .../org/jivesoftware/spark/PluginManager.java | 41 +++++++------ .../spark/plugin/PublicPlugin.java | 20 +++---- .../sparkimpl/plugin/viewer/PluginViewer.java | 58 +++++++++++-------- .../sparkimpl/plugin/viewer/SparkPlugUI.java | 26 +++++---- 7 files changed, 117 insertions(+), 68 deletions(-) create mode 100644 documentation/sample_plugin_repository.xml diff --git a/documentation/sample_plugin_repository.xml b/documentation/sample_plugin_repository.xml new file mode 100644 index 000000000..e1892095d --- /dev/null +++ b/documentation/sample_plugin_repository.xml @@ -0,0 +1,28 @@ + + + Testplugin1 + 1.0 + Some Guy + http://www.jivesoftware.com + someguy@somewebsite.com + Used for doing stuff + org.jivesoftware.spark.test.plugin.stuff + 2.6.0 + http://localhost/test.jar + http://www.google.de/search?q=changelog + http://www.google.de/search?q=readme + + + Other Plugin + 1.0 + Joe Mamma + http://www.jivesoftware.com + Joe@Mama.com + Adds some weird features you dont want + org.weird.feature.class.mainclass + 2.6.0 + http://localhost/test.jar + http://www.google.de/search?q=changelog + http://www.google.de/search?q=readme + + \ No newline at end of file diff --git a/src/java/org/jivesoftware/resource/Default.java b/src/java/org/jivesoftware/resource/Default.java index b72a749ec..292637eac 100644 --- a/src/java/org/jivesoftware/resource/Default.java +++ b/src/java/org/jivesoftware/resource/Default.java @@ -98,7 +98,7 @@ public class Default { } public static boolean getBoolean(String propertyName) { - return getString(propertyName).equals("true"); + return getString(propertyName).replace(" ","").equals("true"); } public static ImageIcon getImageIcon(String imageName) { diff --git a/src/java/org/jivesoftware/resource/default.properties b/src/java/org/jivesoftware/resource/default.properties index 3b9f40bf5..c18795825 100644 --- a/src/java/org/jivesoftware/resource/default.properties +++ b/src/java/org/jivesoftware/resource/default.properties @@ -114,7 +114,15 @@ HELP_FORUM_TEXT = ################ Plugins ################ ################################################# - +# This is the default location where Plugins can be downloaded from +# for a sample structure see trunk/documentation/sample_plugin_repository.xml +# default: http://www.igniterealtime.org/updater/plugins.jsp +PLUGIN_REPOSITORY = http://www.igniterealtime.org/updater/plugins.jsp +# Use Sparks global Proxy to connect to the repository? +# if your repository lies within your network, this probably needs to be disabled +# default: true +PLUGIN_REPOSITORY_USE_PROXY = true +#http://www.igniterealtime.org/updater/plugins.jsp # Disable Installing of Plugins # set true if you want to disable installing of Plugins INSTALL_PLUGINS_DISABLED = diff --git a/src/java/org/jivesoftware/spark/PluginManager.java b/src/java/org/jivesoftware/spark/PluginManager.java index fef58eaf0..b7d25e8f6 100644 --- a/src/java/org/jivesoftware/spark/PluginManager.java +++ b/src/java/org/jivesoftware/spark/PluginManager.java @@ -767,30 +767,29 @@ public class PluginManager implements MainWindowListener { * @throws Exception thrown if there was a problem loading the plugin. */ public void addPlugin(PublicPlugin plugin) throws Exception { - expandNewPlugins(); + expandNewPlugins(); - URL url = new URL(plugin.getDownloadURL()); - String name = URLFileSystem.getName(url); - File pluginDownload = new File(PluginManager.PLUGINS_DIRECTORY, name); + URL url = new URL(plugin.getDownloadURL()); + String name = URLFileSystem.getName(url); + File pluginDownload = new File(PluginManager.PLUGINS_DIRECTORY, name); - ((PluginClassLoader)getParentClassLoader()).addPlugin(pluginDownload); - - pluginClass = loadPublicPlugin(pluginDownload); - - try { - EventQueue.invokeAndWait(new Runnable() { - @Override - public void run() { + ((PluginClassLoader) getParentClassLoader()).addPlugin(pluginDownload); + + pluginClass = loadPublicPlugin(pluginDownload); + + try { + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + + Log.debug("Trying to initialize " + pluginClass); + pluginClass.initialize(); + } + }); + } catch (Exception e) { + Log.error(e); + } - Log.debug("Trying to initialize " + pluginClass); - pluginClass.initialize(); - } - }); - } - catch(Exception e){ - Log.error(e); - } - } /** diff --git a/src/java/org/jivesoftware/spark/plugin/PublicPlugin.java b/src/java/org/jivesoftware/spark/plugin/PublicPlugin.java index 79accf6f9..bca2c719a 100644 --- a/src/java/org/jivesoftware/spark/plugin/PublicPlugin.java +++ b/src/java/org/jivesoftware/spark/plugin/PublicPlugin.java @@ -32,8 +32,8 @@ public class PublicPlugin { private String description; private String homePage; private String downloadURL; - private boolean changeLogAvailable; - private boolean readMeAvailable; + private String changeLogURL; + private String readMeURL; private boolean smallIconAvailable; private boolean largeIconAvailable; private String minVersion; @@ -112,20 +112,20 @@ public class PublicPlugin { this.downloadURL = downloadURL; } - public boolean isChangeLogAvailable() { - return changeLogAvailable; + public String getChangeLog() { + return changeLogURL; } - public void setChangeLogAvailable(boolean changeLogAvailable) { - this.changeLogAvailable = changeLogAvailable; + public void setChangeLogURL(String changeLogURL) { + this.changeLogURL = changeLogURL; } - public boolean isReadMeAvailable() { - return readMeAvailable; + public String getReadMeURL() { + return readMeURL; } - public void setReadMeAvailable(boolean readMeAvailable) { - this.readMeAvailable = readMeAvailable; + public void setReadMeURL(String readMeURL) { + this.readMeURL = readMeURL; } public boolean isSmallIconAvailable() { diff --git a/src/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java b/src/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java index bd07ddd0b..06a5a0766 100644 --- a/src/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java +++ b/src/java/org/jivesoftware/sparkimpl/plugin/viewer/PluginViewer.java @@ -52,6 +52,7 @@ import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; +import javax.swing.JViewport; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -93,7 +94,7 @@ public class PluginViewer extends JPanel implements Plugin { private boolean loaded = false; - private String retrieveListURL = "http://www.igniterealtime.org/updater/plugins.jsp"; + private String retrieveListURL = Default.getString("PLUGIN_REPOSITORY"); private JProgressBar progressBar; @@ -145,7 +146,8 @@ public class PluginViewer extends JPanel implements Plugin { tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { - if (tabbedPane.getSelectedIndex() == 1) { + if (tabbedPane.getSelectedComponent().equals( + ((JViewport)availablePanel.getParent()).getParent())) { loadAvailablePlugins(); loaded = true; } @@ -278,14 +280,18 @@ public class PluginViewer extends JPanel implements Plugin { // Get HTTP client Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); final HttpClient httpclient = new HttpClient(); - 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); + + 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); + } } } @@ -346,14 +352,18 @@ public class PluginViewer extends JPanel implements Plugin { final HttpClient httpclient = new HttpClient(); 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); - } - } + + if (Default.getBoolean("PLUGIN_REPOSITORY_USE_PROXY")) { + if (ModelUtil.hasLength(proxyHost) + && ModelUtil.hasLength(proxyPort)) { + try { + httpclient.getHostConfiguration().setProxy(proxyHost, + Integer.parseInt(proxyPort)); + } catch (NumberFormatException e) { + Log.error(e); + } + } + } // Execute request @@ -514,14 +524,14 @@ public class PluginViewer extends JPanel implements Plugin { publicPlugin.setDownloadURL(downloadURL); } - Node changeLog = plugin.selectSingleNode("changeLog"); - if (changeLog != null) { - publicPlugin.setChangeLogAvailable(true); + Node changeLogNode = plugin.selectSingleNode("changeLog"); + if (changeLogNode != null) { + publicPlugin.setChangeLogURL(changeLogNode.getText()); } - Node readMe = plugin.selectSingleNode("readme"); - if (readMe != null) { - publicPlugin.setReadMeAvailable(true); + Node readMeNode = plugin.selectSingleNode("readme"); + if (readMeNode != null) { + publicPlugin.setReadMeURL(readMeNode.getText()); } Node smallIcon = plugin.selectSingleNode("smallIcon"); diff --git a/src/java/org/jivesoftware/sparkimpl/plugin/viewer/SparkPlugUI.java b/src/java/org/jivesoftware/sparkimpl/plugin/viewer/SparkPlugUI.java index 6cb74a6c8..6d7e2da3c 100644 --- a/src/java/org/jivesoftware/sparkimpl/plugin/viewer/SparkPlugUI.java +++ b/src/java/org/jivesoftware/sparkimpl/plugin/viewer/SparkPlugUI.java @@ -51,12 +51,12 @@ import org.jivesoftware.spark.util.log.Log; public class SparkPlugUI extends JPanel { private static final long serialVersionUID = -4206533328807591854L; - private PublicPlugin plugin; + private PublicPlugin _plugin; private final JButton installButton = new JButton(); private JLabel imageIcon = new JLabel(); public SparkPlugUI(PublicPlugin plugin) { - this.plugin = plugin; + _plugin = plugin; setLayout(new GridBagLayout()); setBackground(Color.white); @@ -78,8 +78,8 @@ public class SparkPlugUI extends JPanel { titleLabel.setText(plugin.getName()); if (plugin.getVersion() != null && plugin.getAuthor() != null) { - versionLabel.setText(plugin.getVersion() + " by " - + plugin.getAuthor()); + versionLabel.setText(_plugin.getVersion() + " by " + + _plugin.getAuthor()); } descriptionLabel.setText(plugin.getDescription()); @@ -87,7 +87,7 @@ public class SparkPlugUI extends JPanel { add(installButton, new GridBagConstraints(4, 0, 1, 2, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0)); - if (plugin.isChangeLogAvailable() && plugin.isReadMeAvailable()) { + if (_plugin.getChangeLog()!=null && _plugin.getReadMeURL() != null) { RolloverButton changeLogButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.CHANGELOG_IMAGE)); RolloverButton readMeButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.README_IMAGE)); @@ -95,7 +95,7 @@ public class SparkPlugUI extends JPanel { changeLogButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { - BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&changeLog=true"); + BrowserLauncher.openURL(_plugin.getChangeLog()); } catch (Exception e1) { Log.error(e1); @@ -106,7 +106,7 @@ public class SparkPlugUI extends JPanel { readMeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { - BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&readme=true"); + BrowserLauncher.openURL(_plugin.getReadMeURL()); } catch (Exception e1) { Log.error(e1); @@ -134,7 +134,7 @@ public class SparkPlugUI extends JPanel { public void showOperationButton() { final PluginManager pluginManager = PluginManager.getInstance(); - if (!pluginManager.isInstalled(plugin)) { + if (!pluginManager.isInstalled(_plugin)) { installButton.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_ADD_IMAGE)); } else { @@ -165,7 +165,7 @@ public class SparkPlugUI extends JPanel { public PublicPlugin getPlugin() { - return plugin; + return _plugin; } public JButton getInstallButton() { @@ -173,7 +173,7 @@ public class SparkPlugUI extends JPanel { } public void useLocalIcon() { - File pluginDIR = plugin.getPluginDir(); + File pluginDIR = _plugin.getPluginDir(); try { File smallIcon = new File(pluginDIR, "logo_small.gif"); File largeIcon = new File(pluginDIR, "logo_large.gif"); @@ -190,10 +190,14 @@ public class SparkPlugUI extends JPanel { } + /** + * Returns the Filename of provided Download URL + * @return + */ public String getFilename() { String filename = null; try { - URL downloadURL = new URL(plugin.getDownloadURL()); + URL downloadURL = new URL(_plugin.getDownloadURL()); filename = URLFileSystem.getFileName(downloadURL); } catch (MalformedURLException e) {