[MNG-6065] Create option --fail-on-severity

This commit is contained in:
Martin Kanters 2019-12-27 10:56:55 +01:00 committed by Robert Scholte
parent e3aa406cc7
commit d2510749d8
17 changed files with 586 additions and 43 deletions

View File

@ -0,0 +1,90 @@
package org.slf4j.impl;
/*
* 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.
*/
import org.apache.maven.logwrapper.LogLevelRecorder;
import org.junit.Test;
import org.slf4j.Logger;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class MavenLoggerFactoryTest
{
@Test
public void createsSimpleLogger()
{
MavenLoggerFactory mavenLoggerFactory = new MavenLoggerFactory();
Logger logger = mavenLoggerFactory.getLogger( "Test" );
assertThat( logger, instanceOf( MavenSimpleLogger.class ) );
}
@Test
public void loggerCachingWorks()
{
MavenLoggerFactory mavenLoggerFactory = new MavenLoggerFactory();
Logger logger = mavenLoggerFactory.getLogger( "Test" );
Logger logger2 = mavenLoggerFactory.getLogger( "Test" );
Logger differentLogger = mavenLoggerFactory.getLogger( "TestWithDifferentName" );
assertNotNull( logger );
assertNotNull( differentLogger );
assertSame( logger, logger2 );
assertNotSame( logger, differentLogger );
}
@Test
public void reportsWhenFailOnSeverityThresholdHasBeenHit()
{
MavenLoggerFactory mavenLoggerFactory = new MavenLoggerFactory();
mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "ERROR" ) );
assertTrue( mavenLoggerFactory.getLogLevelRecorder().isPresent() );
LogLevelRecorder logLevelRecorder = mavenLoggerFactory.getLogLevelRecorder().get();
MavenFailOnSeverityLogger logger = (MavenFailOnSeverityLogger) mavenLoggerFactory.getLogger( "Test" );
assertFalse( logLevelRecorder.metThreshold() );
logger.warn( "This should not hit the fail threshold" );
assertFalse( logLevelRecorder.metThreshold() );
logger.error( "This should hit the fail threshold" );
assertTrue( logLevelRecorder.metThreshold() );
logger.warn( "This should not reset the fail threshold" );
assertTrue( logLevelRecorder.metThreshold() );
}
@Test( expected = IllegalStateException.class )
public void failOnSeverityThresholdCanOnlyBeSetOnce()
{
MavenLoggerFactory mavenLoggerFactory = new MavenLoggerFactory();
mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "WARN" ) );
mavenLoggerFactory.setLogLevelRecorder( new LogLevelRecorder( "ERROR" ) );
}
}

View File

@ -74,6 +74,10 @@ under the License.
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-slf4j-wrapper</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
@ -104,10 +108,6 @@ under the License.
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -77,6 +77,8 @@ public class CLIManager
public static final String FAIL_FAST = "ff";
public static final String FAIL_ON_SEVERITY = "fos";
public static final String FAIL_AT_END = "fae";
public static final String FAIL_NEVER = "fn";
@ -128,6 +130,7 @@ public class CLIManager
options.addOption( Option.builder( ALTERNATE_GLOBAL_SETTINGS ).longOpt( "global-settings" ).desc( "Alternate path for the global settings file" ).hasArg().build() );
options.addOption( Option.builder( Character.toString( ALTERNATE_USER_TOOLCHAINS ) ).longOpt( "toolchains" ).desc( "Alternate path for the user toolchains file" ).hasArg().build() );
options.addOption( Option.builder( ALTERNATE_GLOBAL_TOOLCHAINS ).longOpt( "global-toolchains" ).desc( "Alternate path for the global toolchains file" ).hasArg().build() );
options.addOption( Option.builder( FAIL_ON_SEVERITY ).longOpt( "fail-on-severity" ).desc( "Configure which severity of logging should cause the build to fail" ).hasArgs().build() );
options.addOption( Option.builder( FAIL_FAST ).longOpt( "fail-fast" ).desc( "Stop at first failure in reactorized builds" ).build() );
options.addOption( Option.builder( FAIL_AT_END ).longOpt( "fail-at-end" ).desc( "Only fail the build afterwards; allow all non-impacted builds to continue" ).build() );
options.addOption( Option.builder( FAIL_NEVER ).longOpt( "fail-never" ).desc( "NEVER fail the build, regardless of project result" ).build() );

View File

@ -58,6 +58,8 @@ import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.extension.internal.CoreExports;
import org.apache.maven.extension.internal.CoreExtensionEntry;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.logwrapper.LogLevelRecorder;
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils;
@ -542,6 +544,24 @@ public class MavenCli
plexusLoggerManager = new Slf4jLoggerManager();
slf4jLogger = slf4jLoggerFactory.getLogger( this.getClass().getName() );
if ( cliRequest.commandLine.hasOption( CLIManager.FAIL_ON_SEVERITY ) )
{
String logLevelThreshold = cliRequest.commandLine.getOptionValue( CLIManager.FAIL_ON_SEVERITY );
if ( slf4jLoggerFactory instanceof MavenSlf4jWrapperFactory )
{
LogLevelRecorder logLevelRecorder = new LogLevelRecorder( logLevelThreshold );
( (MavenSlf4jWrapperFactory) slf4jLoggerFactory ).setLogLevelRecorder( logLevelRecorder );
slf4jLogger.info( "Enabled to break the build on log level {}.", logLevelThreshold );
}
else
{
slf4jLogger.warn( "Expected LoggerFactory to be of type '{}', but found '{}' instead. "
+ "The --fail-on-severity flag will not take effect.",
MavenSlf4jWrapperFactory.class.getName(), slf4jLoggerFactory.getClass().getName() );
}
}
}
private void version( CliRequest cliRequest )
@ -1343,6 +1363,8 @@ public class MavenCli
// this is the default behavior.
String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST;
slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
if ( commandLine.hasOption( CLIManager.NON_RECURSIVE ) )
{
recursive = false;

View File

@ -33,11 +33,14 @@ import org.apache.maven.execution.BuildSummary;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.logwrapper.LogLevelRecorder;
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,8 +49,7 @@ import org.slf4j.LoggerFactory;
*
* @author Benjamin Bentmann
*/
public class ExecutionEventLogger
extends AbstractExecutionListener
public class ExecutionEventLogger extends AbstractExecutionListener
{
private final Logger logger;
@ -133,6 +135,20 @@ public class ExecutionEventLogger
logReactorSummary( event.getSession() );
}
ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
if ( iLoggerFactory instanceof MavenSlf4jWrapperFactory )
{
MavenSlf4jWrapperFactory loggerFactory = (MavenSlf4jWrapperFactory) iLoggerFactory;
loggerFactory.getLogLevelRecorder()
.filter( LogLevelRecorder::metThreshold )
.ifPresent( recorder ->
event.getSession().getResult().addException( new Exception(
"Build failed due to log statements with a higher severity than allowed. "
+ "Fix the logged issues or remove flag --fail-on-severity (-fos)." ) )
);
}
logResult( event.getSession() );
logStats( event.getSession() );
@ -306,8 +322,8 @@ public class ExecutionEventLogger
String prefix = chars( '-', Math.max( 0, ( LINE_LENGTH - headerLen ) / 2 ) ) + preHeader;
String suffix = postHeader
+ chars( '-', Math.max( 0, LINE_LENGTH - headerLen - prefix.length() + preHeader.length() ) );
String suffix = postHeader + chars( '-',
Math.max( 0, LINE_LENGTH - headerLen - prefix.length() + preHeader.length() ) );
logger.info( buffer().strong( prefix ).project( projectKey ).strong( suffix ).toString() );

View File

@ -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.MavenSimpleLoggerFactory org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration
org.slf4j.impl.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

View File

@ -45,6 +45,10 @@ under the License.
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-slf4j-wrapper</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,142 @@
package org.slf4j.impl;
/*
* 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.
*/
import org.apache.maven.logwrapper.LogLevelRecorder;
import org.slf4j.event.Level;
/**
* A proxy which enhances the MavenSimpleLogger with functionality to track whether a logging threshold is hit.
* Currently only support WARN and ERROR states, since it's been used for the --fail-on-severity flag.
*/
public class MavenFailOnSeverityLogger extends MavenSimpleLogger
{
private final LogLevelRecorder logLevelRecorder;
MavenFailOnSeverityLogger( String name, LogLevelRecorder logLevelRecorder )
{
super( name );
this.logLevelRecorder = logLevelRecorder;
}
/**
* A simple implementation which always logs messages of level WARN
* according to the format outlined above.
*/
@Override
public void warn( String msg )
{
super.warn( msg );
logLevelRecorder.record( Level.WARN );
}
/**
* Perform single parameter substitution before logging the message of level
* WARN according to the format outlined above.
*/
@Override
public void warn( String format, Object arg )
{
super.warn( format, arg );
logLevelRecorder.record( Level.WARN );
}
/**
* Perform double parameter substitution before logging the message of level
* WARN according to the format outlined above.
*/
@Override
public void warn( String format, Object arg1, Object arg2 )
{
super.warn( format, arg1, arg2 );
logLevelRecorder.record( Level.WARN );
}
/**
* Perform double parameter substitution before logging the message of level
* WARN according to the format outlined above.
*/
@Override
public void warn( String format, Object... argArray )
{
super.warn( format, argArray );
logLevelRecorder.record( Level.WARN );
}
/** Log a message of level WARN, including an exception. */
@Override
public void warn( String msg, Throwable t )
{
super.warn( msg, t );
logLevelRecorder.record( Level.WARN );
}
/**
* A simple implementation which always logs messages of level ERROR
* according to the format outlined above.
*/
@Override
public void error( String msg )
{
super.error( msg );
logLevelRecorder.record( Level.ERROR );
}
/**
* Perform single parameter substitution before logging the message of level
* ERROR according to the format outlined above.
*/
@Override
public void error( String format, Object arg )
{
super.error( format, arg );
logLevelRecorder.record( Level.ERROR );
}
/**
* Perform double parameter substitution before logging the message of level
* ERROR according to the format outlined above.
*/
@Override
public void error( String format, Object arg1, Object arg2 )
{
super.error( format, arg1, arg2 );
logLevelRecorder.record( Level.ERROR );
}
/**
* Perform double parameter substitution before logging the message of level
* ERROR according to the format outlined above.
*/
@Override
public void error( String format, Object... argArray )
{
super.error( format, argArray );
logLevelRecorder.record( Level.ERROR );
}
/** Log a message of level ERROR, including an exception. */
@Override
public void error( String msg, Throwable t )
{
super.error( msg, t );
logLevelRecorder.record( Level.ERROR );
}
}

View File

@ -0,0 +1,82 @@
package org.slf4j.impl;
/*
* 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.
*/
import org.apache.maven.logwrapper.LogLevelRecorder;
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
import org.slf4j.Logger;
import java.util.Optional;
/**
* LogFactory for Maven which can create a simple logger or one which, if set, fails the build on a severity threshold.
*/
public class MavenLoggerFactory extends SimpleLoggerFactory implements MavenSlf4jWrapperFactory
{
private LogLevelRecorder logLevelRecorder = null;
@Override
public void setLogLevelRecorder( LogLevelRecorder logLevelRecorder )
{
if ( this.logLevelRecorder != null )
{
throw new IllegalStateException( "LogLevelRecorder has already been set." );
}
this.logLevelRecorder = logLevelRecorder;
}
@Override
public Optional<LogLevelRecorder> getLogLevelRecorder()
{
return Optional.ofNullable( logLevelRecorder );
}
/**
* Return an appropriate {@link MavenSimpleLogger} instance by name.
*/
@Override
public Logger getLogger( String name )
{
Logger simpleLogger = loggerMap.get( name );
if ( simpleLogger != null )
{
return simpleLogger;
}
else
{
Logger newInstance = getNewLoggingInstance( name );
Logger oldInstance = loggerMap.putIfAbsent( name, newInstance );
return oldInstance == null ? newInstance : oldInstance;
}
}
private Logger getNewLoggingInstance( String name )
{
if ( logLevelRecorder == null )
{
return new MavenSimpleLogger( name );
}
else
{
return new MavenFailOnSeverityLogger( name, logLevelRecorder );
}
}
}

View File

@ -19,18 +19,18 @@ package org.slf4j.impl;
* under the License.
*/
import static org.apache.maven.shared.utils.logging.MessageUtils.level;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
import java.io.PrintStream;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
import static org.apache.maven.shared.utils.logging.MessageUtils.level;
/**
* Logger for Maven, that support colorization of levels and stacktraces.
* This class implements 2 methods introduced in slf4j-simple provider local copy.
* Logger for Maven, that support colorization of levels and stacktraces. This class implements 2 methods introduced in
* slf4j-simple provider local copy.
*
* @since 3.5.0
*/
public class MavenSimpleLogger
extends SimpleLogger
public class MavenSimpleLogger extends SimpleLogger
{
MavenSimpleLogger( String name )
{

View File

@ -40,7 +40,7 @@ public final class StaticLoggerBinder
@SuppressWarnings( { "checkstyle:staticvariablename", "checkstyle:visibilitymodifier" } )
public static String REQUESTED_API_VERSION = "1.7.25"; // !final
private static final String LOGGER_FACTORY_CLASS_STR = MavenSimpleLoggerFactory.class.getName();
private static final String LOGGER_FACTORY_CLASS_STR = MavenLoggerFactory.class.getName();
/**
* The unique instance of this class.
@ -58,7 +58,7 @@ public final class StaticLoggerBinder
*/
private StaticLoggerBinder()
{
loggerFactory = new MavenSimpleLoggerFactory();
loggerFactory = new MavenLoggerFactory();
}
/**

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.7.0-SNAPSHOT</version>
</parent>
<artifactId>maven-slf4j-wrapper</artifactId>
<name>Maven SLF4J Wrapper</name>
<description>
This modules provides an ILoggerFactory interface which avoids a cyclic dependency between maven-embedder and maven-slf4j-provider.
</description>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,55 @@
package org.apache.maven.logwrapper;
/*
* 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.
*/
import org.slf4j.event.Level;
/**
* Responsible for keeping state of whether the threshold of the --fail-on-severity flag has been hit.
*/
public class LogLevelRecorder
{
private final Level logThreshold;
private boolean metThreshold = false;
public LogLevelRecorder( String threshold )
{
Level level = Level.valueOf( threshold );
if ( level.toInt() < Level.WARN.toInt() )
{
throw new IllegalArgumentException( "Logging severity thresholds can only be set to WARN or ERROR" );
}
logThreshold = level;
}
public void record( Level logLevel )
{
if ( !metThreshold && logLevel.toInt() >= logThreshold.toInt() )
{
metThreshold = true;
}
}
public boolean metThreshold()
{
return metThreshold;
}
}

View File

@ -1,4 +1,4 @@
package org.slf4j.impl;
package org.apache.maven.logwrapper;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,29 +19,15 @@ package org.slf4j.impl;
* under the License.
*/
import org.slf4j.Logger;
import org.slf4j.ILoggerFactory;
import java.util.Optional;
/**
* MavenSimpleLoggerFactory
* Wrapper for creating loggers which can have a log level threshold.
*/
public class MavenSimpleLoggerFactory
extends SimpleLoggerFactory
public interface MavenSlf4jWrapperFactory extends ILoggerFactory
{
/**
* Return an appropriate {@link MavenSimpleLogger} instance by name.
*/
public Logger getLogger( String name )
{
Logger simpleLogger = loggerMap.get( name );
if ( simpleLogger != null )
{
return simpleLogger;
}
else
{
Logger newInstance = new MavenSimpleLogger( name );
Logger oldInstance = loggerMap.putIfAbsent( name, newInstance );
return oldInstance == null ? newInstance : oldInstance;
}
}
void setLogLevelRecorder( LogLevelRecorder logLevelRecorder );
Optional<LogLevelRecorder> getLogLevelRecorder();
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
<edit>${project.scm.url}</edit>
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<item name="JavaDocs" href="apidocs/index.html"/>
<item name="Source Xref" href="xref/index.html"/>
<!--item name="FAQ" href="faq.html"/-->
</menu>
<menu ref="parent"/>
<menu ref="reports"/>
</body>
</project>

View File

@ -0,0 +1,49 @@
package org.apache.maven.logwrapper;
/*
* 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.
*/
import org.junit.Test;
import org.slf4j.event.Level;
import static org.junit.Assert.assertTrue;
public class LogLevelRecorderTest
{
@Test
public void createsLogLevelRecorder()
{
LogLevelRecorder logLevelRecorder = new LogLevelRecorder( "WARN" );
logLevelRecorder.record( Level.ERROR );
assertTrue( logLevelRecorder.metThreshold() );
}
@Test( expected = IllegalArgumentException.class )
public void failsOnLowerThanWarn ()
{
new LogLevelRecorder( "INFO" );
}
@Test( expected = IllegalArgumentException.class )
public void failsOnUnknownLogLevel ()
{
new LogLevelRecorder( "SEVERE" );
}
}

14
pom.xml
View File

@ -92,6 +92,7 @@ under the License.
<module>maven-resolver-provider</module>
<module>maven-repository-metadata</module>
<module>maven-slf4j-provider</module>
<module>maven-slf4j-wrapper</module>
<module>maven-embedder</module>
<module>maven-compat</module>
<module>apache-maven</module>
@ -157,7 +158,13 @@ under the License.
<name>Mike Mol (MNG-6665)</name>
</contributor>
<contributor>
<name>Martin Kanters (MNG-6665)</name>
<name>Martin Kanters (MNG-6665, MNG-6065)</name>
</contributor>
<contributor>
<name>Luc Klaassen (MNG-6065)</name>
</contributor>
<contributor>
<name>Wouter Aarts (MNG-6065)</name>
</contributor>
</contributors>
@ -232,6 +239,11 @@ under the License.
<artifactId>maven-slf4j-provider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-slf4j-wrapper</artifactId>
<version>${project.version}</version>
</dependency>
<!--bootstrap-end-comment-->
<!-- Plexus -->
<dependency>