diff --git a/build.sbt b/build.sbt index 9650f62..76a051d 100644 --- a/build.sbt +++ b/build.sbt @@ -170,12 +170,17 @@ // include plugins val pluginsDir = temp / "WEB-INF" / "classes" / "plugins" IO createDirectory (pluginsDir) - IO copyFile (Keys.baseDirectory.value / "plugins.json", pluginsDir / "plugins.json") + //IO copyFile (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt", pluginsDir / "plugins.json") - val json = IO read (Keys.baseDirectory.value / "plugins.json") - PluginsJson.getUrls(json).foreach { url => - log info s"Download: ${url}" - IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1)) + val plugins = IO readLines (Keys.baseDirectory.value / "src" / "main" / "resources" / "bundle-plugins.txt") + plugins.foreach { plugin => + plugin.trim.split(":") match { + case Array(pluginId, pluginVersion) => + val url = s"https://plugins.gitbucket-community.org/releases/gitbucket-${pluginId}-plugin/gitbucket-${pluginId}-plugin-gitbucket_${version.value}-${pluginVersion}.jar" + log info s"Download: ${url}" + IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1)) + case _ => () + } } // zip it up diff --git a/plugins.json b/plugins.json deleted file mode 100644 index 3682660..0000000 --- a/plugins.json +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "id": "notifications", - "name": "Notifications Plugin", - "description": "Provides notifications feature on GitBucket.", - "versions": [ - { - "version": "1.5.0", - "range": ">=4.23.0", - "url": "https://github.com/gitbucket/gitbucket-notifications-plugin/releases/download/1.5.0/gitbucket-notifications-plugin-assembly-1.5.0.jar" - } - ], - "default": true - }, - { - "id": "emoji", - "name": "Emoji Plugin", - "description": "Provides Emoji support for GitBucket.", - "versions": [ - { - "version": "4.5.0", - "range": ">=4.18.0", - "url": "https://github.com/gitbucket/gitbucket-emoji-plugin/releases/download/4.5.0/gitbucket-emoji-plugin_2.12-4.5.0.jar" - } - ], - "default": false - }, - { - "id": "gist", - "name": "Gist Plugin", - "description": "Provides Gist feature on GitBucket.", - "versions": [ - { - "version": "4.15.0", - "range": ">=4.25.0", - "url": "https://github.com/gitbucket/gitbucket-gist-plugin/releases/download/4.15.0/gitbucket-gist-plugin-gitbucket_4.25.0-4.15.0.jar" - } - ], - "default": false - }, - { - "id": "pages", - "name": "Pages Plugin", - "description": "Project pages for gitbucket", - "versions": [ - { - "version": "1.7.0", - "range": ">=4.23.0", - "url": "https://github.com/gitbucket/gitbucket-pages-plugin/releases/download/v1.7.0/gitbucket-pages-plugin_2.12-1.7.0.jar" - } - ], - "default": false - } -] diff --git a/src/main/resources/bundle-plugins.txt b/src/main/resources/bundle-plugins.txt new file mode 100644 index 0000000..e2ab698 --- /dev/null +++ b/src/main/resources/bundle-plugins.txt @@ -0,0 +1 @@ +notifications:1.5.1 diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala index 2398891..8d9c49e 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala @@ -204,7 +204,6 @@ private var watcher: PluginWatchThread = null private var extraWatcher: PluginWatchThread = null - //private val initializing = new AtomicBoolean(false) /** * Returns the PluginRegistry singleton instance. diff --git a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala index 2818dbd..f278109 100644 --- a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala +++ b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala @@ -136,46 +136,36 @@ } private def extractBundledPlugins(gitbucketVersion: String): Unit = { -// logger.info("Extract bundled plugins") -// val cl = Thread.currentThread.getContextClassLoader -// try { -// using(cl.getResourceAsStream("plugins/plugins.json")) { pluginsFile => -// if (pluginsFile != null) { -// val pluginsJson = IOUtils.toString(pluginsFile, "UTF-8") -// -// FileUtils.forceMkdir(PluginRepository.LocalRepositoryDir) -// FileUtils.write(PluginRepository.LocalRepositoryIndexFile, pluginsJson, "UTF-8") -// -// val plugins = PluginRepository.parsePluginJson(pluginsJson) -// plugins.foreach { plugin => -// plugin.versions -// .sortBy { x => -// Semver.valueOf(x.version) -// } -// .reverse -// .zipWithIndex -// .foreach { -// case (version, i) => -// val file = new File(PluginRepository.LocalRepositoryDir, version.file) -// if (!file.exists) { -// logger.info(s"Copy ${plugin} to ${file.getAbsolutePath}") -// FileUtils.forceMkdirParent(file) -// using(cl.getResourceAsStream("plugins/" + version.file), new FileOutputStream(file)) { -// case (in, out) => IOUtils.copy(in, out) -// } -// -// if (plugin.default && i == 0) { -// logger.info(s"Enable ${file.getName} in default") -// FileUtils.copyFile(file, new File(PluginHome, version.file)) -// } -// } -// } -// } -// } -// } -// } catch { -// case e: Exception => logger.error("Error in extracting bundled plugin", e) -// } + logger.info("Extract bundled plugins...") + val cl = Thread.currentThread.getContextClassLoader + try { + using(cl.getResourceAsStream("bundle-plugins.txt")) { pluginsFile => + if (pluginsFile != null) { + val plugins = IOUtils.readLines(pluginsFile, "UTF-8") + val gitbucketVersion = GitBucketCoreModule.getVersions.asScala.last.getVersion + + plugins.asScala.foreach { plugin => + plugin.trim.split(":") match { + case Array(pluginId, pluginVersion) => + val fileName = s"gitbucket-${pluginId}-plugin-gitbucket_${gitbucketVersion}-${pluginVersion}.jar" + val in = cl.getResourceAsStream("plugins/" + fileName) + if (in != null) { + val file = new File(PluginHome, fileName) + logger.info(s"Extract to ${file.getAbsolutePath}") + + FileUtils.forceMkdirParent(file) + using(in, new FileOutputStream(file)) { + case (in, out) => IOUtils.copy(in, out) + } + } + case _ => () + } + } + } + } + } catch { + case e: Exception => logger.error("Error in extracting bundled plugin", e) + } } override def contextDestroyed(event: ServletContextEvent): Unit = {