1 package org.apache.maven.cli.logging;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.net.URL;
24 import java.util.Enumeration;
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27 import java.util.Properties;
28 import java.util.Set;
29
30 import org.apache.maven.cli.logging.impl.UnsupportedSlf4jBindingConfiguration;
31 import org.codehaus.plexus.util.PropertyUtils;
32 import org.slf4j.ILoggerFactory;
33
34
35
36
37
38
39
40
41
42 public class Slf4jConfigurationFactory
43 {
44 public static final String RESOURCE = "META-INF/maven/slf4j-configuration.properties";
45
46 public static Slf4jConfiguration getConfiguration( ILoggerFactory loggerFactory )
47 {
48 Map<URL, Set<Object>> supported = new LinkedHashMap<>();
49
50 String slf4jBinding = loggerFactory.getClass().getCanonicalName();
51
52 try
53 {
54 Enumeration<URL> resources = Slf4jConfigurationFactory.class.getClassLoader().getResources( RESOURCE );
55
56 while ( resources.hasMoreElements() )
57 {
58 URL resource = resources.nextElement();
59
60 Properties conf = PropertyUtils.loadProperties( resource.openStream() );
61
62 String impl = conf.getProperty( slf4jBinding );
63
64 if ( impl != null )
65 {
66 return (Slf4jConfiguration) Class.forName( impl ).newInstance();
67 }
68
69 supported.put( resource, conf.keySet() );
70 }
71 }
72 catch ( IOException | ClassNotFoundException | IllegalAccessException | InstantiationException e )
73 {
74 e.printStackTrace();
75 }
76
77 return new UnsupportedSlf4jBindingConfiguration( slf4jBinding, supported );
78 }
79 }