Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@quidryan
Last active December 16, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quidryan/5491942 to your computer and use it in GitHub Desktop.
Save quidryan/5491942 to your computer and use it in GitHub Desktop.
Hack to get my afterEvaluation blocks to go before other ones.
beforeAfterEvaluate {
println "Nah, nah, nah. I'm first"
}
def BroadcastDispatch<ProjectEvaluationListener> getProjectEvaluationListeners() {
ProjectEvaluationListener listener = ((AbstractProject) project).getProjectEvaluationBroadcaster();
def /* org.gradle.messaging.dispatch.ProxyDispatchAdapter.DispatchingInvocationHandler */ h = ((java.lang.reflect.Proxy) listener).h
BroadcastDispatch<ProjectEvaluationListener> dispatcher = h.dispatch
return dispatcher
}
def beforeAfterEvaluate(Closure beforeEvaluateClosure) {
BroadcastDispatch<ProjectEvaluationListener> broadcast = getProjectEvaluationListeners()
final String methodName = 'afterEvaluate'
Dispatch<MethodInvocation> invocation = new ClosureBackedMethodInvocationDispatch(methodName, beforeEvaluateClosure)
Map<Object, Dispatch<MethodInvocation>> prependedHandlers = new LinkedHashMap<Object, Dispatch<MethodInvocation>>();
prependedHandlers.put(invocation, invocation);
prependedHandlers.putAll( broadcast.handlers )
broadcast.handlers.clear()
broadcast.handlers.putAll(prependedHandlers)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment