[MNG-4393] [regression] Parent POMs resolved from repository are parsed in strict mode

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@824842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-13 17:06:17 +00:00
parent eb16f89312
commit d74d8f4a4d
2 changed files with 54 additions and 8 deletions

View File

@ -300,17 +300,32 @@ public class DefaultModelBuilder
Map<String, ?> 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() );
}

View File

@ -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 )