gnodet commented on code in PR #1197:
URL: https://github.com/apache/maven/pull/1197#discussion_r1253418206
##########
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);
+ // transform
+ model = model.withRoot(false).withModules(null);
+ if (model.getParent() != null) {
+ model =
model.withParent(model.getParent().withRelativePath(null));
+ }
+ MavenStaxWriter w = new MavenStaxWriter();
+ w.write(output, model);
Review Comment:
Ouch, no, it has options (file comment, string formatter), which are not
used here.
--
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]