From 02eef1ac389fb2addd7f282d4bc55dce8edb2653 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 25 May 2009 21:21:10 +0000 Subject: [PATCH] o Added utility method git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@778514 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/DefaultMavenProjectBuilder.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 027ddba6b3..4345b08d70 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; @@ -393,7 +394,7 @@ public class DefaultMavenProjectBuilder private List build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration ) throws ProjectBuildingException, IOException { - Model mainModel = modelReader.read( pomFile, null ); + Model mainModel = readModel( projectId, pomFile, true ); mainModel.setProjectDirectory( pomFile.getParentFile() ); List domainModels = new ArrayList(); @@ -559,7 +560,7 @@ public class DefaultMavenProjectBuilder } private List getDomainModelParentsFromRepository( Model model, ArtifactRepository localRepository, List remoteRepositories ) - throws IOException + throws IOException, ProjectBuildingException { List models = new ArrayList(); @@ -599,7 +600,7 @@ public class DefaultMavenProjectBuilder throw (IOException) new IOException( "The parent POM " + artifactParent + " could not be retrieved from any repository" ).initCause( e ); } - Model parentModel = modelReader.read( artifactParent.getFile(), null ); + Model parentModel = readModel( parent.getId(), artifactParent.getFile(), true ); if ( !isMatchingParent( parentModel, parent ) ) { @@ -624,10 +625,11 @@ public class DefaultMavenProjectBuilder * @param projectDirectory * @return * @throws IOException + * @throws ProjectBuildingException */ private List getDomainModelParentsFromLocalPath( Model model, ArtifactRepository localRepository, List remoteRepositories, File projectDirectory, ProjectBuilderConfiguration projectBuilderConfiguration ) - throws IOException + throws IOException, ProjectBuildingException { List models = new ArrayList(); @@ -649,7 +651,7 @@ public class DefaultMavenProjectBuilder throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() ); } - Model parentModel = modelReader.read( parentFile, null ); + Model parentModel = readModel( parent.getId(), parentFile, true ); parentModel.setProjectDirectory( parentFile.getParentFile() ); if ( !isMatchingParent( parentModel, parent ) ) @@ -718,6 +720,22 @@ public class DefaultMavenProjectBuilder return true; } + private Model readModel( String projectId, File pomFile, boolean strict ) + throws ProjectBuildingException + { + Map options = + Collections. singletonMap( ModelReader.IS_STRICT, Boolean.valueOf( strict ) ); + try + { + return modelReader.read( pomFile, options ); + } + catch ( IOException e ) + { + throw new ProjectBuildingException( projectId, "Failed to read POM for " + projectId + " from " + pomFile + + ": " + e.getMessage(), pomFile, e ); + } + } + // Super Model Handling private static final String MAVEN_MODEL_VERSION = "4.0.0";