mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 03:55:58 +01:00
(refs #32)Switch JavaScript processor to Rhino from Nashorn because GitBucket should work on both of JDK7 and JDK8
This commit is contained in:
@@ -39,6 +39,7 @@ object MyBuild extends Build {
|
|||||||
"org.apache.httpcomponents" % "httpclient" % "4.3",
|
"org.apache.httpcomponents" % "httpclient" % "4.3",
|
||||||
"org.apache.sshd" % "apache-sshd" % "0.11.0",
|
"org.apache.sshd" % "apache-sshd" % "0.11.0",
|
||||||
"com.typesafe.slick" %% "slick" % "1.0.1",
|
"com.typesafe.slick" %% "slick" % "1.0.1",
|
||||||
|
"org.mozilla" % "rhino" % "1.7R4",
|
||||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
"com.h2database" % "h2" % "1.3.173",
|
"com.h2database" % "h2" % "1.3.173",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime",
|
"ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime",
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package plugin
|
|||||||
|
|
||||||
import app.Context
|
import app.Context
|
||||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||||
import javax.script.ScriptEngineManager
|
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import jdk.nashorn.api.scripting.ScriptObjectMirror
|
import org.mozilla.javascript.{Context => JsContext}
|
||||||
|
import org.mozilla.javascript.{Function => JsFunction}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides extension points to plug-ins.
|
* Provides extension points to plug-ins.
|
||||||
@@ -46,47 +46,89 @@ object PluginSystem {
|
|||||||
private[PluginSystem] val repositoryActionList = ListBuffer[Action]()
|
private[PluginSystem] val repositoryActionList = ListBuffer[Action]()
|
||||||
private[PluginSystem] val globalActionList = ListBuffer[Action]()
|
private[PluginSystem] val globalActionList = ListBuffer[Action]()
|
||||||
|
|
||||||
def addRepositoryMenu(label: String, name: String, url: String, icon: String)(condition: Context => Boolean): Unit = {
|
// def addRepositoryMenu(label: String, name: String, url: String, icon: String)(condition: Context => Boolean): Unit = {
|
||||||
repositoryMenuList += RepositoryMenu(label, name, url, icon, condition)
|
// repositoryMenuList += RepositoryMenu(label, name, url, icon, condition)
|
||||||
|
// }
|
||||||
|
|
||||||
|
def addRepositoryMenu(label: String, name: String, url: String, icon: String, condition: JsFunction): Unit = {
|
||||||
|
repositoryMenuList += RepositoryMenu(label, name, url, icon, (context) => {
|
||||||
|
val context = JsContext.enter()
|
||||||
|
try {
|
||||||
|
condition.call(context, condition, condition, Array(context)).asInstanceOf[Boolean]
|
||||||
|
} finally {
|
||||||
|
JsContext.exit()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def addRepositoryMenu(label: String, name: String, url: String, icon: String, condition: ScriptObjectMirror): Unit = {
|
// def addGlobalMenu(label: String, url: String, icon: String)(condition: Context => Boolean): Unit = {
|
||||||
repositoryMenuList += RepositoryMenu(label, name, url, icon, (context) => condition.call(this, context).asInstanceOf[Boolean])
|
// globalMenuList += GlobalMenu(label, url, icon, condition)
|
||||||
|
// }
|
||||||
|
|
||||||
|
def addGlobalMenu(label: String, url: String, icon: String, condition: JsFunction): Unit = {
|
||||||
|
globalMenuList += GlobalMenu(label, url, icon, (context) => {
|
||||||
|
val context = JsContext.enter()
|
||||||
|
try {
|
||||||
|
condition.call(context, condition, condition, Array(context)).asInstanceOf[Boolean]
|
||||||
|
} finally {
|
||||||
|
JsContext.exit()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def addGlobalMenu(label: String, url: String, icon: String)(condition: Context => Boolean): Unit = {
|
// def addGlobalAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
||||||
globalMenuList += GlobalMenu(label, url, icon, condition)
|
// globalActionList += Action(path, function)
|
||||||
|
// }
|
||||||
|
|
||||||
|
def addGlobalAction(path: String, function: JsFunction): Unit = {
|
||||||
|
globalActionList += Action(path, (request, response) => {
|
||||||
|
val context = JsContext.enter()
|
||||||
|
try {
|
||||||
|
function.call(context, function, function, Array(request, response))
|
||||||
|
} finally {
|
||||||
|
JsContext.exit()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def addGlobalMenu(label: String, url: String, icon: String, condition: ScriptObjectMirror): Unit = {
|
// def addRepositoryAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
||||||
globalMenuList += GlobalMenu(label, url, icon, (context) => condition.call(this, context).asInstanceOf[Boolean])
|
// repositoryActionList += Action(path, function)
|
||||||
|
// }
|
||||||
|
|
||||||
|
def addRepositoryAction(path: String, function: JsFunction): Unit = {
|
||||||
|
repositoryActionList += Action(path, (request, response) => {
|
||||||
|
val context = JsContext.enter()
|
||||||
|
try {
|
||||||
|
function.call(context, function, function, Array(request, response))
|
||||||
|
} finally {
|
||||||
|
JsContext.exit()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def addGlobalAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
|
||||||
globalActionList += Action(path, function)
|
|
||||||
}
|
|
||||||
|
|
||||||
def addGlobalAction(path: String, function: ScriptObjectMirror): Unit = {
|
|
||||||
globalActionList += Action(path, (request, response) => function.call(this, request, response))
|
|
||||||
}
|
|
||||||
|
|
||||||
def addRepositoryAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
|
||||||
repositoryActionList += Action(path, function)
|
|
||||||
}
|
|
||||||
|
|
||||||
def addRepositoryAction(path: String, function: ScriptObjectMirror): Unit = {
|
|
||||||
repositoryActionList += Action(path, (request, response) => function.call(this, request, response))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def definePlugin(id: String, author: String, url: String, description: String): Plugin = new Plugin(id, author, url, description)
|
||||||
|
|
||||||
def evaluateJavaScript(script: String): Any = {
|
def evaluateJavaScript(script: String): Any = {
|
||||||
val engine = new ScriptEngineManager().getEngineByName("JavaScript")
|
val context = JsContext.enter()
|
||||||
logger.debug("Script: " + script)
|
try {
|
||||||
engine.put("PluginSystem", this)
|
val scope = context.initStandardObjects()
|
||||||
// TODO Support both of Nashorn and Rhino!
|
scope.put("PluginSystem", scope, this)
|
||||||
val result = engine.eval("var Plugin = Java.type(\"plugin.PluginSystem.Plugin\"); " + script)
|
val result = context.evaluateString(scope, script, "<cmd>", 1, null)
|
||||||
logger.debug("Result: " + result)
|
result
|
||||||
result
|
} finally {
|
||||||
|
JsContext.exit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// val engine = new ScriptEngineManager().getEngineByName("JavaScript")
|
||||||
|
// logger.debug("Script: " + script)
|
||||||
|
// engine.put("PluginSystem", this)
|
||||||
|
// // TODO Support both of Nashorn and Rhino!
|
||||||
|
// val result = engine.eval("var Plugin = Java.type(\"plugin.PluginSystem.Plugin\"); " + script)
|
||||||
|
// logger.debug("Result: " + result)
|
||||||
|
// result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user