PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/resources/examples/MapAsInterfaceTests.groovy

https://bitbucket.org/aschuma/scriptrunner-public-2.0.9
Groovy | 64 lines | 50 code | 14 blank | 0 comment | 2 complexity | e7463d2a67002403f2eaafbf716e9dc8 MD5 | raw file
  1. import com.atlassian.core.action.ActionUtils
  2. import com.atlassian.core.ofbiz.CoreFactory
  3. import com.atlassian.jira.ComponentManager
  4. import com.atlassian.jira.action.ActionNames
  5. import com.atlassian.jira.event.ListenerManager
  6. import com.atlassian.jira.event.listeners.DebugListener
  7. import org.apache.log4j.Category
  8. import webwork.dispatcher.ActionResult
  9. import com.atlassian.jira.event.issue.IssueEventListener
  10. import org.netbeans.lib.cvsclient.commandLine.command.log
  11. import com.atlassian.jira.event.issue.IssueEvent
  12. Category log = Category.getInstance("com.onresolve.jira.groovy.Scratch")
  13. ComponentManager componentManager = ComponentManager.getInstance()
  14. class AwesomePostFunction {
  15. Category log = Category.getInstance("com.acme.AwesomePostFunction")
  16. void doStuff() {
  17. log.fatal("doStuff")
  18. log.fatal(this.class.getName())
  19. }
  20. }
  21. log.debug("Script name: ${this.class.getName()}")
  22. (new AwesomePostFunction()).doStuff()
  23. return
  24. IssueEventListener getMapAsInterface() {
  25. def map = [:]
  26. IssueEventListener.class.methods.each() { method ->
  27. map."$method.name" = { Object[] args ->
  28. println "Called method ${method.name} with ${args}"
  29. }
  30. }
  31. map.toString = {-> "dynamic interface impl "}
  32. return map.asType(IssueEventListener.class) as IssueEventListener
  33. }
  34. IssueEventListener issueEventListener = getMapAsInterface()
  35. log.debug(this.class.getName())
  36. log.debug(issueEventListener.class.getName())
  37. return
  38. issueEventListener.metaClass.constructor = {println "EMC Ctor"}
  39. log.debug "InstallListener running"
  40. String LISTENER_NAME = "Debug ListenerX";
  41. ListenerManager listenerManager = (ListenerManager) ComponentManager.getInstance().getContainer().getComponentInstance(ListenerManager.class)
  42. if (!listenerManager.getListeners().containsKey(LISTENER_NAME)) {
  43. ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.LISTENER_CREATE,
  44. ["name": LISTENER_NAME, "clazz": issueEventListener.class.getName()])
  45. ActionUtils.checkForErrors(aResult);
  46. log.info "Installed listener $LISTENER_NAME"
  47. }
  48. else {
  49. log.debug "Listener $LISTENER_NAME already installed"
  50. }