(refs #464)Add PLUGIN table for plugin management

This commit is contained in:
Naoki Takezoe
2014-08-13 02:23:29 +09:00
parent 3f20cec7b2
commit 13385cbced
5 changed files with 64 additions and 8 deletions

View 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);

View 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
)

View File

@@ -31,7 +31,8 @@ object Profile extends {
with PullRequestComponent with PullRequestComponent
with RepositoryComponent with RepositoryComponent
with SshKeyComponent with SshKeyComponent
with WebHookComponent with Profile { with WebHookComponent
with PluginComponent with Profile {
/** /**
* Returns system date. * Returns system date.

View File

@@ -9,12 +9,12 @@ import util.ControlUtil._
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import service.RepositoryService.RepositoryInfo import service.RepositoryService.RepositoryInfo
import Security._ import Security._
import service.PluginService
/** /**
* Provides extension points to plug-ins. * Provides extension points to plug-ins.
*/ */
object PluginSystem { object PluginSystem extends PluginService {
private val logger = LoggerFactory.getLogger(PluginSystem.getClass) private val logger = LoggerFactory.getLogger(PluginSystem.getClass)
@@ -62,16 +62,27 @@ object PluginSystem {
properties.load(in) 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 source = s"""
|val id = "${properties.getProperty("id")}" |val id = "${pluginId}"
|val version = "${properties.getProperty("version")}" |val version = "${version}"
|val author = "${properties.getProperty("author")}" |val author = "${author}"
|val url = "${properties.getProperty("url")}" |val url = "${url}"
|val description = "${properties.getProperty("description")}" |val description = "${description}"
""".stripMargin + FileUtils.readFileToString(scalaFile, "UTF-8") """.stripMargin + FileUtils.readFileToString(scalaFile, "UTF-8")
try { try {
ScalaPlugin.eval(source) ScalaPlugin.eval(source)
if(getPlugin(pluginId).isDefined){
registerPlugin(model.Plugin(pluginId, version))
} else {
updatePlugin(model.Plugin(pluginId, version))
}
} catch { } catch {
case e: Exception => logger.warn(s"Error in plugin loading for ${scalaFile.getAbsolutePath}", e) case e: Exception => logger.warn(s"Error in plugin loading for ${scalaFile.getAbsolutePath}", e)
} }

View 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
}