From 80cf76b88cb9b9c1696c48fd418c0cdee995812c Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 17 Apr 2014 23:08:07 -0400 Subject: [PATCH] Filter the current plugin release by the system version --- src/main/java/com/gitblit/models/PluginRegistry.java | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gitblit/models/PluginRegistry.java b/src/main/java/com/gitblit/models/PluginRegistry.java index ef46316..0c5d5a1 100644 --- a/src/main/java/com/gitblit/models/PluginRegistry.java +++ b/src/main/java/com/gitblit/models/PluginRegistry.java @@ -93,19 +93,40 @@ this.releases = new ArrayList<PluginRelease>(); } - public PluginRelease getCurrentRelease() { + public PluginRelease getCurrentRelease(Version system) { PluginRelease current = null; if (!StringUtils.isEmpty(currentRelease)) { // find specified current = getRelease(currentRelease); } + if (current != null) { + // verify the current release is acceptable for this system + Version requires = Version.ZERO; + if (!StringUtils.isEmpty(current.requires)) { + requires = Version.createVersion(current.requires); + } + + if (!system.isZero() && !system.atLeast(requires)) { + // requires newer system version + current = null; + } + } + if (current == null) { // find by date Date date = new Date(0); for (PluginRelease pv : releases) { - if (pv.date.after(date)) { - current = pv; + Version requires = Version.ZERO; + if (!StringUtils.isEmpty(pv.requires)) { + requires = Version.createVersion(pv.requires); + } + + if (system.isZero() || system.atLeast(requires)) { + if (pv.date.after(date)) { + current = pv; + date = pv.date; + } } } } @@ -143,7 +164,10 @@ } } - public static class PluginRelease implements Comparable<PluginRelease> { + public static class PluginRelease implements Serializable, Comparable<PluginRelease> { + + private static final long serialVersionUID = 1L; + public String version; public Date date; public String requires; -- Gitblit v1.9.1