From 61261dcb4e864226b376d9eef0c7d9ed30f259c4 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Wed, 4 Jul 2018 14:42:46 +0900 Subject: [PATCH] Improve plugin version handling - Allow to include "-SNAPSHOT" (both plugin and gitbucket version) - Allow to omit patch version like "x.y" --- .../gitbucket/core/plugin/PluginRegistry.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala index 62acace9c..fb0d39e80 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala @@ -272,17 +272,23 @@ object PluginRegistry { lazy val extraPluginDir: Option[String] = Option(System.getProperty("gitbucket.pluginDir")) def getGitBucketVersion(pluginJarFileName: String): Option[String] = { - val regex = ".+-gitbucket\\_(\\d+\\.\\d+\\.\\d+)-.+".r + val regex = ".+-gitbucket\\_(\\d+\\.\\d+\\.\\d+(-SNAPSHOT)?)-.+".r pluginJarFileName match { - case regex(x) => Some(x) - case _ => None + case regex(all, _) => Some(all) + case _ => None } } def getPluginVersion(pluginJarFileName: String): String = { - val regex = ".+-(\\d+\\.\\d+\\.\\d+)\\.jar$".r + val regex = ".+-((\\d+)\\.(\\d+)(\\.(\\d+))?(-SNAPSHOT)?)\\.jar$".r pluginJarFileName match { - case regex(x) => x + case regex(all, major, minor, _, patch, modifier) => { + if (patch != null) all + else { + s"${major}.${minor}.0" + (if (modifier == null) "" else modifier) + } + } + case _ => "0.0.0" } }