diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java new file mode 100644 index 0000000000..b87688c40d --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java @@ -0,0 +1,29 @@ +package org.apache.maven.project.builder; + +import org.apache.maven.shared.model.DomainModelFactory; +import org.apache.maven.shared.model.DomainModel; +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.ModelMarshaller; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.util.List; +import java.io.IOException; +import java.io.StringReader; + +public class PomClassicDomainModelFactory implements DomainModelFactory +{ + public DomainModel createDomainModel(List modelProperties) throws IOException + { + String xml = null; + try + { + xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); + return new PomClassicDomainModel( new MavenXpp3Reader().read( new StringReader( xml ) ) ); + } + catch ( XmlPullParserException e ) + { + throw new IOException( e + ":\r\n" + xml ); + } + } +} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java index 9f48127ac3..a1ac7846f1 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java @@ -35,6 +35,13 @@ public final class PomClassicTransformer implements ModelTransformer { + private final DomainModelFactory factory; + + public PomClassicTransformer(DomainModelFactory factory) + { + this.factory = factory; + } + private static Map> cache = new HashMap>(); /** @@ -168,16 +175,7 @@ public final class PomClassicTransformer } } - String xml = null; - try - { - xml = ModelMarshaller.unmarshalModelPropertiesToXml( props, ProjectUri.baseUri ); - return new PomClassicDomainModel( new MavenXpp3Reader().read( new StringReader( xml ) ) ); - } - catch ( XmlPullParserException e ) - { - throw new IOException( e + ":\r\n" + xml ); - } + return factory.createDomainModel( props ); } /** diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index 3453ad3065..3b15674200 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -161,7 +161,7 @@ public final class DefaultProjectBuilder domainModels.add( new PomClassicDomainModel( model ) ); } - PomClassicTransformer transformer = new PomClassicTransformer( ); + PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory() ); ModelTransformerContext ctx = new ModelTransformerContext( Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );