View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 v1.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.core.util;
15  
16  import static ch.qos.logback.core.CoreConstants.FA_FILENAME_COLLISION_MAP;
17  import static ch.qos.logback.core.CoreConstants.RFA_FILENAME_PATTERN_COLLISION_MAP;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Properties;
23  
24  import ch.qos.logback.core.Context;
25  import ch.qos.logback.core.rolling.helper.FileNamePattern;
26  import ch.qos.logback.core.spi.ContextAwareBase;
27  
28  public class ContextUtil extends ContextAwareBase {
29  
30      public ContextUtil(Context context) {
31          setContext(context);
32      }
33  
34  
35      public void addProperties(Properties props) {
36          if (props == null) {
37              return;
38          }
39          @SuppressWarnings("rawtypes")
40          Iterator i = props.keySet().iterator();
41          while (i.hasNext()) {
42              String key = (String) i.next();
43              context.putProperty(key, props.getProperty(key));
44          }
45      }
46  
47      public static Map<String, String> getFilenameCollisionMap(Context context) {
48          if (context == null)
49              return null;
50          @SuppressWarnings("unchecked")
51          Map<String, String> map = (Map<String, String>) context.getObject(FA_FILENAME_COLLISION_MAP);
52          return map;
53      }
54  
55      public static Map<String, FileNamePattern> getFilenamePatternCollisionMap(Context context) {
56          if (context == null)
57              return null;
58          @SuppressWarnings("unchecked")
59          Map<String, FileNamePattern> map = (Map<String, FileNamePattern>) context.getObject(RFA_FILENAME_PATTERN_COLLISION_MAP);
60          return map;
61      }
62      
63      public void addGroovyPackages(List<String> frameworkPackages) {
64          // addFrameworkPackage(frameworkPackages, "groovy.lang");
65          addFrameworkPackage(frameworkPackages, "org.codehaus.groovy.runtime");
66      }
67  
68      public void addFrameworkPackage(List<String> frameworkPackages, String packageName) {
69          if (!frameworkPackages.contains(packageName)) {
70              frameworkPackages.add(packageName);
71          }
72      }
73  
74  }