Gradle source code entry 7: gradle source code

Source: Internet
Author: User

Gradle source code entry 7: gradle source code

Today I analyzed the Object org. gradle. internal. service. DefaultServiceRegistry. doGet (Type serviceType) function.


    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));        }    }



The focus here is context. find (serviceType, allServices );

AllServices is a variable of the CompositeProvider type. When serviceType is a value

In the getService of the CompositeProvider class, the class diagram shows that it also maintains a List of providers,

Traverse the list and continue provider. getSerivce.

Ownservices is also a member of allServices. providers by default.

  1. FindDecoratorMethods (target, type, methods, ownServices );
  2. FindFactoryMethods (target, type, methods, ownServices );
Come,


Result

For example, when serviceType is interface org. gradle. logging. StyledTextOutputFactory

Provider is Service StyledTextOutputFactory at LoggingServiceRegistry. createStyledTextOutputFactory ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.