Gradle原碼入門七,gradle原碼

來源:互聯網
上載者:User

Gradle原碼入門七,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()


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.