View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.cli.logging.impl;
20  
21  import java.net.URL;
22  import java.util.Map;
23  import java.util.Set;
24  
25  import org.apache.maven.cli.logging.BaseSlf4jConfiguration;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  /**
30   * Pseudo-configuration for unsupported slf4j binding.
31   *
32   * @author Hervé Boutemy
33   * @since 3.2.4
34   */
35  public class UnsupportedSlf4jBindingConfiguration extends BaseSlf4jConfiguration {
36      private final Logger logger = LoggerFactory.getLogger(UnsupportedSlf4jBindingConfiguration.class);
37  
38      private String slf4jBinding;
39  
40      private Map<URL, Set<Object>> supported;
41  
42      public UnsupportedSlf4jBindingConfiguration(String slf4jBinding, Map<URL, Set<Object>> supported) {
43          this.slf4jBinding = slf4jBinding;
44          this.supported = supported;
45      }
46  
47      @Override
48      public void activate() {
49          logger.warn("The SLF4J binding actually used is not supported by Maven: {}", slf4jBinding);
50          logger.warn("Maven supported bindings are:");
51  
52          String ls = System.lineSeparator();
53  
54          for (Map.Entry<URL, Set<Object>> entry : supported.entrySet()) {
55              StringBuilder sb = new StringBuilder();
56              sb.append("(from ").append(entry.getKey().toExternalForm()).append(')');
57  
58              for (Object binding : entry.getValue()) {
59                  sb.append(ls).append("- ").append(binding);
60              }
61  
62              logger.warn(sb.toString());
63          }
64      }
65  }