1 /*
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4 *
5 * This program and the accompanying materials are dual-licensed under
6 * either the terms of the Eclipse Public License v2.0 as published by
7 * the Eclipse Foundation
8 *
9 * or (per the licensee's choosing)
10 *
11 * under the terms of the GNU Lesser General Public License version 2.1
12 * as published by the Free Software Foundation.
13 */
14 package ch.qos.logback.classic.util;
15
16 import java.lang.module.ModuleDescriptor;
17 import java.util.*;
18
19 import ch.qos.logback.classic.ClassicConstants;
20 import ch.qos.logback.core.util.EnvUtil;
21 import ch.qos.logback.core.util.VersionUtil;
22
23 /**
24 * @author Ceki Gülcü
25 */
26 public class ClassicEnvUtil {
27
28 /*
29 * Used to replace the ClassLoader that the ServiceLoader uses for unit testing.
30 * We need this to mock the resources the ServiceLoader attempts to load from
31 * /META-INF/services thus keeping the projects src/test/resources clean (see
32 * src/test/resources/README.txt).
33 */
34 //static ClassLoader testServiceLoaderClassLoader = null;
35
36 static public boolean isGroovyAvailable() {
37 return EnvUtil.isClassAvailable(ClassicEnvUtil.class, "groovy.lang.Binding");
38 }
39
40 public static <T> List<T> loadFromServiceLoader(Class<T> c, ClassLoader classLoader) {
41 ServiceLoader<T> loader = ServiceLoader.load(c, classLoader);
42 List<T> listOfT = new ArrayList<>();
43 Iterator<T> it = loader.iterator();
44 while(it.hasNext()) {
45 T t = it.next();
46 listOfT.add(t);
47 }
48 return listOfT;
49 }
50
51 /**
52 * <p>Returns the current version of logback-classic, or null if data is not
53 * available.
54 * </p>
55 *
56 * TODO: remove in 1.6
57 *
58 * @since 1.5.15
59 * @return current version or null if missing version data
60 * @deprecated See {@link ch.qos.logback.classic.util.ClassicVersionUtil#getVersionBySelfDeclaredProperties()}
61 *
62 */
63 @Deprecated
64 static public String getVersionOfLogbackClassic() {
65 try {
66 return VersionUtil.getVersionOfArtifact(ClassicConstants.class);
67 } catch (NoClassDefFoundError e) {
68 return null;
69 }
70 }
71
72 }