mirror of https://github.com/apache/maven.git
[MNG-6952] Fail early if pom cannot be transformed
This commit is contained in:
parent
65ec04c236
commit
2e66809e0e
|
@ -19,11 +19,12 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
@ -34,7 +35,6 @@
|
|||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.AbstractCoreMavenComponentTestCase;
|
||||
import org.apache.maven.artifact.InvalidArtifactRTException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.building.FileModelSource;
|
||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||
|
@ -235,9 +235,9 @@ public void testReadInvalidPom()
|
|||
{
|
||||
projectBuilder.build( pomFile, configuration );
|
||||
}
|
||||
catch ( InvalidArtifactRTException iarte )
|
||||
catch ( Exception ex )
|
||||
{
|
||||
assertThat( iarte.getMessage(), containsString( "The groupId cannot be empty." ) );
|
||||
assertThat( ex.getMessage(), containsString( "expected START_TAG or END_TAG not TEXT" ) );
|
||||
}
|
||||
|
||||
// multi projects build entry point
|
||||
|
@ -248,9 +248,9 @@ public void testReadInvalidPom()
|
|||
catch ( ProjectBuildingException ex )
|
||||
{
|
||||
assertEquals( 1, ex.getResults().size() );
|
||||
MavenProject project = ex.getResults().get( 0 ).getProject();
|
||||
assertNotNull( project );
|
||||
assertNotSame( 0, ex.getResults().get( 0 ).getProblems().size() );
|
||||
assertNotNull( ex.getResults().get( 0 ).getPomFile() );
|
||||
assertThat( ex.getResults().get( 0 ).getProblems().size(), greaterThan( 0 ) );
|
||||
assertThat( ex.getMessage(), containsString( "expected START_TAG or END_TAG not TEXT" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,9 @@
|
|||
import org.apache.maven.xml.Factories;
|
||||
import org.apache.maven.xml.sax.ext.CommentRenormalizer;
|
||||
import org.apache.maven.xml.sax.filter.AbstractSAXFilter;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Offers a transformation implementation based on PipelineStreams.
|
||||
|
@ -82,6 +84,31 @@ public final InputStream transform( Path pomFile, TransformerContext context )
|
|||
{
|
||||
filter = getSAXFilter( pomFile, context );
|
||||
filter.setLexicalHandler( transformerHandler );
|
||||
// By default errors are written to stderr.
|
||||
// Hence set custom errorHandler to reduce noice
|
||||
filter.setErrorHandler( new ErrorHandler()
|
||||
{
|
||||
@Override
|
||||
public void warning( SAXParseException exception )
|
||||
throws SAXException
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatalError( SAXParseException exception )
|
||||
throws SAXException
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error( SAXParseException exception )
|
||||
throws SAXException
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
} );
|
||||
}
|
||||
catch ( TransformerConfigurationException | SAXException | ParserConfigurationException e )
|
||||
{
|
||||
|
|
|
@ -680,7 +680,7 @@ else if ( modelSource instanceof FileModelSource )
|
|||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V37 ).setException( e ) );
|
||||
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V37 ).setException( e ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue