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  import org.apache.maven.cli.logging.BaseSlf4jConfiguration;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /**
29   * Pseudo-configuration for unsupported slf4j binding.
30   *
31   * @author Hervé Boutemy
32   * @since 3.2.4
33   */
34  public class UnsupportedSlf4jBindingConfiguration extends BaseSlf4jConfiguration {
35      private static final Logger LOGGER = LoggerFactory.getLogger(UnsupportedSlf4jBindingConfiguration.class);
36  
37      private String slf4jBinding;
38  
39      private Map<URL, Set<Object>> supported;
40  
41      public UnsupportedSlf4jBindingConfiguration(String slf4jBinding, Map<URL, Set<Object>> supported) {
42          this.slf4jBinding = slf4jBinding;
43          this.supported = supported;
44      }
45  
46      @Override
47      public void activate() {
48          LOGGER.warn("The SLF4J binding actually used is not supported by Maven: {}", slf4jBinding);
49          LOGGER.warn("Maven supported bindings are:");
50  
51          String ls = System.lineSeparator();
52  
53          for (Map.Entry<URL, Set<Object>> entry : supported.entrySet()) {
54              StringBuilder sb = new StringBuilder();
55              sb.append("(from ").append(entry.getKey().toExternalForm()).append(')');
56  
57              for (Object binding : entry.getValue()) {
58                  sb.append(ls).append("- ").append(binding);
59              }
60  
61              LOGGER.warn(sb.toString());
62          }
63      }
64  }