码迷,mamicode.com
首页 > 其他好文 > 详细

Gradle原码入门七

时间:2015-01-11 01:01:28      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:gradle   源码   调试   

今天分析了Object org.gradle.internal.service.DefaultServiceRegistry.doGet(Type serviceType) 函数


    private Object doGet(Type serviceType) throws IllegalArgumentException {
        synchronized (lock) {
            if (closed) {
                throw new IllegalStateException(String.format("Cannot locate service of type %s, as %s has been closed.", format(serviceType), displayName));
            }

            DefaultLookupContext context = new DefaultLookupContext();
            ServiceProvider provider = context.find(serviceType, allServices);
            if (provider != null) {
                return provider.get();
            }

            throw new UnknownServiceException(serviceType, String.format("No service of type %s available in %s.", format(serviceType), displayName));
        }
    }

技术分享


这里重点是context.find(serviceType, allServices);

allServices 是一个CompositeProvider型变量, 在serviceType是某些值的时候,会走到

CompositeProvider类的getService里面, 类图可以看到它自身也维护了一个Provider的List,

遍历该list,   继续provider.getSerivce

默认ownservices也是allServices.providers的一员, ownServices的几何从前文<六>中的

  1.   findDecoratorMethods(target, type, methods, ownServices);  
  2.             findFactoryMethods(target, type, methods, ownServices);  
中来,


结果

例如当serviceType是 interface org.gradle.logging.StyledTextOutputFactory

provider就是Service StyledTextOutputFactory at LoggingServiceRegistry.createStyledTextOutputFactory()


Gradle原码入门七

标签:gradle   源码   调试   

原文地址:http://blog.csdn.net/cleverwyq/article/details/42592401

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!