mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
(refs #464)Fix compilation error
This commit is contained in:
@@ -11,6 +11,7 @@ import org.apache.commons.io.FileUtils
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import plugin.{Plugin, PluginSystem}
|
import plugin.{Plugin, PluginSystem}
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
|
import util.Implicits._
|
||||||
|
|
||||||
class SystemSettingsController extends SystemSettingsControllerBase
|
class SystemSettingsController extends SystemSettingsControllerBase
|
||||||
with AccountService with AdminAuthenticator
|
with AccountService with AdminAuthenticator
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import org.apache.commons.io.FileUtils
|
|||||||
import service.RepositoryService.RepositoryInfo
|
import service.RepositoryService.RepositoryInfo
|
||||||
import Security._
|
import Security._
|
||||||
import service.PluginService
|
import service.PluginService
|
||||||
|
import model.Profile._
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides extension points to plug-ins.
|
* Provides extension points to plug-ins.
|
||||||
@@ -22,14 +24,15 @@ object PluginSystem extends PluginService {
|
|||||||
private val pluginsMap = scala.collection.mutable.Map[String, Plugin]()
|
private val pluginsMap = scala.collection.mutable.Map[String, Plugin]()
|
||||||
private val repositoriesList = scala.collection.mutable.ListBuffer[PluginRepository]()
|
private val repositoriesList = scala.collection.mutable.ListBuffer[PluginRepository]()
|
||||||
|
|
||||||
def install(plugin: Plugin): Unit = {
|
def install(plugin: Plugin)(implicit session: Session): Unit = {
|
||||||
pluginsMap.put(plugin.id, plugin)
|
pluginsMap.put(plugin.id, plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
def plugins: List[Plugin] = pluginsMap.values.toList
|
def plugins: List[Plugin] = pluginsMap.values.toList
|
||||||
|
|
||||||
def uninstall(id: String): Unit = {
|
def uninstall(id: String)(implicit session: Session): Unit = {
|
||||||
pluginsMap.remove(id)
|
pluginsMap.remove(id)
|
||||||
|
deletePlugin(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
def repositories: List[PluginRepository] = repositoriesList.toList
|
def repositories: List[PluginRepository] = repositoriesList.toList
|
||||||
@@ -37,7 +40,7 @@ object PluginSystem extends PluginService {
|
|||||||
/**
|
/**
|
||||||
* Initializes the plugin system. Load scripts from GITBUCKET_HOME/plugins.
|
* Initializes the plugin system. Load scripts from GITBUCKET_HOME/plugins.
|
||||||
*/
|
*/
|
||||||
def init(): Unit = {
|
def init()(implicit session: Session): Unit = {
|
||||||
if(initialized.compareAndSet(false, true)){
|
if(initialized.compareAndSet(false, true)){
|
||||||
// Load installed plugins
|
// Load installed plugins
|
||||||
val pluginDir = new java.io.File(PluginHome)
|
val pluginDir = new java.io.File(PluginHome)
|
||||||
@@ -52,7 +55,7 @@ object PluginSystem extends PluginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Method name seems to not so good.
|
// TODO Method name seems to not so good.
|
||||||
def installPlugin(id: String): Unit = {
|
def installPlugin(id: String)(implicit session: Session): Unit = {
|
||||||
val pluginDir = new java.io.File(PluginHome)
|
val pluginDir = new java.io.File(PluginHome)
|
||||||
|
|
||||||
val scalaFile = new java.io.File(pluginDir, id + "/plugin.scala")
|
val scalaFile = new java.io.File(pluginDir, id + "/plugin.scala")
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ trait PluginService {
|
|||||||
|
|
||||||
def deletePlugin(pluginId: String)(implicit s: Session): Unit = Plugins.filter(_.pluginId === pluginId.bind).delete
|
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
|
def getPlugin(pluginId: String)(implicit s: Session): Option[Plugin] = Plugins.filter(_.pluginId === pluginId.bind).firstOption
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,10 +180,12 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
System.setProperty("gitbucket.home", datadir)
|
System.setProperty("gitbucket.home", datadir)
|
||||||
}
|
}
|
||||||
org.h2.Driver.load()
|
org.h2.Driver.load()
|
||||||
event.getServletContext.setInitParameter("db.url", s"jdbc:h2:${DatabaseHome};MVCC=true")
|
|
||||||
|
|
||||||
logger.debug("Start schema update")
|
val context = event.getServletContext
|
||||||
|
context.setInitParameter("db.url", s"jdbc:h2:${DatabaseHome};MVCC=true")
|
||||||
|
|
||||||
defining(getConnection(event.getServletContext)){ conn =>
|
defining(getConnection(event.getServletContext)){ conn =>
|
||||||
|
logger.debug("Start schema update")
|
||||||
try {
|
try {
|
||||||
defining(getCurrentVersion()){ currentVersion =>
|
defining(getCurrentVersion()){ currentVersion =>
|
||||||
if(currentVersion == headVersion){
|
if(currentVersion == headVersion){
|
||||||
@@ -193,7 +195,6 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
} else {
|
} else {
|
||||||
versions.takeWhile(_ != currentVersion).reverse.foreach(_.update(conn))
|
versions.takeWhile(_ != currentVersion).reverse.foreach(_.update(conn))
|
||||||
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
||||||
conn.commit()
|
|
||||||
logger.debug(s"Updated from ${currentVersion.versionString} to ${headVersion.versionString}")
|
logger.debug(s"Updated from ${currentVersion.versionString} to ${headVersion.versionString}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,17 +205,27 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
conn.rollback()
|
conn.rollback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.debug("End schema update")
|
||||||
}
|
}
|
||||||
logger.debug("End schema update")
|
|
||||||
|
|
||||||
logger.debug("Starting plugin system...")
|
getDatabase(context).withSession { implicit session =>
|
||||||
plugin.PluginSystem.init()
|
logger.debug("Starting plugin system...")
|
||||||
|
try {
|
||||||
|
plugin.PluginSystem.init()
|
||||||
|
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
PluginUpdateJob.schedule(scheduler)
|
PluginUpdateJob.schedule(scheduler)
|
||||||
logger.debug("PluginUpdateJob is started.")
|
logger.debug("PluginUpdateJob is started.")
|
||||||
|
|
||||||
logger.debug("Plugin system is initialized.")
|
logger.debug("Plugin system is initialized.")
|
||||||
|
} catch {
|
||||||
|
case ex: Throwable => {
|
||||||
|
logger.error("Failed to initialize plugin system", ex)
|
||||||
|
ex.printStackTrace()
|
||||||
|
session.rollback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def contextDestroyed(sce: ServletContextEvent): Unit = {
|
def contextDestroyed(sce: ServletContextEvent): Unit = {
|
||||||
@@ -227,4 +238,10 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
servletContext.getInitParameter("db.user"),
|
servletContext.getInitParameter("db.user"),
|
||||||
servletContext.getInitParameter("db.password"))
|
servletContext.getInitParameter("db.password"))
|
||||||
|
|
||||||
|
private def getDatabase(servletContext: ServletContext): scala.slick.jdbc.JdbcBackend.Database =
|
||||||
|
slick.jdbc.JdbcBackend.Database.forURL(
|
||||||
|
servletContext.getInitParameter("db.url"),
|
||||||
|
servletContext.getInitParameter("db.user"),
|
||||||
|
servletContext.getInitParameter("db.password"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user