001package org.apache.maven.cli.logging.impl;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.net.URL;
023import java.util.Map;
024import java.util.Set;
025
026import org.apache.maven.cli.logging.BaseSlf4jConfiguration;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Pseudo-configuration for unsupported slf4j binding.
032 *
033 * @author Hervé Boutemy
034 * @since 3.2.4
035 */
036public class UnsupportedSlf4jBindingConfiguration
037    extends BaseSlf4jConfiguration
038{
039    private final Logger logger = LoggerFactory.getLogger( UnsupportedSlf4jBindingConfiguration.class );
040
041    private String slf4jBinding;
042
043    private Map<URL, Set<Object>> supported;
044
045    public UnsupportedSlf4jBindingConfiguration( String slf4jBinding, Map<URL, Set<Object>> supported )
046    {
047        this.slf4jBinding = slf4jBinding;
048        this.supported = supported;
049    }
050
051    @Override
052    public void activate()
053    {
054        logger.warn( "The SLF4J binding actually used is not supported by Maven: " + slf4jBinding );
055        logger.warn( "Maven supported bindings are:" );
056
057        String ls = System.getProperty( "line.separator" );
058
059        for ( Map.Entry<URL, Set<Object>> entry : supported.entrySet() )
060        {
061            StringBuilder sb = new StringBuilder();
062            sb.append( "(from " ).append( entry.getKey().toExternalForm() ).append( ")" );
063
064            for ( Object binding : entry.getValue() )
065            {
066                sb.append( ls ).append( "- " ).append( binding );
067            }
068
069            logger.warn( sb.toString() );
070        }
071    }
072}