All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juli.logging.ch.qos.logback.classic.util.ClassicEnvUtil Maven / Gradle / Ivy

There is a newer version: 10.1.24
Show newest version
/**
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */
package org.apache.juli.logging.ch.qos.logback.classic.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

import org.apache.juli.logging.ch.qos.logback.core.util.EnvUtil;
import org.apache.juli.logging.ch.qos.logback.core.util.Loader;

/**
 * @author Ceki Gülcü
 */
public class ClassicEnvUtil {

    /*
     * Used to replace the ClassLoader that the ServiceLoader uses for unit testing.
     * We need this to mock the resources the ServiceLoader attempts to load from
     * /META-INF/services thus keeping the projects src/test/resources clean (see
     * src/test/resources/README.txt).
     */
    //static ClassLoader testServiceLoaderClassLoader = null;

    static public boolean isGroovyAvailable() {
        return EnvUtil.isClassAvailable(ClassicEnvUtil.class, "groovy.lang.Binding");
    }
//
//    private static ClassLoader getServiceLoaderClassLoader() {
//        return testServiceLoaderClassLoader == null ? Loader.getClassLoaderOfClass(ClassicEnvUtil.class)
//                : testServiceLoaderClassLoader;
//    }

    public static  List loadFromServiceLoader(Class c, ClassLoader classLoader) {
        ServiceLoader loader = ServiceLoader.load(c, classLoader);
        List listOfT = new ArrayList<>();
        Iterator it = loader.iterator();
        while(it.hasNext()) {
            T t = it.next();
            listOfT.add(t);
        }
        return listOfT;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy