You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/05/03 19:24:21 UTC
[maven] branch MNG-6891 created (now d6b239c)
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a change to branch MNG-6891
in repository https://gitbox.apache.org/repos/asf/maven.git.
at d6b239c Also accept WARNING as value for --fos
This branch includes the following new commits:
new 9c9187a Improve user-friendliness of error message
new c25d02d Don't mention WARNING (yet)
new d6b239c Also accept WARNING as value for --fos
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven] 01/03: Improve user-friendliness of error message
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6891
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 9c9187ae7cd553b52ef1fb095fa397184813a8c6
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Wed Apr 15 13:55:08 2020 +0200
Improve user-friendliness of error message
---
.../java/org/apache/maven/logwrapper/LogLevelRecorder.java | 13 ++++++++++++-
.../org/apache/maven/logwrapper/LogLevelRecorderTest.java | 12 ++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
index 9fa4b51..4ab3d9b 100644
--- a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
+++ b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
@@ -31,7 +31,18 @@ public class LogLevelRecorder
public LogLevelRecorder( String threshold )
{
- Level level = Level.valueOf( threshold );
+ Level level;
+ try
+ {
+ level = Level.valueOf( threshold );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ String message = String.format(
+ "%s is not a valid log severity threshold. Valid severities are WARN, WARNING and ERROR.",
+ threshold );
+ throw new IllegalArgumentException( message );
+ }
if ( level.toInt() < Level.WARN.toInt() )
{
throw new IllegalArgumentException( "Logging severity thresholds can only be set to WARN or ERROR" );
diff --git a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
index 69b2853..4ee9fe6 100644
--- a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
+++ b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
@@ -22,7 +22,10 @@ package org.apache.maven.logwrapper;
import org.junit.Test;
import org.slf4j.event.Level;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
public class LogLevelRecorderTest
{
@@ -41,9 +44,14 @@ public class LogLevelRecorderTest
new LogLevelRecorder( "INFO" );
}
- @Test( expected = IllegalArgumentException.class )
+ @Test
public void failsOnUnknownLogLevel ()
{
- new LogLevelRecorder( "SEVERE" );
+ Throwable thrown = assertThrows( IllegalArgumentException.class, () -> new LogLevelRecorder( "SEVERE" ) );
+ String message = thrown.getMessage();
+ assertThat( message, containsString( "SEVERE is not a valid log severity threshold" ) );
+ assertThat( message, containsString( "WARN" ) );
+ assertThat( message, containsString( "WARNING" ) );
+ assertThat( message, containsString( "ERROR" ) );
}
}
\ No newline at end of file
[maven] 03/03: Also accept WARNING as value for --fos
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6891
in repository https://gitbox.apache.org/repos/asf/maven.git
commit d6b239c679f9cac02d38ca32fb4a316d4def5e42
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Wed Apr 15 20:02:33 2020 +0200
Also accept WARNING as value for --fos
---
.../apache/maven/logwrapper/LogLevelRecorder.java | 38 +++++++++++++++-------
.../maven/logwrapper/LogLevelRecorderTest.java | 10 ++++++
2 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
index 2160034..4cbf326 100644
--- a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
+++ b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
@@ -21,28 +21,29 @@ package org.apache.maven.logwrapper;
import org.slf4j.event.Level;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Responsible for keeping state of whether the threshold of the --fail-on-severity flag has been hit.
*/
public class LogLevelRecorder
{
+ private static final Map<String, Level> ACCEPTED_LEVELS = new HashMap<>();
+ static
+ {
+ ACCEPTED_LEVELS.put( "WARN", Level.WARN );
+ ACCEPTED_LEVELS.put( "WARNING", Level.WARN );
+ ACCEPTED_LEVELS.put( "ERROR", Level.ERROR );
+ }
+
private final Level logThreshold;
private boolean metThreshold = false;
public LogLevelRecorder( String threshold )
{
- Level level;
- try
- {
- level = Level.valueOf( threshold );
- }
- catch ( IllegalArgumentException iae )
- {
- String message = String.format(
- "%s is not a valid log severity threshold. Valid severities are WARN and ERROR.",
- threshold );
- throw new IllegalArgumentException( message );
- }
+ Level level = determineThresholdLevel( threshold );
+
if ( level.toInt() < Level.WARN.toInt() )
{
throw new IllegalArgumentException( "Logging severity thresholds can only be set to WARN or ERROR" );
@@ -51,6 +52,19 @@ public class LogLevelRecorder
logThreshold = level;
}
+ private Level determineThresholdLevel( String input )
+ {
+ final Level result = ACCEPTED_LEVELS.get( input );
+ if ( result == null )
+ {
+ String message = String.format(
+ "%s is not a valid log severity threshold. Valid severities are WARN/WARNING and ERROR.",
+ input );
+ throw new IllegalArgumentException( message );
+ }
+ return result;
+ }
+
public void record( Level logLevel )
{
if ( !metThreshold && logLevel.toInt() >= logThreshold.toInt() )
diff --git a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
index 8b0305c..2bdb867 100644
--- a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
+++ b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
@@ -45,12 +45,22 @@ public class LogLevelRecorderTest
}
@Test
+ public void createsLogLevelRecorderWithWarning()
+ {
+ LogLevelRecorder logLevelRecorder = new LogLevelRecorder( "WARNING" );
+ logLevelRecorder.record( Level.ERROR );
+
+ assertTrue( logLevelRecorder.metThreshold() );
+ }
+
+ @Test
public void failsOnUnknownLogLevel ()
{
Throwable thrown = assertThrows( IllegalArgumentException.class, () -> new LogLevelRecorder( "SEVERE" ) );
String message = thrown.getMessage();
assertThat( message, containsString( "SEVERE is not a valid log severity threshold" ) );
assertThat( message, containsString( "WARN" ) );
+ assertThat( message, containsString( "WARNING" ) );
assertThat( message, containsString( "ERROR" ) );
}
}
\ No newline at end of file
[maven] 02/03: Don't mention WARNING (yet)
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6891
in repository https://gitbox.apache.org/repos/asf/maven.git
commit c25d02da213767e13704a78a2a38dcb88946e82a
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Wed Apr 15 15:32:20 2020 +0200
Don't mention WARNING (yet)
---
.../src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java | 2 +-
.../src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
index 4ab3d9b..2160034 100644
--- a/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
+++ b/maven-slf4j-wrapper/src/main/java/org/apache/maven/logwrapper/LogLevelRecorder.java
@@ -39,7 +39,7 @@ public class LogLevelRecorder
catch ( IllegalArgumentException iae )
{
String message = String.format(
- "%s is not a valid log severity threshold. Valid severities are WARN, WARNING and ERROR.",
+ "%s is not a valid log severity threshold. Valid severities are WARN and ERROR.",
threshold );
throw new IllegalArgumentException( message );
}
diff --git a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
index 4ee9fe6..8b0305c 100644
--- a/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
+++ b/maven-slf4j-wrapper/src/test/java/org/apache/maven/logwrapper/LogLevelRecorderTest.java
@@ -51,7 +51,6 @@ public class LogLevelRecorderTest
String message = thrown.getMessage();
assertThat( message, containsString( "SEVERE is not a valid log severity threshold" ) );
assertThat( message, containsString( "WARN" ) );
- assertThat( message, containsString( "WARNING" ) );
assertThat( message, containsString( "ERROR" ) );
}
}
\ No newline at end of file