(refs #812)Add new extension point to serve Git repository by plug-in
1 parent 3d5e4a4 commit 6f7579f8d9e50c884eb00e4d1ae3e2f73cc15975
@Naoki Takezoe Naoki Takezoe authored on 4 Jul 2015
Showing 4 changed files
View
13
src/main/scala/gitbucket/core/plugin/Plugin.scala
*/
def renderers(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(String, Renderer)] = Nil
 
/**
* Override to add git repository routings.
*/
val repositoryRoutings: Seq[(String, String)] = Nil
 
/**
* Override to add git repository routings.
*/
def repositoryRoutings(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(String, String)] = Nil
 
/**
* This method is invoked in initialization of plugin system.
* Register plugin functionality to PluginRegistry.
*/
def initialize(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {
registry.addJavaScript(path, script)
}
(renderers ++ renderers(registry, context, settings)).foreach { case (extension, renderer) =>
registry.addRenderer(extension, renderer)
}
(repositoryRoutings ++ repositoryRoutings(registry, context, settings)).foreach { case (urlPath, localPath) =>
registry.addRepositoryRouting(urlPath, localPath)
}
}
 
/**
View
20
src/main/scala/gitbucket/core/plugin/PluginRegistory.scala
private val renderers = mutable.Map[String, Renderer]()
renderers ++= Seq(
"md" -> MarkdownRenderer, "markdown" -> MarkdownRenderer
)
private val repositoryRoutings = new ListBuffer[(String, String)]
 
def addPlugin(pluginInfo: PluginInfo): Unit = {
plugins += pluginInfo
}
renderers.get(extension).getOrElse(DefaultRenderer)
}
 
def renderableExtensions: Seq[String] = renderers.keys.toSeq
 
def addRepositoryRouting(urlPath: String, localPath: String): Unit = {
repositoryRoutings += ((urlPath, localPath))
}
 
def getRepositoryRoutings(): Seq[(String, String)] = {
repositoryRoutings.toSeq
}
 
def getRepositoryRouting(requestURI: String): Option[(String, String)] = {
val path = requestURI.replaceFirst("^/git/", "")
 
PluginRegistry().getRepositoryRoutings().find {
case (urlPath, localPath) => {
println(urlPath)
path.matches(urlPath + "(/.*)?")
}
}
}
 
private case class GlobalAction(
method: String,
path: String,
View
src/main/scala/gitbucket/core/servlet/BasicAuthenticationFilter.scala
View
src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala