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_r334255176
 
 

 ##########
 File path: 
maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
 ##########
 @@ -238,9 +268,82 @@ else if ( request.isUpdateSnapshots() )
         mavenRepositorySystem.injectProxy( session, 
request.getPluginArtifactRepositories() );
         mavenRepositorySystem.injectAuthentication( session, 
request.getPluginArtifactRepositories() );
 
+        if ( Boolean.getBoolean( "maven.experimental.buildconsumer" ) )
+        {
+            session.setFileTransformerManager( newFileTransformerManager() );
+        }
         return session;
     }
 
+    private FileTransformerManager newFileTransformerManager()
+    {
+        return new FileTransformerManager()
+        {
+            @Override
+            public Collection<FileTransformer> getTransformersForArtifact( 
final Artifact artifact )
+            {
+                Collection<FileTransformer> transformers = new ArrayList<>();
+                if ( "pom".equals( artifact.getExtension() ) )
+                {
+                    final TransformerFactory transformerFactory = 
Factories.newTransformerFactory();
+
+                    transformers.add( new FileTransformer()
+                    {
+                        @Override
+                        public InputStream transformData( File file )
+                            throws IOException, TransformException
+                        {
+                            final PipedOutputStream pipedOutputStream  = new 
PipedOutputStream();
+                            final PipedInputStream pipedInputStream  = new 
PipedInputStream( pipedOutputStream );
+                            
+                            final SAXSource transformSource;
+                            try
+                            {
+                                transformSource =
+                                    new SAXSource( 
consumerPomXMLFilterFactory.get().get( file.toPath() ),
+                                                   new InputSource( new 
FileReader( file ) ) );
+                            }
+                            catch ( SAXException | 
ParserConfigurationException | TransformerConfigurationException e )
+                            {   
+                                throw new TransformException( "Failed to 
create a consumerPomXMLFilter", e );
+                            }
+                            
+                            final StreamResult result = new StreamResult( 
pipedOutputStream );
+                            
+                            final Callable<Void> callable = () ->
+                            {
+                                try ( PipedOutputStream out = 
pipedOutputStream )
+                                {
+                                    
transformerFactory.newTransformer().transform( transformSource, result );
+                                }
+                                return null;
+                            };
+
+                            ExecutorService executorService = 
Executors.newSingleThreadExecutor();
 
 Review comment:
   Yes, please read 
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/io/PipedInputStream.html.
   I don't want to buffer the streams, that can consume too much memory. And it 
is quite easy to get the deadlock: fork, switch to this branch, change default 
value in Features to `true`  and run `mvn test`.

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

Reply via email to