init.d
gradle.projectsLoaded { println "Hi from loaded" }
script.run->
//script = init_c691rc.... , 也是后面closure _run_closure1 的delegate
通过groovy的closure调用机制
->DefaultGradle.java
public void projectsLoaded(Closure closure) {
buildListenerBroadcast.add(new ClosureBackedMethodInvocationDispatch("projectsLoaded", closure));
}
//new 一个ClosureBackedMethodInvocationDispatch对象
后面走到doBuildStages的
buildListener.projectsLoaded(gradle);的时候
org.gradle.listener.ClosureBackedMethodInvocationDispatch
public void dispatch(MethodInvocation message) {
if (message.getMethod().getName().equals(methodName)) {
Object[] parameters = message.getArguments();
if (closure.getMaximumNumberOfParameters() < parameters.length) {
parameters = Arrays.asList(parameters).subList(0, closure.getMaximumNumberOfParameters()).toArray();
}
closure.call(parameters);
}
}
这个closure就是 init_c69lrc3uiec789gk9t0jr56ux$_run_closure1
parameters 是 [build ‘G‘]
结果就是输出一行
原文地址:http://blog.csdn.net/cleverwyq/article/details/43717531