From: James Moger Date: Wed, 23 Apr 2014 14:34:17 +0000 (-0400) Subject: Simplify current plugin release detection, ignore currentRelease registry field X-Git-Tag: v1.5.1~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=67278f5;p=gitblit.git Simplify current plugin release detection, ignore currentRelease registry field --- diff --git a/releases.moxie b/releases.moxie index 8360d778..8e183f74 100644 --- a/releases.moxie +++ b/releases.moxie @@ -12,6 +12,7 @@ r23: { fixes: ~ changes: - improve French translation (pr-176) + - simplify current plugin release detection and ignore the currentRelease registry field additions: ~ dependencyChanges: - update to Apache MINA/SSHD 0.11.0 (issue-410) diff --git a/src/main/java/com/gitblit/manager/PluginManager.java b/src/main/java/com/gitblit/manager/PluginManager.java index 9e6a31f6..2ee48558 100644 --- a/src/main/java/com/gitblit/manager/PluginManager.java +++ b/src/main/java/com/gitblit/manager/PluginManager.java @@ -377,7 +377,7 @@ public class PluginManager implements IPluginManager, PluginStateListener { List list = getRegisteredPlugins(); Iterator itr = list.iterator(); while (itr.hasNext()) { - if (state != itr.next().getInstallState()) { + if (state != itr.next().getInstallState(getSystemVersion())) { itr.remove(); } } diff --git a/src/main/java/com/gitblit/models/PluginRegistry.java b/src/main/java/com/gitblit/models/PluginRegistry.java index 0c5d5a19..8da34578 100644 --- a/src/main/java/com/gitblit/models/PluginRegistry.java +++ b/src/main/java/com/gitblit/models/PluginRegistry.java @@ -80,8 +80,6 @@ public class PluginRegistry implements Serializable { public String projectUrl; - public String currentRelease; - public transient String installedRelease; public transient String registry; @@ -95,38 +93,17 @@ public class PluginRegistry implements Serializable { 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 + Date date = new Date(0); + for (PluginRelease pv : releases) { 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 (!StringUtils.isEmpty(pv.requires)) { + requires = Version.createVersion(pv.requires); } - } - if (current == null) { - // find by date - Date date = new Date(0); - for (PluginRelease pv : releases) { - 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; - } + if (system.isZero() || system.atLeast(requires)) { + if (pv.date.after(date)) { + current = pv; + date = pv.date; } } } @@ -142,12 +119,16 @@ public class PluginRegistry implements Serializable { return null; } - public InstallState getInstallState() { + public InstallState getInstallState(Version system) { if (StringUtils.isEmpty(installedRelease)) { return InstallState.NOT_INSTALLED; } Version ir = Version.createVersion(installedRelease); - Version cr = Version.createVersion(currentRelease); + Version cr = Version.ZERO; + PluginRelease curr = getCurrentRelease(system); + if (cr != null) { + cr = Version.createVersion(curr.version); + } switch (ir.compareTo(cr)) { case -1: return InstallState.UNKNOWN; 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 42325e79..ce0958c3 100644 --- a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java @@ -283,7 +283,7 @@ public class PluginDispatcher extends DispatchCommand { state = Joiner.on(", ").join(InstallState.INSTALLED, pw.getPluginState()); } else { // registered, installed plugin - state = Joiner.on(", ").join(reg.getInstallState(), pw.getPluginState()); + state = Joiner.on(", ").join(reg.getInstallState(system), pw.getPluginState()); } StringBuilder sb = new StringBuilder(); @@ -486,9 +486,9 @@ public class PluginDispatcher extends DispatchCommand { curr = new PluginRelease(); } if (verbose) { - data[i] = new Object[] {p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(), p.registry}; + data[i] = new Object[] {p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(system), p.registry}; } else { - data[i] = new Object[] {p.id, p.installedRelease, curr.version, curr.requires, p.getInstallState()}; + data[i] = new Object[] {p.id, p.installedRelease, curr.version, curr.requires, p.getInstallState(system)}; } } @@ -504,9 +504,9 @@ public class PluginDispatcher extends DispatchCommand { curr = new PluginRelease(); } if (verbose) { - outTabbed(p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(), p.provider, p.registry); + outTabbed(p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(system), p.provider, p.registry); } else { - outTabbed(p.id, p.installedRelease, curr.version, curr.requires, p.getInstallState()); + outTabbed(p.id, p.installedRelease, curr.version, curr.requires, p.getInstallState(system)); } } }