/**
* The system version used for comparisons to the plugin requires attribute.
*/
- private PluginVersion systemVersion = PluginVersion.DEFAULT;
+ private PluginVersion systemVersion = PluginVersion.ZERO;
/**
* The plugins directory is supplied by System.getProperty("pf4j.pluginsDir", "plugins").
}
PluginWrapper pluginWrapper = getPlugin(pluginId);
+ if (!isPluginValid(pluginWrapper)) {
+ log.warn("Plugin '{}:{}' can not be enabled",
+ pluginWrapper.getPluginId(),
+ pluginWrapper.getDescriptor().getVersion());
+ return false;
+ }
+
PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
PluginState pluginState = pluginWrapper.getPluginState();
if (PluginState.DISABLED != pluginState) {
- log.debug("Plugin plugin '{}:{}' is not disabled", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion());
+ log.debug("Plugin '{}:{}' is not disabled", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion());
return true;
}
- PluginVersion requires = pluginWrapper.getDescriptor().getRequires();
- PluginVersion system = getSystemVersion();
- if (!system.isDefault() && !system.atLeast(requires)) {
- log.warn(String.format("Failed to enable plugin `{}:{}` because it requires a minimum system version of %s",
- pluginWrapper.getPluginId(),
- pluginWrapper.getDescriptor().getVersion(),
- requires));
- return false;
- }
-
try {
if (disabledPlugins.remove(pluginId)) {
FileUtils.writeLines(disabledPlugins, new File(pluginsDirectory, "disabled.txt"));
return !enabledPlugins.contains(pluginId);
}
+ protected boolean isPluginValid(PluginWrapper pluginWrapper) {
+ PluginVersion requires = pluginWrapper.getDescriptor().getRequires();
+ PluginVersion system = getSystemVersion();
+ if (system.isZero() || system.atLeast(requires)) {
+ return true;
+ }
+
+ log.warn(String.format("Plugin '%s:%s' requires a minimum system version of %s",
+ pluginWrapper.getPluginId(),
+ pluginWrapper.getDescriptor().getVersion(),
+ requires));
+ return false;
+ }
+
protected FileFilter createHiddenPluginFilter() {
return new HiddenFilter();
}
pluginWrapper.setPluginState(PluginState.DISABLED);
}
- // optionally enforce minimum system version requirements
- PluginVersion requires = pluginWrapper.getDescriptor().getRequires();
- PluginVersion system = getSystemVersion();
- if (!system.isDefault() && !system.atLeast(requires)) {
- log.warn(String.format("Disabling plugin '%s:%s' because it requires a minimum system version of %s",
- pluginWrapper.getPluginId(),
- pluginWrapper.getDescriptor().getVersion(),
- requires));
- pluginWrapper.setPluginState(PluginState.DISABLED);
- disabledPlugins.add(pluginWrapper.getPluginId());
+ // validate the plugin
+ if (!isPluginValid(pluginWrapper)) {
+ log.info("Plugin '{}' is disabled", pluginPath);
+ pluginWrapper.setPluginState(PluginState.DISABLED);
}
log.debug("Created wrapper '{}' for plugin '{}'", pluginWrapper, pluginPath);
*/
public class PluginVersion implements Comparable<PluginVersion> {
- public static final PluginVersion DEFAULT = new PluginVersion(0, 0, 0);
+ public static final PluginVersion ZERO = new PluginVersion(0, 0, 0);
private static final String FORMAT = "(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?";
private static final Pattern PATTERN = Pattern.compile(FORMAT);
return 0;
}
- public boolean isDefault() {
- return compareTo(DEFAULT) == 0;
+ public boolean isZero() {
+ return compareTo(ZERO) == 0;
}
public boolean atLeast(PluginVersion v) {
return compareTo(v) <= 0;
}
+ public boolean exceeds(PluginVersion v) {
+ return compareTo(v) > 0;
+ }
+
// for test only
public static void main(String[] args) {
PluginVersion v = PluginVersion.createVersion("1.2.3-SNAPSHOT");