From ceb08cfa77cb552b8315b8ee60846d0584db9488 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sat, 30 Jan 2021 22:48:14 +0100 Subject: [PATCH] Test for empty locations and avoid printing them --- .../java/org/apache/maven/building/DefaultProblem.java | 8 +++++++- .../apache/maven/exception/DefaultExceptionHandler.java | 2 +- .../main/java/org/apache/maven/project/MavenProject.java | 9 ++------- .../apache/maven/project/ProjectBuildingException.java | 8 ++++++-- .../apache/maven/model/building/DefaultModelProblem.java | 7 ++++++- .../maven/model/building/ModelBuildingException.java | 8 ++++++-- .../maven/settings/building/DefaultSettingsProblem.java | 7 ++++++- .../settings/building/SettingsBuildingException.java | 8 ++++++-- 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java b/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java index c4bfe1e463..212eaa1725 100644 --- a/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java +++ b/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java @@ -153,7 +153,13 @@ class DefaultProblem buffer.append( '[' ).append( getSeverity() ).append( "] " ); buffer.append( getMessage() ); - buffer.append( " @ " ).append( getLocation() ); + String location = getLocation(); + if ( !location.isEmpty() ) + { + buffer.append( " @ " ); + buffer.append( location ); + } + return buffer.toString(); } diff --git a/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java b/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java index 4a5b281bad..30b73f4b95 100644 --- a/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java +++ b/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java @@ -163,7 +163,7 @@ public class DefaultExceptionHandler String location = ModelProblemUtils.formatLocation( problem, projectId ); - if ( StringUtils.isNotEmpty( location ) ) + if ( !location.isEmpty() ) { message += " @ " + location; } diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 958df1e563..57069a5e6a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -1154,16 +1154,11 @@ public class MavenProject sb.append( getArtifactId() ); sb.append( ':' ); sb.append( getVersion() ); - sb.append( " @ " ); - - try + if ( getFile() != null ) { + sb.append( " @ " ); sb.append( getFile().getPath() ); } - catch ( NullPointerException e ) - { - // don't log it. - } return sb.toString(); } diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java index 7786c90deb..3ace7a489a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingException.java @@ -135,8 +135,12 @@ public class ProjectBuildingException writer.print( problem.getSeverity() ); writer.print( "] " ); writer.print( problem.getMessage() ); - writer.print( " @ " ); - writer.println( ModelProblemUtils.formatLocation( problem, result.getProjectId() ) ); + String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() ); + if ( !location.isEmpty() ) + { + writer.print( " @ " ); + writer.println( location ); + } } } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java index e1b05aa0af..95c71c5719 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java @@ -168,7 +168,12 @@ public class DefaultModelProblem buffer.append( '[' ).append( getSeverity() ).append( "] " ); buffer.append( getMessage() ); - buffer.append( " @ " ).append( ModelProblemUtils.formatLocation( this, null ) ); + String location = ModelProblemUtils.formatLocation( this, null ); + if ( !location.isEmpty() ) + { + buffer.append( " @ " ); + buffer.append( location ); + } return buffer.toString(); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java index b5274382be..e9d18e456d 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java @@ -170,8 +170,12 @@ public class ModelBuildingException writer.print( problem.getSeverity() ); writer.print( "] " ); writer.print( problem.getMessage() ); - writer.print( " @ " ); - writer.println( ModelProblemUtils.formatLocation( problem, modelId ) ); + String location = ModelProblemUtils.formatLocation( problem, modelId ); + if ( !location.isEmpty() ) + { + writer.print( " @ " ); + writer.println( location ); + } } return buffer.toString(); diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsProblem.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsProblem.java index a8eb909b45..ac06109681 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsProblem.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsProblem.java @@ -158,7 +158,12 @@ public class DefaultSettingsProblem buffer.append( '[' ).append( getSeverity() ).append( "] " ); buffer.append( getMessage() ); - buffer.append( " @ " ).append( getLocation() ); + String location = getLocation(); + if ( !location.isEmpty() ) + { + buffer.append( " @ " ); + buffer.append( location ); + } return buffer.toString(); } diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/SettingsBuildingException.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/SettingsBuildingException.java index 0f2ade265d..530d522ed9 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/SettingsBuildingException.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/SettingsBuildingException.java @@ -80,8 +80,12 @@ public class SettingsBuildingException writer.print( problem.getSeverity() ); writer.print( "] " ); writer.print( problem.getMessage() ); - writer.print( " @ " ); - writer.println( problem.getLocation() ); + String location = problem.getLocation(); + if ( !location.isEmpty() ) + { + writer.print( " @ " ); + writer.println( location ); + } } return buffer.toString();