scriptrunner-public-sorin /src/test/resources/examples/MapAsInterfaceTests.groovy

Language Groovy Lines 65
MD5 Hash 6f3cc291199a529ba026fb1eb4e986c7
Repository https://bitbucket.org/sorin/scriptrunner-public-sorin View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import com.atlassian.core.action.ActionUtils
import com.atlassian.core.ofbiz.CoreFactory
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.action.ActionNames
import com.atlassian.jira.event.ListenerManager
import com.atlassian.jira.event.listeners.DebugListener
import org.apache.log4j.Category
import webwork.dispatcher.ActionResult
import com.atlassian.jira.event.issue.IssueEventListener
import org.netbeans.lib.cvsclient.commandLine.command.log
import com.atlassian.jira.event.issue.IssueEvent

Category log = Category.getInstance("com.onresolve.jira.groovy.Scratch")

ComponentManager componentManager = ComponentManager.getInstance()

class AwesomePostFunction {
    Category log = Category.getInstance("com.acme.AwesomePostFunction")
    void doStuff() {
        log.fatal("doStuff")
        log.fatal(this.class.getName())
    }
}

log.debug("Script name: ${this.class.getName()}")
(new AwesomePostFunction()).doStuff()
return

IssueEventListener getMapAsInterface() {
    def map = [:]

    IssueEventListener.class.methods.each() { method ->
        map."$method.name" = { Object[] args ->
            println "Called method ${method.name} with ${args}"
        }
    }
    map.toString = {-> "dynamic interface impl "}

    return map.asType(IssueEventListener.class) as IssueEventListener
}

IssueEventListener issueEventListener = getMapAsInterface()
log.debug(this.class.getName()) 
log.debug(issueEventListener.class.getName())
return

issueEventListener.metaClass.constructor = {println "EMC Ctor"}


log.debug "InstallListener running"

String LISTENER_NAME = "Debug ListenerX";

ListenerManager listenerManager = (ListenerManager) ComponentManager.getInstance().getContainer().getComponentInstance(ListenerManager.class)

if (!listenerManager.getListeners().containsKey(LISTENER_NAME)) {
    ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.LISTENER_CREATE,
            ["name": LISTENER_NAME, "clazz": issueEventListener.class.getName()])
    ActionUtils.checkForErrors(aResult);
    log.info "Installed listener $LISTENER_NAME"
}
else {
    log.debug "Listener $LISTENER_NAME already installed"
}
Back to Top