diff options
Diffstat (limited to 'src/main/java/com/gitblit')
4 files changed, 65 insertions, 10 deletions
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java index 56a71d41..4ecb9c6d 100644 --- a/src/main/java/com/gitblit/manager/GitblitManager.java +++ b/src/main/java/com/gitblit/manager/GitblitManager.java @@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory; import ro.fortsoft.pf4j.PluginState; import ro.fortsoft.pf4j.PluginWrapper; +import ro.fortsoft.pf4j.Version; import com.gitblit.Constants; import com.gitblit.Constants.AccessPermission; @@ -1190,6 +1191,11 @@ public class GitblitManager implements IGitblit { */ @Override + public Version getSystemVersion() { + return pluginManager.getSystemVersion(); + } + + @Override public void startPlugins() { pluginManager.startPlugins(); } diff --git a/src/main/java/com/gitblit/manager/IPluginManager.java b/src/main/java/com/gitblit/manager/IPluginManager.java index 317cff73..bf04619c 100644 --- a/src/main/java/com/gitblit/manager/IPluginManager.java +++ b/src/main/java/com/gitblit/manager/IPluginManager.java @@ -20,6 +20,7 @@ import java.util.List; import ro.fortsoft.pf4j.PluginState; import ro.fortsoft.pf4j.PluginWrapper; +import ro.fortsoft.pf4j.Version; import com.gitblit.models.PluginRegistry.InstallState; import com.gitblit.models.PluginRegistry.PluginRegistration; @@ -28,6 +29,13 @@ import com.gitblit.models.PluginRegistry.PluginRelease; public interface IPluginManager extends IManager { /** + * Returns the system version. + * + * @return the system version + */ + Version getSystemVersion(); + + /** * Starts all plugins. */ void startPlugins(); diff --git a/src/main/java/com/gitblit/manager/PluginManager.java b/src/main/java/com/gitblit/manager/PluginManager.java index b2a87ab3..405dc510 100644 --- a/src/main/java/com/gitblit/manager/PluginManager.java +++ b/src/main/java/com/gitblit/manager/PluginManager.java @@ -42,9 +42,10 @@ import ro.fortsoft.pf4j.PluginClassLoader; import ro.fortsoft.pf4j.PluginState; import ro.fortsoft.pf4j.PluginStateEvent; import ro.fortsoft.pf4j.PluginStateListener; -import ro.fortsoft.pf4j.PluginVersion; import ro.fortsoft.pf4j.PluginWrapper; +import ro.fortsoft.pf4j.Version; +import com.gitblit.Constants; import com.gitblit.Keys; import com.gitblit.models.PluginRegistry; import com.gitblit.models.PluginRegistry.InstallState; @@ -63,6 +64,7 @@ import com.google.common.io.InputSupplier; * the Dagger DI and retrieve extensions provided by active plugins. * * @author David Ostrovsky + * @author James Moger * */ public class PluginManager implements IPluginManager, PluginStateListener { @@ -82,7 +84,20 @@ public class PluginManager implements IPluginManager, PluginStateListener { File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins"); dir.mkdirs(); this.runtimeManager = runtimeManager; + this.pf4j = new DefaultPluginManager(dir); + + try { + Version systemVersion = Version.createVersion(Constants.getVersion()); + pf4j.setSystemVersion(systemVersion); + } catch (Exception e) { + logger.error(null, e); + } + } + + @Override + public Version getSystemVersion() { + return pf4j.getSystemVersion(); } @Override @@ -130,6 +145,7 @@ public class PluginManager implements IPluginManager, PluginStateListener { return PluginState.STARTED.equals(state); } + @Override public synchronized boolean upgradePlugin(String pluginId, String url, boolean verifyChecksum) throws IOException { // ensure we can download the update BEFORE we remove the existing one File file = download(url, verifyChecksum); @@ -185,7 +201,6 @@ public class PluginManager implements IPluginManager, PluginStateListener { (file.getName().toLowerCase().endsWith(".sha1") || file.getName().toLowerCase().endsWith(".md5")); } - }); if (checksums != null) { @@ -322,7 +337,7 @@ public class PluginManager implements IPluginManager, PluginStateListener { for (PluginWrapper pw : pf4j.getPlugins()) { String id = pw.getDescriptor().getPluginId(); - PluginVersion pv = pw.getDescriptor().getVersion(); + Version pv = pw.getDescriptor().getVersion(); PluginRegistration reg = map.get(id); if (reg != null) { reg.installedRelease = pv.toString(); 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())); |