mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-07 06:27:07 +02:00
Add enabled flag to plugin info list
This commit is contained in:
@@ -192,7 +192,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
post("/admin/plugins/:pluginId/_uninstall")(adminOnly {
|
||||
val pluginId = params("pluginId")
|
||||
PluginRegistry().getPlugins().find(_.pluginId == pluginId).foreach { plugin =>
|
||||
PluginRegistry().getPlugins()
|
||||
.collect { case (plugin, true) if plugin.pluginId == pluginId => plugin }
|
||||
.foreach { plugin =>
|
||||
PluginRegistry.uninstall(pluginId, request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
||||
flash += "info" -> s"${pluginId} was uninstalled."
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import scala.collection.mutable.ListBuffer
|
||||
|
||||
class PluginRegistry {
|
||||
|
||||
private val plugins = new ListBuffer[PluginInfo]
|
||||
private val plugins = new ListBuffer[(PluginInfo, Boolean)]
|
||||
private val javaScripts = new ListBuffer[(String, String)]
|
||||
private val controllers = new ListBuffer[(ControllerBase, String)]
|
||||
private val images = mutable.Map[String, String]()
|
||||
@@ -53,9 +53,9 @@ class PluginRegistry {
|
||||
private val suggestionProviders = new ListBuffer[SuggestionProvider]
|
||||
suggestionProviders += new UserNameSuggestionProvider()
|
||||
|
||||
def addPlugin(pluginInfo: PluginInfo): Unit = plugins += pluginInfo
|
||||
def addPlugin(pluginInfo: PluginInfo, enabled: Boolean): Unit = plugins += ((pluginInfo, enabled))
|
||||
|
||||
def getPlugins(): List[PluginInfo] = plugins.toList
|
||||
def getPlugins(): List[(PluginInfo, Boolean)] = plugins.toList
|
||||
|
||||
def addImage(id: String, bytes: Array[Byte]): Unit = {
|
||||
val encoded = Base64.getEncoder.encodeToString(bytes)
|
||||
@@ -181,7 +181,9 @@ object PluginRegistry {
|
||||
* Uninstall a specified plugin.
|
||||
*/
|
||||
def uninstall(pluginId: String, context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit = synchronized {
|
||||
instance.getPlugins().find(_.pluginId == pluginId).foreach { plugin =>
|
||||
instance.getPlugins()
|
||||
.collect { case (plugin, true) if plugin.pluginId == plugin => plugin }
|
||||
.foreach { plugin =>
|
||||
// try {
|
||||
// plugin.pluginClass.uninstall(instance, context, settings)
|
||||
// } catch {
|
||||
@@ -243,10 +245,10 @@ object PluginRegistry {
|
||||
val plugin = classLoader.loadClass("Plugin").getDeclaredConstructor().newInstance().asInstanceOf[Plugin]
|
||||
val pluginId = plugin.pluginId
|
||||
|
||||
// Check duplication
|
||||
instance.getPlugins().find(_.pluginId == pluginId).foreach { x =>
|
||||
throw new IllegalStateException(s"Plugin ${pluginId} is duplicated. ${x.pluginJar.getName} is available.")
|
||||
}
|
||||
// // Check duplication
|
||||
// instance.getPlugins().find(_.pluginId == pluginId).foreach { x =>
|
||||
// throw new IllegalStateException(s"Plugin ${pluginId} is duplicated. ${x.pluginJar.getName} is available.")
|
||||
// }
|
||||
|
||||
// Migration
|
||||
val solidbase = new Solidbase()
|
||||
@@ -269,7 +271,7 @@ object PluginRegistry {
|
||||
pluginClass = plugin,
|
||||
pluginJar = pluginJar,
|
||||
classLoader = classLoader
|
||||
))
|
||||
), true)
|
||||
} catch {
|
||||
case e: Throwable => {
|
||||
logger.error(s"Error during plugin initialization: ${pluginJar.getName}", e)
|
||||
@@ -285,7 +287,9 @@ object PluginRegistry {
|
||||
}
|
||||
|
||||
def shutdown(context: ServletContext, settings: SystemSettings): Unit = synchronized {
|
||||
instance.getPlugins().foreach { plugin =>
|
||||
instance.getPlugins()
|
||||
.collect { case (plugin, true) => plugin }
|
||||
.foreach { plugin =>
|
||||
try {
|
||||
plugin.pluginClass.shutdown(instance, context, settings)
|
||||
} catch {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@(plugins: List[gitbucket.core.plugin.PluginInfo], info: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@(plugins: List[(gitbucket.core.plugin.PluginInfo, Boolean)], info: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@gitbucket.core.html.main("Plugins"){
|
||||
@gitbucket.core.admin.html.menu("plugins") {
|
||||
@gitbucket.core.helper.html.information(info)
|
||||
@@ -8,12 +8,12 @@
|
||||
<h1>Installed plugins</h1>
|
||||
@if(plugins.size > 0) {
|
||||
<ul>
|
||||
@plugins.map { plugin =>
|
||||
@plugins.map { case (plugin, enabled) =>
|
||||
<li><a href="#@plugin.pluginId">@plugin.pluginId:@plugin.pluginVersion</a></li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@plugins.map { plugin =>
|
||||
@plugins.map { case (plugin, enabled) =>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong" id="@plugin.pluginId">
|
||||
<form action="@{context.path}/admin/plugins/@{plugin.pluginId}/_uninstall" method="POST" class="pull-right uninstall-form">
|
||||
|
||||
Reference in New Issue
Block a user