Discover all the service provider implementations of the given class,
via {@code META-INF/services}.
@deprecated Use {@link ServiceLoader} instead, or (more commonly) {@link ExtensionList}.
179478
@Deprecated
    public <T> Collection<Class<? extends T>> discover( Class<T> spi ) {
        Set<Class<? extends T>> result = new HashSet<>();

        for (PluginWrapper p : activePlugins) {
            Service.load(spi, p.classLoader, result);
        }

        return result;
    }
944764
private Map<String, List<String>> findImplementations(ClassLoader loader,
                                                          List<Class<?>> interfaceClasses) throws MojoExecutionException {
        Map<String, List<String>> serviceImplementations = new HashMap<String, List<String>>();
        for (String interfaceClassName : getServices()) {
            serviceImplementations.put(interfaceClassName, new ArrayList<String>());
        }
        getLog().info("Scanning generated classes for implementations...");
        File classFolder = getClassFolder();
        List<String> classNames = listCompiledClasses(classFolder);
        // List<String> classNames = listCompiledClassesRegex( classFolder );
        for (String className : classNames) {
            try {
                if(getLog().isDebugEnabled()){
                    getLog().debug("checking class: " + className);
                }
                Class<?> cls = loader.loadClass(className);
                int mods = cls.getModifiers();
                if (!cls.isAnonymousClass() && !cls.isInterface()
                        && !cls.isEnum() && !Modifier.isAbstract(mods)
                        && Modifier.isPublic(mods)) {
                    for (Class<?> interfaceCls : interfaceClasses) {
                        if (!interfaceCls.equals(cls) && interfaceCls.isAssignableFrom(cls)) {
                            
                            // if the includes section isn't empty, we need to respect the choice and only include the items that are shown there.
                            if (includes == null || includes.length == 0) {
                                serviceImplementations.get(interfaceCls.getName()).add(className);
                            } else {
                                for ( String include : includes )
                                {
                                    if(SelectorUtils.match(include, className)) {
                                        serviceImplementations.get(interfaceCls.getName()).add(className);
                                    }
                                }
                            }
                            
                        }
                    }
                }
            } catch (ClassNotFoundException e1) {
                getLog().warn(e1);
            } catch (NoClassDefFoundError e2) {
                getLog().warn(e2);
            }
            
        }
        
        // in the next iteration we start to process with the excludes
        if (excludes != null && excludes.length != 0) {
            Set<Entry<String,List<String>>> entrySet = serviceImplementations.entrySet();
            for ( Entry<String, List<String>> entry : entrySet )
            {
                classNames = entry.getValue();
                ListIterator<String> classNamesIter = classNames.listIterator();
                
                while ( classNamesIter.hasNext())
                {
                    String className = classNamesIter.next();
                    for ( String exclude : excludes )
                    {
                        if(SelectorUtils.match(exclude, className)) {
                          classNamesIter.remove();
                          break;
                        }
                    }
                }
            }
        }
        return serviceImplementations;
    }
705312
@VisibleForTesting
  public static <T> Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl) {
    return ServiceProviders.getCandidatesViaServiceLoader(klass, cl);
  }
43503
public PluginLoader withExtensionPoints(Class... extensionPoints) {
        this.extensionPoints.addAll(
                Stream.of(extensionPoints)
                        .distinct()
                        .collect(Collectors.<Class>toList())
        );
        return this;
    }
847019
public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> clazz, ExtensionLoaderListener<T> listener) {
        ExtensionLoader<T> loader = LOADER_MAP.get(clazz);
        if (loader == null) {
            synchronized (ExtensionLoaderFactory.class) {
                loader = LOADER_MAP.get(clazz);
                if (loader == null) {
                    loader = new ExtensionLoader<T>(clazz, listener);
                    LOADER_MAP.put(clazz, loader);
                }
            }
        }
        return loader;
    }
737859
public static <T> T loadAnyServiceProvider( Class<T> klass )
    {
        T provider = findAnyServiceProvider( klass );
        if (provider == null) {
            throw new NoServiceProviderException( klass.getName()
                + ": no service provider found in META-INF/services on classpath" );            
        }
        return provider;
    }
