diff --git a/build.sbt b/build.sbt index c941cce..569e462 100644 --- a/build.sbt +++ b/build.sbt @@ -50,6 +50,7 @@ "org.cache2k" % "cache2k-all" % "1.0.0.CR1", "com.enragedginger" %% "akka-quartz-scheduler" % "1.6.0-akka-2.4.x" exclude("c3p0","c3p0"), "net.coobird" % "thumbnailator" % "0.4.8", + "com.github.zafarkhaja" % "java-semver" % "0.9.0", "org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided", "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided", "junit" % "junit" % "4.12" % "test", diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index c87adbf..a5e2e5e 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -21,6 +21,7 @@ import scala.collection.mutable import scala.collection.mutable.ListBuffer +import com.github.zafarkhaja.semver.Version class PluginRegistry { @@ -197,7 +198,16 @@ if(pluginDir.exists && pluginDir.isDirectory){ pluginDir.listFiles(new FilenameFilter { override def accept(dir: File, name: String): Boolean = name.endsWith(".jar") - }).sortBy(_.getName).foreach { pluginJar => + }).map { file => + val Array(name, version) = file.getName.split("_2.12-") + (name, Version.valueOf(version.replaceFirst("\\.jar$", "")), file) + }.groupBy { case (name, _, _) => + name + }.map { case (name, versions) => + // Adopt the latest version + versions.sortBy { case (name, version, file) => version }.reverse.head._3 + }.toSeq.sortBy(_.getName).foreach { pluginJar => + logger.info(s"Initialize ${pluginJar.getName}") val classLoader = new URLClassLoader(Array(pluginJar.toURI.toURL), Thread.currentThread.getContextClassLoader) try { val plugin = classLoader.loadClass("Plugin").getDeclaredConstructor().newInstance().asInstanceOf[Plugin] @@ -222,7 +232,6 @@ description = plugin.description, pluginClass = plugin )) - } catch { case e: Throwable => { logger.error(s"Error during plugin initialization: ${pluginJar.getAbsolutePath}", e)