diff --git a/src/main/resources/update/2_3.sql b/src/main/resources/update/2_3.sql new file mode 100644 index 0000000..7620092 --- /dev/null +++ b/src/main/resources/update/2_3.sql @@ -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); diff --git a/src/main/scala/model/Plugin.scala b/src/main/scala/model/Plugin.scala new file mode 100644 index 0000000..3295a33 --- /dev/null +++ b/src/main/scala/model/Plugin.scala @@ -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 +) diff --git a/src/main/scala/model/Profile.scala b/src/main/scala/model/Profile.scala index 9bfee3b..10e2ab1 100644 --- a/src/main/scala/model/Profile.scala +++ b/src/main/scala/model/Profile.scala @@ -31,7 +31,8 @@ with PullRequestComponent with RepositoryComponent with SshKeyComponent - with WebHookComponent with Profile { + with WebHookComponent + with PluginComponent with Profile { /** * Returns system date. diff --git a/src/main/scala/plugin/PluginSystem.scala b/src/main/scala/plugin/PluginSystem.scala index 8caf6bf..2afaa6e 100644 --- a/src/main/scala/plugin/PluginSystem.scala +++ b/src/main/scala/plugin/PluginSystem.scala @@ -9,12 +9,12 @@ 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 @@ 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) } diff --git a/src/main/scala/service/PluginService.scala b/src/main/scala/service/PluginService.scala new file mode 100644 index 0000000..12f97fb --- /dev/null +++ b/src/main/scala/service/PluginService.scala @@ -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 + +}