mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #464)Add PLUGIN table for plugin management
This commit is contained in:
6
src/main/resources/update/2_3.sql
Normal file
6
src/main/resources/update/2_3.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE PLUGIN (
|
||||
PLUGIN_ID VARCHAR(100) NOT NULL,
|
||||
VERSION VARCHAR(100) NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE PLUGIN ADD CONSTRAINT IDX_PLUGIN_PK PRIMARY KEY (PLUGIN_ID);
|
||||
19
src/main/scala/model/Plugin.scala
Normal file
19
src/main/scala/model/Plugin.scala
Normal file
@@ -0,0 +1,19 @@
|
||||
package model
|
||||
|
||||
trait PluginComponent extends TemplateComponent { self: Profile =>
|
||||
import profile.simple._
|
||||
import self._
|
||||
|
||||
lazy val Plugins = TableQuery[Plugins]
|
||||
|
||||
class Plugins(tag: Tag) extends Table[Plugin](tag, "PLUGIN"){
|
||||
val pluginId = column[String]("PLUGIN_ID")
|
||||
val version = column[String]("VERSION")
|
||||
def * = (pluginId, version) <> (Plugin.tupled, Plugin.unapply)
|
||||
}
|
||||
}
|
||||
|
||||
case class Plugin(
|
||||
pluginId: String,
|
||||
version: String
|
||||
)
|
||||
@@ -31,7 +31,8 @@ object Profile extends {
|
||||
with PullRequestComponent
|
||||
with RepositoryComponent
|
||||
with SshKeyComponent
|
||||
with WebHookComponent with Profile {
|
||||
with WebHookComponent
|
||||
with PluginComponent with Profile {
|
||||
|
||||
/**
|
||||
* Returns system date.
|
||||
|
||||
@@ -9,12 +9,12 @@ import util.ControlUtil._
|
||||
import org.apache.commons.io.FileUtils
|
||||
import service.RepositoryService.RepositoryInfo
|
||||
import Security._
|
||||
|
||||
import service.PluginService
|
||||
|
||||
/**
|
||||
* Provides extension points to plug-ins.
|
||||
*/
|
||||
object PluginSystem {
|
||||
object PluginSystem extends PluginService {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(PluginSystem.getClass)
|
||||
|
||||
@@ -62,16 +62,27 @@ object PluginSystem {
|
||||
properties.load(in)
|
||||
}
|
||||
|
||||
val pluginId = properties.getProperty("id")
|
||||
val version = properties.getProperty("version")
|
||||
val author = properties.getProperty("author")
|
||||
val url = properties.getProperty("url")
|
||||
val description = properties.getProperty("description")
|
||||
|
||||
val source = s"""
|
||||
|val id = "${properties.getProperty("id")}"
|
||||
|val version = "${properties.getProperty("version")}"
|
||||
|val author = "${properties.getProperty("author")}"
|
||||
|val url = "${properties.getProperty("url")}"
|
||||
|val description = "${properties.getProperty("description")}"
|
||||
|val id = "${pluginId}"
|
||||
|val version = "${version}"
|
||||
|val author = "${author}"
|
||||
|val url = "${url}"
|
||||
|val description = "${description}"
|
||||
""".stripMargin + FileUtils.readFileToString(scalaFile, "UTF-8")
|
||||
|
||||
try {
|
||||
ScalaPlugin.eval(source)
|
||||
if(getPlugin(pluginId).isDefined){
|
||||
registerPlugin(model.Plugin(pluginId, version))
|
||||
} else {
|
||||
updatePlugin(model.Plugin(pluginId, version))
|
||||
}
|
||||
} catch {
|
||||
case e: Exception => logger.warn(s"Error in plugin loading for ${scalaFile.getAbsolutePath}", e)
|
||||
}
|
||||
|
||||
19
src/main/scala/service/PluginService.scala
Normal file
19
src/main/scala/service/PluginService.scala
Normal file
@@ -0,0 +1,19 @@
|
||||
package service
|
||||
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.Plugin
|
||||
|
||||
trait PluginService {
|
||||
|
||||
def getPlugins()(implicit s: Session): List[Plugin] = Plugins.sortBy(_.pluginId).list
|
||||
|
||||
def registerPlugin(plugin: Plugin)(implicit s: Session): Unit = Plugins.insert(plugin)
|
||||
|
||||
def updatePlugin(plugin: Plugin)(implicit s: Session): Unit = Plugins.update(plugin)
|
||||
|
||||
def deletePlugin(pluginId: String)(implicit s: Session): Unit = Plugins.filter(_.pluginId === pluginId.bind).delete
|
||||
|
||||
def getPlugin(pluginId: String): Option[Plugin] = Plugins.filter(_.pluginId === pluginId.bind).firstOption
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user