]> source.dussan.org Git - gitblit.git/commitdiff
Filter the current plugin release by the system version
authorJames Moger <james.moger@gitblit.com>
Fri, 18 Apr 2014 03:03:34 +0000 (23:03 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 18 Apr 2014 03:08:07 +0000 (23:08 -0400)
src/main/java/com/gitblit/manager/PluginManager.java
src/main/java/com/gitblit/models/PluginRegistry.java
src/main/java/com/gitblit/transport/ssh/commands/PluginDispatcher.java

index 40d302ddd80ae860ca4b85ec353ec228b7fc73ca..9e6a31f62d2e7bb0b83e083f28bc1f291d639214 100644 (file)
@@ -403,7 +403,7 @@ public class PluginManager implements IPluginManager, PluginStateListener {
 
                PluginRelease pv;
                if (StringUtils.isEmpty(version)) {
-                       pv = reg.getCurrentRelease();
+                       pv = reg.getCurrentRelease(getSystemVersion());
                } else {
                        pv = reg.getRelease(version);
                }
index ef46316330564c7ae8c4177f4d294462ea9756d0..0c5d5a1990fd7af4312fada2be109d204696c37b 100644 (file)
@@ -93,19 +93,40 @@ public class PluginRegistry implements Serializable {
                        this.releases = new ArrayList<PluginRelease>();\r
                }\r
 \r
-               public PluginRelease getCurrentRelease() {\r
+               public PluginRelease getCurrentRelease(Version system) {\r
                        PluginRelease current = null;\r
                        if (!StringUtils.isEmpty(currentRelease)) {\r
                                // find specified\r
                                current = getRelease(currentRelease);\r
                        }\r
 \r
+                       if (current != null) {\r
+                               // verify the current release is acceptable for this system\r
+                               Version requires = Version.ZERO;\r
+                               if (!StringUtils.isEmpty(current.requires)) {\r
+                                       requires = Version.createVersion(current.requires);\r
+                               }\r
+\r
+                               if (!system.isZero() && !system.atLeast(requires)) {\r
+                                       // requires newer system version\r
+                                       current = null;\r
+                               }\r
+                       }\r
+\r
                        if (current == null) {\r
                                // find by date\r
                                Date date = new Date(0);\r
                                for (PluginRelease pv : releases) {\r
-                                       if (pv.date.after(date)) {\r
-                                               current = pv;\r
+                                       Version requires = Version.ZERO;\r
+                                       if (!StringUtils.isEmpty(pv.requires)) {\r
+                                               requires = Version.createVersion(pv.requires);\r
+                                       }\r
+\r
+                                       if (system.isZero() || system.atLeast(requires)) {\r
+                                               if (pv.date.after(date)) {\r
+                                                       current = pv;\r
+                                                       date = pv.date;\r
+                                               }\r
                                        }\r
                                }\r
                        }\r
@@ -143,7 +164,10 @@ public class PluginRegistry implements Serializable {
                }\r
        }\r
 \r
-       public static class PluginRelease implements Comparable<PluginRelease> {\r
+       public static class PluginRelease implements Serializable, Comparable<PluginRelease> {\r
+\r
+               private static final long serialVersionUID = 1L;\r
+\r
                public String version;\r
                public Date date;\r
                public String requires;\r
index 6f8f95ae6785535b302aef2a0b7e3978df4c4310..15345cac09d4b22013767b356e9ee5d5d305194f 100644 (file)
@@ -259,10 +259,18 @@ public class PluginDispatcher extends DispatchCommand {
                }
 
                protected String buildFieldTable(PluginWrapper pw, PluginRegistration reg) {
+                       Version system = getContext().getGitblit().getSystemVersion();
+                       PluginRelease current = reg == null ? null : reg.getCurrentRelease(system);
+                       if (current == null) {
+                               current = new PluginRelease();
+                               current.version = "";
+                               current.requires = "";
+                       }
+
                        final String id = pw == null ? reg.id : pw.getPluginId();
                        final String description = reg == null ? pw.getDescriptor().getPluginDescription() : reg.description;
-                       final String version = pw == null ? reg.getCurrentRelease().version : pw.getDescriptor().getVersion().toString();
-                       final String requires = pw == null ? reg.getCurrentRelease().requires : pw.getDescriptor().getRequires().toString();
+                       final String version = pw == null ? current.version : pw.getDescriptor().getVersion().toString();
+                       final String requires = pw == null ? current.requires : pw.getDescriptor().getRequires().toString();
                        final String provider = pw == null ? reg.provider : pw.getDescriptor().getProvider();
                        final String registry = reg == null ? "" : reg.registry;
                        final String path = pw == null ? "" : pw.getPluginPath();
@@ -470,10 +478,14 @@ public class PluginDispatcher extends DispatchCommand {
                                String [] h = { "Id", "Installed", "Current", "Requires", "State" };
                                headers = h;
                        }
+                       Version system = getContext().getGitblit().getSystemVersion();
                        Object[][] data = new Object[list.size()][];
                        for (int i = 0; i < list.size(); i++) {
                                PluginRegistration p = list.get(i);
-                               PluginRelease curr = p.getCurrentRelease();
+                               PluginRelease curr = p.getCurrentRelease(system);
+                               if (curr == null) {
+                                       curr = new PluginRelease();
+                               }
                                if (verbose) {
                                        data[i] = new Object[] {p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(), p.registry};
                                } else {
@@ -486,8 +498,12 @@ public class PluginDispatcher extends DispatchCommand {
 
                @Override
                protected void asTabbed(List<PluginRegistration> list) {
+                       Version system = getContext().getGitblit().getSystemVersion();
                        for (PluginRegistration p : list) {
-                               PluginRelease curr = p.getCurrentRelease();
+                               PluginRelease curr = p.getCurrentRelease(system);
+                               if (curr == null) {
+                                       curr = new PluginRelease();
+                               }
                                if (verbose) {
                                        outTabbed(p.id, p.description, p.installedRelease, curr.version, curr.requires, p.getInstallState(), p.provider, p.registry);
                                } else {