mirror of https://github.com/apache/maven.git
[MNG-7983] Switch to slf4j-api 2 (#1358)
This commit is contained in:
parent
5baa2f4098
commit
979fc9a5b6
|
@ -1,24 +0,0 @@
|
|||
Copyright (c) 2004-2022 QOS.ch Sarl (Switzerland)
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
Copyright (c) 2004-2023 QOS.ch
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -34,6 +34,6 @@ public class BaseSlf4jConfiguration implements Slf4jConfiguration {
|
|||
}
|
||||
|
||||
public void activate() {
|
||||
LOGGER.warn("reset(): operation not supported");
|
||||
LOGGER.warn("activate(): operation not supported");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
package org.apache.maven.cli.logging.impl;
|
||||
|
||||
import org.apache.maven.cli.logging.BaseSlf4jConfiguration;
|
||||
import org.slf4j.MavenSlf4jFriend;
|
||||
import org.slf4j.impl.MavenSlf4jSimpleFriend;
|
||||
import org.slf4j.simple.MavenSlf4jSimpleFriend;
|
||||
|
||||
/**
|
||||
* Configuration for slf4j-simple.
|
||||
|
@ -50,7 +49,6 @@ public class Slf4jSimpleConfiguration extends BaseSlf4jConfiguration {
|
|||
@Override
|
||||
public void activate() {
|
||||
// property for root logger level or System.out redirection need to be taken into account
|
||||
MavenSlf4jFriend.reset();
|
||||
MavenSlf4jSimpleFriend.init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.slf4j.simple;
|
||||
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -18,6 +18,6 @@
|
|||
# key = Slf4j effective logger factory implementation
|
||||
# value = corresponding o.a.m.cli.logging.Slf4jConfiguration class
|
||||
org.slf4j.impl.SimpleLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration
|
||||
org.slf4j.impl.MavenLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration
|
||||
org.apache.maven.slf4j.MavenLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration
|
||||
org.apache.logging.slf4j.Log4jLoggerFactory org.apache.maven.cli.logging.impl.Log4j2Configuration
|
||||
ch.qos.logback.classic.LoggerContext org.apache.maven.cli.logging.impl.LogbackConfiguration
|
||||
|
|
|
@ -66,8 +66,7 @@ under the License.
|
|||
<classifier>sources</classifier>
|
||||
<overWrite>false</overWrite>
|
||||
<outputDirectory>${project.build.directory}/generated-sources/slf4j-simple</outputDirectory>
|
||||
<includes>org/slf4j/impl/*.java</includes>
|
||||
<excludes>org/slf4j/impl/StaticLoggerBinder*</excludes>
|
||||
<includes>org/slf4j/simple/*.java</includes>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import org.apache.maven.logwrapper.LogLevelRecorder;
|
||||
import org.slf4j.event.Level;
|
|
@ -16,13 +16,14 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.maven.logwrapper.LogLevelRecorder;
|
||||
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.simple.SimpleLoggerFactory;
|
||||
|
||||
/**
|
||||
* LogFactory for Maven which can create a simple logger or one which, if set, fails the build on a severity threshold.
|
||||
|
@ -30,13 +31,15 @@ import org.slf4j.Logger;
|
|||
public class MavenLoggerFactory extends SimpleLoggerFactory implements MavenSlf4jWrapperFactory {
|
||||
private LogLevelRecorder logLevelRecorder = null;
|
||||
|
||||
public MavenLoggerFactory() {}
|
||||
|
||||
@Override
|
||||
public void setLogLevelRecorder(LogLevelRecorder logLevelRecorder) {
|
||||
if (this.logLevelRecorder != null) {
|
||||
throw new IllegalStateException("LogLevelRecorder has already been set.");
|
||||
}
|
||||
|
||||
this.logLevelRecorder = logLevelRecorder;
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,15 +47,7 @@ public class MavenLoggerFactory extends SimpleLoggerFactory implements MavenSlf4
|
|||
return Optional.ofNullable(logLevelRecorder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an appropriate {@link MavenSimpleLogger} instance by name.
|
||||
*/
|
||||
@Override
|
||||
public Logger getLogger(String name) {
|
||||
return loggerMap.computeIfAbsent(name, this::getNewLoggingInstance);
|
||||
}
|
||||
|
||||
private Logger getNewLoggingInstance(String name) {
|
||||
protected Logger createLogger(String name) {
|
||||
if (logLevelRecorder == null) {
|
||||
return new MavenSimpleLogger(name);
|
||||
} else {
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.IMarkerFactory;
|
||||
import org.slf4j.helpers.BasicMarkerFactory;
|
||||
import org.slf4j.helpers.NOPMDCAdapter;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.slf4j.spi.SLF4JServiceProvider;
|
||||
|
||||
public class MavenServiceProvider implements SLF4JServiceProvider {
|
||||
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||
* The value of this field is modified with each major release.
|
||||
*/
|
||||
// to avoid constant folding by the compiler, this field must *not* be final
|
||||
@SuppressWarnings({"checkstyle:StaticVariableName", "checkstyle:VisibilityModifier"})
|
||||
public static String REQUESTED_API_VERSION = "2.0.99"; // !final
|
||||
|
||||
private MavenLoggerFactory loggerFactory = new MavenLoggerFactory();
|
||||
private IMarkerFactory markerFactory = new BasicMarkerFactory();
|
||||
private MDCAdapter mdcAdapter = new NOPMDCAdapter();
|
||||
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
return loggerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMarkerFactory getMarkerFactory() {
|
||||
return markerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MDCAdapter getMDCAdapter() {
|
||||
return mdcAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestedApiVersion() {
|
||||
return REQUESTED_API_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
// already initialized
|
||||
}
|
||||
}
|
|
@ -16,11 +16,12 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.apache.maven.api.services.MessageBuilder;
|
||||
import org.slf4j.simple.SimpleLogger;
|
||||
|
||||
import static org.apache.maven.cli.jline.MessageUtils.builder;
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.spi.LoggerFactoryBinder;
|
||||
|
||||
/**
|
||||
* SLF4J LoggerFactoryBinder implementation using MavenSimpleLogger.
|
||||
* This class is part of the required classes used to specify an
|
||||
* SLF4J logger provider implementation.
|
||||
*
|
||||
* @since 3.5.1
|
||||
*/
|
||||
public final class StaticLoggerBinder implements LoggerFactoryBinder {
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled
|
||||
* against. The value of this field is usually modified with each release.
|
||||
*/
|
||||
// to avoid constant folding by the compiler, this field must *not* be final
|
||||
@SuppressWarnings({"checkstyle:staticvariablename", "checkstyle:visibilitymodifier"})
|
||||
public static String REQUESTED_API_VERSION = "1.7.25"; // !final
|
||||
|
||||
private static final String LOGGER_FACTORY_CLASS_STR = MavenLoggerFactory.class.getName();
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
|
||||
|
||||
/**
|
||||
* The ILoggerFactory instance returned by the {@link #getLoggerFactory}
|
||||
* method should always be the same object
|
||||
*/
|
||||
private final ILoggerFactory loggerFactory;
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation
|
||||
*/
|
||||
private StaticLoggerBinder() {
|
||||
loggerFactory = new MavenLoggerFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton of this class.
|
||||
*/
|
||||
public static StaticLoggerBinder getSingleton() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the factory.
|
||||
*/
|
||||
@Override
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
return loggerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name.
|
||||
*/
|
||||
@Override
|
||||
public String getLoggerFactoryClassStr() {
|
||||
return LOGGER_FACTORY_CLASS_STR;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.apache.maven.slf4j.MavenServiceProvider
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import org.apache.maven.logwrapper.LogLevelRecorder;
|
||||
import org.junit.jupiter.api.Test;
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.slf4j.impl;
|
||||
package org.apache.maven.slf4j;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
@ -44,7 +44,7 @@ class MavenSimpleLoggerTest {
|
|||
}
|
||||
|
||||
@AfterEach
|
||||
void taerdown() {
|
||||
void tearDown() {
|
||||
MessageUtils.setColorEnabled(colorEnabled);
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
|
@ -180,7 +180,7 @@ under the License.
|
|||
<resolverVersion>2.0.0-alpha-5</resolverVersion>
|
||||
<securityDispatcherVersion>2.0</securityDispatcherVersion>
|
||||
<sisuVersion>0.9.0.M2</sisuVersion>
|
||||
<slf4jVersion>1.7.36</slf4jVersion>
|
||||
<slf4jVersion>2.0.11</slf4jVersion>
|
||||
<stax2ApiVersion>4.2.1</stax2ApiVersion>
|
||||
<wagonVersion>3.5.3</wagonVersion>
|
||||
<woodstoxVersion>6.5.1</woodstoxVersion>
|
||||
|
|
Loading…
Reference in New Issue