mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-07 20:36:45 +02:00
Bundle plugins
This commit is contained in:
15
build.sbt
15
build.sbt
@@ -170,12 +170,17 @@ executableKey := {
|
||||
// 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
|
||||
|
||||
54
plugins.json
54
plugins.json
@@ -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
|
||||
}
|
||||
]
|
||||
1
src/main/resources/bundle-plugins.txt
Normal file
1
src/main/resources/bundle-plugins.txt
Normal file
@@ -0,0 +1 @@
|
||||
notifications:1.5.1
|
||||
@@ -204,7 +204,6 @@ object PluginRegistry {
|
||||
|
||||
private var watcher: PluginWatchThread = null
|
||||
private var extraWatcher: PluginWatchThread = null
|
||||
//private val initializing = new AtomicBoolean(false)
|
||||
|
||||
/**
|
||||
* Returns the PluginRegistry singleton instance.
|
||||
|
||||
@@ -136,46 +136,36 @@ class InitializeListener extends ServletContextListener with SystemSettingsServi
|
||||
}
|
||||
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user