318883
public static ClassLoader getServiceClassLoader(String serviceUniqueName) {
        ClassLoader appClassLoader = SERVICE_CLASSLOADER_MAP.get(serviceUniqueName);
        if (appClassLoader == null) {
            return ClassLoaderUtils.getCurrentClassLoader();
        } else {
            return appClassLoader;
        }
    }
717242
public static <T> List<T> getServices(Class<T> intf) {
        List<T> ret = new ArrayList<T>();

        for (T service : ServiceLoader.load(intf)) {
            if (!(service instanceof ServiceStatus) || ((ServiceStatus)service).isAvailable()) {
                if (service instanceof ServiceLifecycle) {
                    ((ServiceLifecycle)service).init();
                }

                ret.add(service);
            }
        }

        return ret;
    }
1173114
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError {
        String serviceId = "META-INF/services/" + factoryId;
        InputStream is = null;

        // First try the Context ClassLoader
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl != null) {
            is = cl.getResourceAsStream(serviceId);
        }

        if (is == null) {
            cl = FactoryFinder.class.getClassLoader();
            is = cl.getResourceAsStream(serviceId);
        }

        if (is == null) {
            // No provider found
            return null;
        }

        if (debug) debugPrintln("found jar resource=" + serviceId + " using ClassLoader: " + cl);

        BufferedReader rd;
        try {
            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
        } catch (java.io.UnsupportedEncodingException e) {
            rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
        }

        String factoryClassName = null;
        try {
            // XXX Does not handle all possible input as specified by the
            // Jar Service Provider specification
            factoryClassName = rd.readLine();
        } catch (IOException x) {
            // No provider found
            return null;
        } finally {
            IoUtils.closeQuietly(rd);
        }

        if (factoryClassName != null &&
            ! "".equals(factoryClassName)) {
            if (debug) debugPrintln("found in resource, value="
                   + factoryClassName);

            return newInstance(factoryClassName, cl);
        }

        // No provider found
        return null;
    }
443851
private <T> List<T> loadServices(final Class<T> serviceType) {
        List<T> services = new ArrayList<>();
        try {
            for (T t : ServiceLoader.load(serviceType)) {
                services.add(t);
            }
            services.sort(Comparator.comparing(o -> o.getClass().getSimpleName()));
            @SuppressWarnings("unchecked")
            final List<T> previousServices = (List<T>) servicesLoaded.putIfAbsent(serviceType, (List<Object>) services);
            return Collections.unmodifiableList(previousServices != null ? previousServices : services);
        } catch (Exception e) {
            Logger.getLogger(DefaultServiceProvider.class.getName()).log(Level.WARNING,
                                                                         "Error loading services of type " + serviceType, e);
            return services;
        }
    }
227075
@Override
    public Set<String> getExtensionClasses() {

        Set<String> serviceClazzes = new HashSet<>();

        if (getType() == ArchiveType.WEB_MODULE) {
            Resource webInfClassesMetaInfServicesEntry = getResource(CDIUtils.WEB_INF_CLASSES_META_INF_SERVICES_CDI_EXTENSION);
            serviceClazzes.addAll(CDIUtils.parseServiceSPIExtensionFile(webInfClassesMetaInfServicesEntry));
        }

        Resource metaInfServicesEntry = getResource(CDIUtils.META_INF_SERVICES_CDI_EXTENSION);
        serviceClazzes.addAll(CDIUtils.parseServiceSPIExtensionFile(metaInfServicesEntry));
        return serviceClazzes;
    }
188940
@Deprecated
    public static List<Service> getServices(String type,
            List<String> algorithms) {
        ProviderList list = Providers.getProviderList();
        return list.getServices(type, algorithms);
    }
708338
public static <T> List<T> load(final Class<T> type, final ClassLoader classLoader) {
        final List<T> loaded = new ArrayList<>();
        final Iterator<T> iterator = ServiceLoader.load(type, classLoader).iterator();
        while (hasNextSafely(iterator)) {
            try {
                final T next = iterator.next();
                loaded.add(next);
                LOGGER.debug("Found {}", type);
            } catch (Exception e) {
                LOGGER.error("Could not load {}: {}", type, e);
            }
        }
        return loaded;
    }
