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