From 1ab67de677b71d66a8065025027f06e5b95bf44d Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 23 Mar 2017 14:55:56 +0000 Subject: [PATCH] Plugins: Blacklist i2pbote and BwSchedule Translate exceptions thrown from PluginStarter --- .../i2p/router/update/PluginUpdateRunner.java | 7 +++ .../src/net/i2p/router/web/PluginStarter.java | 43 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java index b4a7493b74..bd5525df26 100644 --- a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java +++ b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java @@ -457,6 +457,13 @@ class PluginUpdateRunner extends UpdateRunner { statusDone("" + _t("Plugin requires Jetty version {0} or higher", minVersion) + ""); return; } + String blacklistVersion = PluginStarter.jetty9Blacklist.get(appName); + if (blacklistVersion != null && + VersionComparator.comp(version, blacklistVersion) <= 0) { + to.delete(); + statusDone("" + _t("Plugin requires Jetty version {0} or lower", "8.9999") + ""); + return; + } maxVersion = ConfigClientsHelper.stripHTML(props, "max-jetty-version"); if (maxVersion != null && VersionComparator.comp(maxVersion, oldVersion) < 0) { diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java index 9c9c7e9ddc..c33f0e9267 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -67,6 +67,22 @@ public class PluginStarter implements Runnable { private static Map _clCache = new ConcurrentHashMap(); private static Map> pluginWars = new ConcurrentHashMap>(); + /** + * Plugin name to plugin version of plugins that do not work + * with Jetty 9, but do not have a max-jetty-version=8.9999 set. + * Unmodifiable. + * + * @since 0.9.30 + */ + public static final Map jetty9Blacklist; + + static { + Map map = new HashMap(4); + map.put("i2pbote", "0.4.5"); + map.put("BwSchedule", "0.0.36"); + jetty9Blacklist = Collections.unmodifiableMap(map); + } + public PluginStarter(RouterContext ctx) { _context = ctx; } @@ -297,8 +313,8 @@ public class PluginStarter implements Runnable { Properties props = pluginProperties(ctx, appName); - - + // For the following, we use the exact same translated strings as in PluginUpdateRunner + // to avoid duplication String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version"); if (minVersion != null && @@ -306,6 +322,7 @@ public class PluginStarter implements Runnable { String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher"; log.error(foo); disablePlugin(appName); + foo = gettext("This plugin requires I2P version {0} or higher", minVersion, ctx); throw new Exception(foo); } @@ -315,6 +332,7 @@ public class PluginStarter implements Runnable { String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher"; log.error(foo); disablePlugin(appName); + foo = gettext("This plugin requires Java version {0} or higher", minVersion, ctx); throw new Exception(foo); } @@ -325,6 +343,18 @@ public class PluginStarter implements Runnable { String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher"; log.error(foo); disablePlugin(appName); + foo = gettext("Plugin requires Jetty version {0} or higher", minVersion, ctx); + throw new Exception(foo); + } + + String blacklistVersion = jetty9Blacklist.get(appName); + String curVersion = ConfigClientsHelper.stripHTML(props, "version"); + if (blacklistVersion != null && + VersionComparator.comp(curVersion, blacklistVersion) <= 0) { + String foo = "Plugin " + appName + " requires Jetty version 8.9999 or lower"; + log.error(foo); + disablePlugin(appName); + foo = gettext("Plugin requires Jetty version {0} or lower", "8.9999", ctx); throw new Exception(foo); } @@ -334,6 +364,7 @@ public class PluginStarter implements Runnable { String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower"; log.error(foo); disablePlugin(appName); + foo = gettext("Plugin requires Jetty version {0} or lower", maxVersion, ctx); throw new Exception(foo); } @@ -1002,6 +1033,14 @@ public class PluginStarter implements Runnable { method.invoke(urlClassLoader, new Object[]{u}); } + /** + * translate a string + * @since 0.9.30 + */ + private static String gettext(String s, Object o, I2PAppContext ctx) { + return Messages.getString(s, o, ctx); + } + /** translate a string */ private static String ngettext(String s, String p, int n, I2PAppContext ctx) { return Messages.getString(n, s, p, ctx);