mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Enhance plugin install / uninstall process
This commit is contained in:
@@ -364,17 +364,15 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect("/admin/plugins")
|
redirect("/admin/plugins")
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/plugins/:pluginId/:version/_uninstall")(adminOnly {
|
post("/admin/plugins/:pluginId/_uninstall")(adminOnly { // TODO Is version unnecessary?
|
||||||
val pluginId = params("pluginId")
|
val pluginId = params("pluginId")
|
||||||
val version = params("version")
|
|
||||||
PluginRegistry()
|
if (PluginRegistry().getPlugins().exists(_.pluginId == pluginId)) {
|
||||||
.getPlugins()
|
|
||||||
.collect { case plugin if (plugin.pluginId == pluginId && plugin.pluginVersion == version) => plugin }
|
|
||||||
.foreach { _ =>
|
|
||||||
PluginRegistry
|
PluginRegistry
|
||||||
.uninstall(pluginId, request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
.uninstall(pluginId, request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
||||||
flash += "info" -> s"${pluginId} was uninstalled."
|
flash += "info" -> s"${pluginId} was uninstalled."
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect("/admin/plugins")
|
redirect("/admin/plugins")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -389,6 +387,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
case (meta, version) =>
|
case (meta, version) =>
|
||||||
version.foreach { version =>
|
version.foreach { version =>
|
||||||
PluginRegistry.install(
|
PluginRegistry.install(
|
||||||
|
pluginId,
|
||||||
new java.net.URL(version.url),
|
new java.net.URL(version.url),
|
||||||
request.getServletContext,
|
request.getServletContext,
|
||||||
loadSystemSettings(),
|
loadSystemSettings(),
|
||||||
|
|||||||
@@ -225,37 +225,37 @@ object PluginRegistry {
|
|||||||
*/
|
*/
|
||||||
def uninstall(pluginId: String, context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit =
|
def uninstall(pluginId: String, context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit =
|
||||||
synchronized {
|
synchronized {
|
||||||
instance
|
|
||||||
.getPlugins()
|
|
||||||
.collect { case plugin if plugin.pluginId == pluginId => plugin }
|
|
||||||
.foreach { plugin =>
|
|
||||||
// try {
|
|
||||||
// plugin.pluginClass.uninstall(instance, context, settings)
|
|
||||||
// } catch {
|
|
||||||
// case e: Exception =>
|
|
||||||
// logger.error(s"Error during uninstalling plugin: ${plugin.pluginJar.getName}", e)
|
|
||||||
// }
|
|
||||||
shutdown(context, settings)
|
shutdown(context, settings)
|
||||||
|
|
||||||
new File(PluginHome)
|
new File(PluginHome)
|
||||||
.listFiles((_: File, name: String) => {
|
.listFiles((_: File, name: String) => {
|
||||||
name.startsWith(s"gitbucket-${pluginId}-plugin") && name.endsWith(".jar")
|
name.startsWith(s"gitbucket-${pluginId}-plugin") && name.endsWith(".jar")
|
||||||
})
|
})
|
||||||
.foreach { file =>
|
.foreach(_.delete())
|
||||||
file.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
instance = new PluginRegistry()
|
instance = new PluginRegistry()
|
||||||
initialize(context, settings, conn)
|
initialize(context, settings, conn)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install a plugin from a specified jar file.
|
* Install a plugin from a specified jar file.
|
||||||
*/
|
*/
|
||||||
def install(url: java.net.URL, context: ServletContext, settings: SystemSettings, conn: java.sql.Connection): Unit =
|
def install(
|
||||||
|
pluginId: String,
|
||||||
|
url: java.net.URL,
|
||||||
|
context: ServletContext,
|
||||||
|
settings: SystemSettings,
|
||||||
|
conn: java.sql.Connection
|
||||||
|
): Unit =
|
||||||
synchronized {
|
synchronized {
|
||||||
shutdown(context, settings)
|
shutdown(context, settings)
|
||||||
|
|
||||||
|
new File(PluginHome)
|
||||||
|
.listFiles((_: File, name: String) => {
|
||||||
|
name.startsWith(s"gitbucket-${pluginId}-plugin") && name.endsWith(".jar")
|
||||||
|
})
|
||||||
|
.foreach(_.delete())
|
||||||
|
|
||||||
val in = url.openStream()
|
val in = url.openStream()
|
||||||
FileUtils.copyToFile(in, new File(PluginHome, new File(url.getFile).getName))
|
FileUtils.copyToFile(in, new File(PluginHome, new File(url.getFile).getName))
|
||||||
instance = new PluginRegistry()
|
instance = new PluginRegistry()
|
||||||
|
|||||||
@@ -16,21 +16,19 @@
|
|||||||
@plugins.map { case (plugin, enabled, updatableVersion) =>
|
@plugins.map { case (plugin, enabled, updatableVersion) =>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading strong" id="@plugin.pluginId">
|
<div class="panel-heading strong" id="@plugin.pluginId">
|
||||||
|
<form method="POST" class="pull-right">
|
||||||
@if(enabled){
|
@if(enabled){
|
||||||
@if(updatableVersion.isEmpty){
|
@if(updatableVersion.nonEmpty){
|
||||||
<form action="@{context.path}/admin/plugins/@{plugin.pluginId}/@{plugin.pluginVersion}/_uninstall" method="POST" class="pull-right uninstall-form">
|
<input type="submit" value="Update" class="btn btn-success btn-sm update-plugin" style="position: relative; top: -5px; left: 10px;"
|
||||||
<input type="submit" value="Uninstall" class="btn btn-danger btn-sm" style="position: relative; top: -5px; left: 10px;" data-name="@plugin.pluginName">
|
data-name="@plugin.pluginName" formaction="@{context.path}/admin/plugins/@{plugin.pluginId}/@{updatableVersion}/_install">
|
||||||
</form>
|
|
||||||
} else {
|
|
||||||
<form action="@{context.path}/admin/plugins/@{plugin.pluginId}/@{updatableVersion}/_install" method="POST" class="pull-right install-form">
|
|
||||||
<input type="submit" value="Update" class="btn btn-primary btn-sm" style="position: relative; top: -5px; left: 10px;" data-name="@plugin.pluginName">
|
|
||||||
</form>
|
|
||||||
}
|
}
|
||||||
|
<input type="submit" value="Uninstall" class="btn btn-danger btn-sm uninstall-plugin" style="position: relative; top: -5px; left: 10px;"
|
||||||
|
data-name="@plugin.pluginName" formaction="@{context.path}/admin/plugins/@{plugin.pluginId}/_uninstall">
|
||||||
} else {
|
} else {
|
||||||
<form action="@{context.path}/admin/plugins/@{plugin.pluginId}/@{plugin.pluginVersion}/_install" method="POST" class="pull-right install-form">
|
<input type="submit" value="Install" class="btn btn-success btn-sm install-plugin" style="position: relative; top: -5px; left: 10px;"
|
||||||
<input type="submit" value="Install" class="btn btn-success btn-sm" style="position: relative; top: -5px; left: 10px;" data-name="@plugin.pluginName">
|
data-name="@plugin.pluginName" formaction="@{context.path}/admin/plugins/@{plugin.pluginId}/@{plugin.pluginVersion}/_install">
|
||||||
</form>
|
|
||||||
}
|
}
|
||||||
|
</form>
|
||||||
@plugin.pluginName
|
@plugin.pluginName
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -60,14 +58,19 @@
|
|||||||
}
|
}
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
$('.uninstall-form').click(function(e){
|
$('.uninstall-plugin').click(function(e){
|
||||||
var name = $(e.target).data('name');
|
var name = $(e.target).data('name');
|
||||||
return confirm('Uninstall ' + name + '. Are you sure?');
|
return confirm('Uninstall ' + name + '. Are you sure?');
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.install-form').click(function(e){
|
$('.install-plugin').click(function(e){
|
||||||
var name = $(e.target).data('name');
|
var name = $(e.target).data('name');
|
||||||
return confirm('Install ' + name + '. Are you sure?');
|
return confirm('Install ' + name + '. Are you sure?');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.update-plugin').click(function(e){
|
||||||
|
var name = $(e.target).data('name');
|
||||||
|
return confirm('Update ' + name + '. Are you sure?');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user