1270343
private <T> Set<Class<? extends T>> load(Class<T> serviceClass) {
        String serviceFile = SERVICES + "/" + serviceClass.getName();

        LinkedHashSet<Class<? extends T>> providers = new LinkedHashSet<Class<? extends T>>();

        try {
            Enumeration<URL> enumeration = classLoader.getResources(serviceFile);
            while (enumeration.hasMoreElements()) {
                final URL url = enumeration.nextElement();
                final InputStream is = url.openStream();
                BufferedReader reader = null;

                try {
                    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    String line = reader.readLine();
                    while (null != line) {
                        line = skipCommentAndTrim(line);

                        if (line.length() > 0) {
                            try {
                                Class<? extends T> provider = classLoader.loadClass(line).asSubclass(serviceClass);
                                providers.add(provider);
                            } catch (ClassCastException e) {
                                ClassLoader other = serviceClass.getClassLoader();
                                if (!classLoader.getClass().equals(serviceClass.getClassLoader())) {
                                    throw new IllegalStateException("Service " + line
                                        + " was loaded by different classloader (" + (other == null ? "bootstrap"
                                            : other.getClass().getName()) + ") then service interface "
                                        + serviceClass.getName() + " (" + classLoader.getClass().getName()
                                        + "), unable to cast classes");
                                }
                                throw new IllegalStateException("Service " + line + " does not implement expected type "
                                    + serviceClass.getName());
                            }
                        }
                        line = reader.readLine();
                    }
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not load services for " + serviceClass.getName(), e);
        }
        return providers;
    }
473662
private List<Class<?>> loadServiceClasses(ClassLoader loader)
            throws MojoExecutionException {
        List<Class<?>> serviceClasses = new ArrayList<Class<?>>();
        for (String serviceClassName : getServices()) {
            try {
                Class<?> serviceClass = loader.loadClass(serviceClassName);
                serviceClasses.add(serviceClass);
            } catch (ClassNotFoundException ex) {
                throw new MojoExecutionException("Could not load class: " + serviceClassName, ex);
            }
        }
        return serviceClasses;
    }
928253
public <T extends ServiceConfiguration<?>> List<T> getExistingServiceConfigurations(Class<T> clazz) {
    ArrayList<T> results = new ArrayList<>();
    for (ServiceConfiguration<?> serviceConfiguration : serviceConfigurations) {
      if (clazz.equals(serviceConfiguration.getClass())) {
        results.add(clazz.cast(serviceConfiguration));
      }
    }
    return results;
  }
690744
public static List<WorkItemHandlerBuilder> builders(ClassLoader classLoader, ServiceDomain serviceDomain, KnowledgeComponentImplementationModel implementationModel) {
        List<WorkItemHandlerBuilder> builders = new ArrayList<WorkItemHandlerBuilder>();
        Set<String> registeredNames = new HashSet<String>();
        if (implementationModel != null) {
            WorkItemHandlersModel workItemHandlersModel = implementationModel.getWorkItemHandlers();
            if (workItemHandlersModel != null) {
                for (WorkItemHandlerModel workItemHandlerModel : workItemHandlersModel.getWorkItemHandlers()) {
                    if (workItemHandlerModel != null) {
                        WorkItemHandlerBuilder builder = new WorkItemHandlerBuilder(classLoader, serviceDomain, workItemHandlerModel);
                        builders.add(builder);
                        String name = builder.getWorkItemHandlerName();
                        if (name != null) {
                            registeredNames.add(name);
                        }
                    }
                }
            }
            // add our default WorkItemHandlers if they haven't already been added
            for (Entry<String, Class<? extends WorkItemHandler>> entry : DEFAULT_HANDLERS.entrySet()) {
                String name = entry.getKey();
                if (!registeredNames.contains(name)) {
                    WorkItemHandlerBuilder builder = new WorkItemHandlerBuilder(classLoader, serviceDomain, implementationModel, entry.getValue(), name);
                    builders.add(builder);
                    registeredNames.add(name);
                }
            }
        }
        return builders;
    }