diff options
author | James Moger <james.moger@gitblit.com> | 2014-04-15 08:33:05 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-04-15 08:33:05 -0400 |
commit | 027267ac5fac0f205f5cca3fac0c57ce013bbc3e (patch) | |
tree | 6ec87cf1114efb56b935d3c9ac6ba84971b5c896 /src/main/java/com/gitblit/transport | |
parent | cc26656d8deaf8ebe552897480240a7665b0fb76 (diff) | |
download | gitblit-027267ac5fac0f205f5cca3fac0c57ce013bbc3e.tar.gz gitblit-027267ac5fac0f205f5cca3fac0c57ce013bbc3e.zip |
Enforce plugin-requires attribute
Diffstat (limited to 'src/main/java/com/gitblit/transport')
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java index 70dc5130..37649ead 100644 --- a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java @@ -27,6 +27,7 @@ import ro.fortsoft.pf4j.PluginDependency; import ro.fortsoft.pf4j.PluginDescriptor; import ro.fortsoft.pf4j.PluginState; import ro.fortsoft.pf4j.PluginWrapper; +import ro.fortsoft.pf4j.Version; import com.gitblit.manager.IGitblit; import com.gitblit.models.PluginRegistry.InstallState; @@ -35,6 +36,7 @@ import com.gitblit.models.PluginRegistry.PluginRelease; import com.gitblit.models.UserModel; import com.gitblit.utils.FlipTable; import com.gitblit.utils.FlipTable.Borders; +import com.gitblit.utils.StringUtils; import com.google.common.base.Joiner; /** @@ -519,11 +521,24 @@ public class PluginDispatcher extends DispatchCommand { new UnloggedFailure(1, String.format("Failed to install %s", urlOrId)); } } else { - PluginRelease pv = gitblit.lookupRelease(urlOrId, version); - if (pv == null) { - throw new Failure(1, String.format("Plugin \"%s\" is not in the registry!", urlOrId)); + PluginRelease pr = gitblit.lookupRelease(urlOrId, version); + if (pr == null) { + throw new UnloggedFailure(1, String.format("Plugin \"%s\" is not in the registry!", urlOrId)); } - if (gitblit.installPlugin(pv.url, !disableChecksum)) { + + // enforce minimum system requirement + if (!StringUtils.isEmpty(pr.requires)) { + Version requires = Version.createVersion(pr.requires); + Version system = gitblit.getSystemVersion(); + boolean isValid = system.isZero() || system.atLeast(requires); + if (!isValid) { + String msg = String.format("Plugin \"%s:%s\" requires Gitblit %s", + urlOrId, pr.version, pr.requires); + throw new UnloggedFailure(1, msg); + } + } + + if (gitblit.installPlugin(pr.url, !disableChecksum)) { stdout.println(String.format("Installed %s", urlOrId)); } else { throw new UnloggedFailure(1, String.format("Failed to install %s", urlOrId)); @@ -556,13 +571,24 @@ public class PluginDispatcher extends DispatchCommand { throw new UnloggedFailure("Invalid plugin specified!"); } - PluginRelease pv = gitblit.lookupRelease(pluginWrapper.getPluginId(), version); - if (pv == null) { + PluginRelease pr = gitblit.lookupRelease(pluginWrapper.getPluginId(), version); + if (pr == null) { throw new UnloggedFailure(1, String.format("Plugin \"%s\" is not in the registry!", pluginWrapper.getPluginId())); } + // enforce minimum system requirement + if (!StringUtils.isEmpty(pr.requires)) { + Version requires = Version.createVersion(pr.requires); + Version system = gitblit.getSystemVersion(); + boolean isValid = system.isZero() || system.atLeast(requires); + if (!isValid) { + throw new Failure(1, String.format("Plugin \"%s:%s\" requires Gitblit %s", + pluginWrapper.getPluginId(), pr.version, pr.requires)); + } + } + try { - if (gitblit.upgradePlugin(pluginWrapper.getPluginId(), pv.url, !disableChecksum)) { + if (gitblit.upgradePlugin(pluginWrapper.getPluginId(), pr.url, !disableChecksum)) { stdout.println(String.format("Upgraded %s", pluginWrapper.getPluginId())); } else { throw new UnloggedFailure(1, String.format("Failed to upgrade %s", pluginWrapper.getPluginId())); |