I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3d2d6046 authored by zzz's avatar zzz
Browse files

* Plugins:

    - Only stop a plugin before update if it was running
    - Don't start a plugin after update if it was disabled
    - Disable plugin if it fails version checks at startup
parent b5d77685
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,7 @@ public class PluginStarter implements Runnable {
File pluginDir = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName);
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
log.error("Cannot start nonexistent plugin: " + appName);
disablePlugin(appName);
return false;
}
......@@ -104,6 +105,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(CoreVersion.VERSION, minVersion) < 0) {
String foo = "Plugin " + appName + " requires I2P version " + minVersion + " or higher";
log.error(foo);
disablePlugin(appName);
throw new Exception(foo);
}
......@@ -112,6 +114,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(System.getProperty("java.version"), minVersion) < 0) {
String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher";
log.error(foo);
disablePlugin(appName);
throw new Exception(foo);
}
......@@ -121,6 +124,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(minVersion, jVersion) > 0) {
String foo = "Plugin " + appName + " requires Jetty version " + minVersion + " or higher";
log.error(foo);
disablePlugin(appName);
throw new Exception(foo);
}
......@@ -129,6 +133,7 @@ public class PluginStarter implements Runnable {
(new VersionComparator()).compare(maxVersion, jVersion) < 0) {
String foo = "Plugin " + appName + " requires Jetty version " + maxVersion + " or lower";
log.error(foo);
disablePlugin(appName);
throw new Exception(foo);
}
......@@ -334,7 +339,7 @@ public class PluginStarter implements Runnable {
Properties props = pluginProperties();
for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
if (name.startsWith(PREFIX + appName))
if (name.startsWith(PREFIX + appName + '.'))
iter.remove();
}
storePluginProperties(props);
......@@ -373,6 +378,32 @@ public class PluginStarter implements Runnable {
return rv;
}
/**
* Is the plugin enabled in plugins.config?
* Default true
*
* @since 0.8.13
*/
public static boolean isPluginEnabled(String appName) {
Properties props = pluginProperties();
String prop = PREFIX + appName + ENABLED;
return Boolean.valueOf(props.getProperty(prop, "true")).booleanValue();
}
/**
* Disable in plugins.config
*
* @since 0.8.13
*/
public static void disablePlugin(String appName) {
Properties props = pluginProperties();
String prop = PREFIX + appName + ENABLED;
if (Boolean.valueOf(props.getProperty(prop, "true")).booleanValue()) {
props.setProperty(prop, "false");
storePluginProperties(props);
}
}
/**
* all installed plugins whether enabled or not
*/
......
......@@ -286,6 +286,7 @@ public class PluginUpdateHandler extends UpdateHandler {
return;
}
boolean wasRunning = false;
File destDir = new SecureDirectory(appDir, appName);
if (destDir.exists()) {
if (Boolean.valueOf(props.getProperty("install-only")).booleanValue()) {
......@@ -350,14 +351,16 @@ public class PluginUpdateHandler extends UpdateHandler {
return;
}
// check if it is running first?
try {
if (!PluginStarter.stopPlugin(_context, appName)) {
// failed, ignore
if (PluginStarter.isPluginRunning(appName, _context)) {
wasRunning = true;
try {
if (!PluginStarter.stopPlugin(_context, appName)) {
// failed, ignore
}
} catch (Throwable e) {
// no updateStatus() for this one
_log.error("Error stopping plugin " + appName, e);
}
} catch (Throwable e) {
// no updateStatus() for this one
_log.error("Error stopping plugin " + appName, e);
}
} else {
......@@ -390,8 +393,8 @@ public class PluginUpdateHandler extends UpdateHandler {
pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false");
PluginStarter.storePluginProperties(pluginProps);
}
} else {
// start everything
} else if (wasRunning || PluginStarter.isPluginEnabled(appName)) {
// start everything unless it was disabled and not running before
try {
if (PluginStarter.startPlugin(_context, appName)) {
String linkName = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(_context));
......@@ -411,6 +414,8 @@ public class PluginUpdateHandler extends UpdateHandler {
statusDone("<b>" + _("Plugin {0} installed but failed to start", appName) + ": " + e + "</b>");
_log.error("Error starting plugin " + appName, e);
}
} else {
statusDone("<b>" + _("Plugin {0} installed", appName) + "</b>");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment