rfscholte commented on a change in pull request #286: [MNG-6656] Introduce base
for build/consumer process
URL: https://github.com/apache/maven/pull/286#discussion_r330235426
##########
File path:
maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
##########
@@ -733,12 +758,81 @@ private void checkPluginVersions( List<ModelData>
lineage, ModelBuildingRequest
private void assembleInheritance( List<ModelData> lineage,
ModelBuildingRequest request,
ModelProblemCollector problems )
{
- for ( int i = lineage.size() - 2; i >= 0; i-- )
+ for ( int i = lineage.size() - 2; i >= 1; i-- )
{
Model parent = lineage.get( i + 1 ).getModel();
Model child = lineage.get( i ).getModel();
inheritanceAssembler.assembleModelInheritance( child, parent,
request, problems );
}
+
+ // re-read model from file
+ if ( Boolean.getBoolean( "maven.experimental.buildconsumer" ) &&
request.isTransformPom() )
+ {
+ try
+ {
+ // TODO: parent might be part of reactor... better read all
lineage items like this?
+ Model parent = lineage.get( 1 ).getModel();
+
+ Model child = modelProcessor.read( transformData( lineage.get(
0 ) ), null );
+ inheritanceAssembler.assembleModelInheritance( child, parent,
request, problems );
+
+ // sync pomfile, is transient
+ child.setPomFile( lineage.get( 0 ).getModel().getPomFile() );
+ // overwrite child
+ lineage.get( 0 ).setModel( child );
+ }
+ catch ( IOException | TransformException | SAXException |
ParserConfigurationException e )
+ {
+ // this is second read, should not happen
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ Model parent = lineage.get( 1 ).getModel();
+ Model child = lineage.get( 0 ).getModel();
+ inheritanceAssembler.assembleModelInheritance( child, parent,
request, problems );
+ }
+ }
+
+ private InputStream transformData( ModelData modelData )
+ throws IOException, TransformException, SAXException,
ParserConfigurationException
+ {
+ final TransformerFactory transformerFactory =
TransformerFactory.newInstance();
+
+ final PipedOutputStream pipedOutputStream = new PipedOutputStream();
+ final PipedInputStream pipedInputStream = new PipedInputStream(
pipedOutputStream );
+
+ // Should always be FileSource for reactor poms
+ FileSource source = (FileSource) modelData.getSource();
+
+ System.out.println( "transforming " + source.getFile() );
+
+ final SAXSource transformSource =
+ new SAXSource( buildPomXMLFilterFactory.get().get(
source.getFile().toPath() ),
+ new org.xml.sax.InputSource(
modelData.getSource().getInputStream() ) );
+
+ final StreamResult result = new StreamResult( pipedOutputStream );
+
+ final Runnable runnable = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try ( PipedOutputStream out = pipedOutputStream )
+ {
+ transformerFactory.newTransformer().transform(
transformSource, result );
+ }
+ catch ( TransformerException | IOException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+ };
+
+ new Thread( runnable ).start();
Review comment:
If you think it can be improved, go ahead. I just started with this PoC,
would be good if others could join and improve.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services