diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 9c151f789b..5cb78b287f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -300,17 +300,32 @@ public class DefaultModelBuilder Map options = Collections.singletonMap( ModelProcessor.IS_STRICT, Boolean.valueOf( strict ) ); - model = modelProcessor.read( modelSource.getInputStream(), options ); + try + { + model = modelProcessor.read( modelSource.getInputStream(), options ); + } + catch ( ModelParseException e ) + { + if ( !strict || pomFile != null ) + { + throw e; + } + + options = Collections.singletonMap( ModelProcessor.IS_STRICT, Boolean.FALSE ); + + model = modelProcessor.read( modelSource.getInputStream(), options ); + + problems.addWarning( "Malformed POM " + modelSource.getLocation() + ": " + e.getMessage(), e ); + } } catch ( ModelParseException e ) { - problems.addFatalError( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), - e.getLineNumber(), e.getColumnNumber(), e ); + problems.addFatalError( "Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage(), e ); throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() ); } catch ( IOException e ) { - problems.addFatalError( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(), -1, -1, e ); + problems.addFatalError( "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(), e ); throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() ); } @@ -552,7 +567,7 @@ public class DefaultModelBuilder catch ( UnresolvableModelException e ) { problems.addFatalError( "Non-resolvable parent POM " - + ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), -1, -1, e ); + + ModelProblemUtils.toId( groupId, artifactId, version ) + ": " + e.getMessage(), e ); throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() ); } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java index 7b417ba2ef..499e27a40e 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblemCollector.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.maven.model.Model; +import org.apache.maven.model.io.ModelParseException; /** * Collects problems that are encountered during model building. The primary purpose of this component is to account for @@ -106,8 +107,18 @@ class DefaultModelProblemCollector problems.addAll( problems ); } - public void addFatalError( String message, int line, int column, Exception cause ) + public void addFatalError( String message, Exception cause ) { + int line = -1; + int column = -1; + + if ( cause instanceof ModelParseException ) + { + ModelParseException e = (ModelParseException) cause; + line = e.getLineNumber(); + column = e.getColumnNumber(); + } + add( message, ModelProblem.Severity.FATAL, line, column, cause ); } @@ -118,7 +129,17 @@ class DefaultModelProblemCollector public void addError( String message, Exception cause ) { - add( message, ModelProblem.Severity.ERROR, -1, -1, cause ); + int line = -1; + int column = -1; + + if ( cause instanceof ModelParseException ) + { + ModelParseException e = (ModelParseException) cause; + line = e.getLineNumber(); + column = e.getColumnNumber(); + } + + add( message, ModelProblem.Severity.ERROR, line, column, cause ); } public void addWarning( String message ) @@ -128,7 +149,17 @@ class DefaultModelProblemCollector public void addWarning( String message, Exception cause ) { - add( message, ModelProblem.Severity.WARNING, -1, -1, cause ); + int line = -1; + int column = -1; + + if ( cause instanceof ModelParseException ) + { + ModelParseException e = (ModelParseException) cause; + line = e.getLineNumber(); + column = e.getColumnNumber(); + } + + add( message, ModelProblem.Severity.WARNING, line, column, cause ); } private void add( String message, ModelProblem.Severity severity, int line, int column, Exception cause )