gnodet commented on code in PR #1197:
URL: https://github.com/apache/maven/pull/1197#discussion_r1253417277


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -165,31 +178,50 @@ private ConsumerPomArtifact(MavenProject mavenProject, 
Path target, RepositorySy
                     target,
                     transformer(session));
         }
+    }
 
-        private static BiConsumer<Path, Path> 
transformer(RepositorySystemSession session) {
-            TransformerContext context = (TransformerContext) 
session.getData().get(TransformerContext.KEY);
-            return (src, dest) -> {
-                try (InputStream inputStream = transform(src, context)) {
-                    Files.createDirectories(dest.getParent());
-                    Files.copy(inputStream, dest, 
StandardCopyOption.REPLACE_EXISTING);
-                } catch (XMLStreamException | IOException e) {
-                    throw new RuntimeException(e);
-                }
-            };
-        }
+    BiConsumer<Path, Path> transformer(RepositorySystemSession session) {
+        TransformerContext context = (TransformerContext) 
session.getData().get(TransformerContext.KEY);
+        return (src, dest) -> {
+            try {
+                Files.createDirectories(dest.getParent());
+                transform(src, dest, context);
+            } catch (XMLStreamException | IOException e) {
+                throw new RuntimeException(e);
+            }
+        };
     }
 
     /**
      * The actual transformation: visible for testing.
      */
-    static InputStream transform(Path pomFile, TransformerContext context) 
throws IOException, XMLStreamException {
-        try (InputStream input = Files.newInputStream(pomFile)) {
-            XMLInputFactory2 factory = new 
com.ctc.wstx.stax.WstxInputFactory();
-            factory.configureForRoundTripping();
-            XMLStreamReader reader = factory.createXMLStreamReader(input);
-            reader = new RawToConsumerPomXMLFilterFactory(new 
DefaultBuildPomXMLFilterFactory(context, true))
-                    .get(reader, pomFile);
-            return XmlUtils.writeDocument(reader);
+    void transform(Path pomFile, Path destPomFile, TransformerContext context) 
throws IOException, XMLStreamException {
+        ModelParser parser = modelParsers.values().stream()
+                .filter(p -> pomFile.equals(p.locatePom(pomFile.getParent())))
+                .findAny()
+                .orElse(null);
+        if (parser != null) {
+            try (OutputStream output = Files.newOutputStream(destPomFile)) {
+                Model model = parser.parse(new FileSource(pomFile), null);

Review Comment:
   Yes, that's exactly why I prefer unchecked exceptions.
   The way to handle that, if `ModelParserException` would be a checked 
exception, is to add another exception type to the [catch 
clause](https://github.com/gnodet/maven/blob/MNG-7836-Support-alternative-syntaxes-for-POMs/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java#L189)
 so that it can be rethrown as a `RuntimeException`.   The catch/rethrow with a 
different checked exception is a very common pattern, which imho does not make 
sense.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to