How to rewrite POMs retaining the XML structure

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to rewrite POMs retaining the XML structure

Marc Rohlfs-2
Hi all,

is there a way to rewrite pom.xml files without loosing formatting,
ordering and comments?

We need to (programmatically) do several changes on Maven POMs, e.g. adding
and removing dependencies and properties. Currently we're using
the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
pom.xml files, but in the output files, all comments are removed, the XML
nodes are reordered and formatting (indentations, empty lines) is lost.
Does anybody know a way how to read and write POM files without loosing
formatting ordering and comments?

Best regards
Marc
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Chris Barlock
SInce it is XML, you could use the Java DOM or Sax parsers.

Chris




From:   Marc Rohlfs <[hidden email]>
To:     [hidden email]
Date:   11/29/2018 07:42 PM
Subject:        How to rewrite POMs retaining the XML structure



Hi all,

is there a way to rewrite pom.xml files without loosing formatting,
ordering and comments?

We need to (programmatically) do several changes on Maven POMs, e.g.
adding
and removing dependencies and properties. Currently we're using
the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
pom.xml files, but in the output files, all comments are removed, the XML
nodes are reordered and formatting (indentations, empty lines) is lost.
Does anybody know a way how to read and write POM files without loosing
formatting ordering and comments?

Best regards
Marc




Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Anton Tanasenko
In the past I've used decentxml as a lightweight reader/writer which
retains everything as-is.

https://bitbucket.org/digulla/decentxml/wiki/Home


пт, 30 нояб. 2018 г. в 02:47, Chris Barlock <[hidden email]>:

> SInce it is XML, you could use the Java DOM or Sax parsers.
>
> Chris
>
>
>
>
> From:   Marc Rohlfs <[hidden email]>
> To:     [hidden email]
> Date:   11/29/2018 07:42 PM
> Subject:        How to rewrite POMs retaining the XML structure
>
>
>
> Hi all,
>
> is there a way to rewrite pom.xml files without loosing formatting,
> ordering and comments?
>
> We need to (programmatically) do several changes on Maven POMs, e.g.
> adding
> and removing dependencies and properties. Currently we're using
> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> pom.xml files, but in the output files, all comments are removed, the XML
> nodes are reordered and formatting (indentations, empty lines) is lost.
> Does anybody know a way how to read and write POM files without loosing
> formatting ordering and comments?
>
> Best regards
> Marc
>
>
>
>
>

--
Regards,
Anton.
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Bernd Eckenfels
In reply to this post by Marc Rohlfs-2
The Release Plugin does rewrite branch/version and does an exceptionally bad job since you have to manually configure the indention. Would be good to have a common utility for that.

Gruss
Bernd
--
http://bernd.eckenfels.net

________________________________
Von: Marc Rohlfs <[hidden email]>
Gesendet: Freitag, November 30, 2018 1:42 AM
An: [hidden email]
Betreff: How to rewrite POMs retaining the XML structure

Hi all,

is there a way to rewrite pom.xml files without loosing formatting,
ordering and comments?

We need to (programmatically) do several changes on Maven POMs, e.g. adding
and removing dependencies and properties. Currently we're using
the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
pom.xml files, but in the output files, all comments are removed, the XML
nodes are reordered and formatting (indentations, empty lines) is lost.
Does anybody know a way how to read and write POM files without loosing
formatting ordering and comments?

Best regards
Marc
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Andrew Todd-2
The tidy-maven-plugin is fairly strict about formatting, and follows the
official Maven POM style guide. You could look at how they're doing it, or
run the plugin after you make your changes to reformat everything.

http://www.mojohaus.org/tidy-maven-plugin/


On Fri, Nov 30, 2018 at 10:39 AM Bernd Eckenfels <[hidden email]>
wrote:

> The Release Plugin does rewrite branch/version and does an exceptionally
> bad job since you have to manually configure the indention. Would be good
> to have a common utility for that.
>
> Gruss
> Bernd
> --
> http://bernd.eckenfels.net
>
> ________________________________
> Von: Marc Rohlfs <[hidden email]>
> Gesendet: Freitag, November 30, 2018 1:42 AM
> An: [hidden email]
> Betreff: How to rewrite POMs retaining the XML structure
>
> Hi all,
>
> is there a way to rewrite pom.xml files without loosing formatting,
> ordering and comments?
>
> We need to (programmatically) do several changes on Maven POMs, e.g. adding
> and removing dependencies and properties. Currently we're using
> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> pom.xml files, but in the output files, all comments are removed, the XML
> nodes are reordered and formatting (indentations, empty lines) is lost.
> Does anybody know a way how to read and write POM files without loosing
> formatting ordering and comments?
>
> Best regards
> Marc
>
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

rfscholte
In reply to this post by Marc Rohlfs-2
Have a look a flatten-maven-plugin[1], which was implemented to rewrite  
the pom file.

Robert

[1] https://www.mojohaus.org/flatten-maven-plugin/

On Thu, 29 Nov 2018 17:11:12 +0100, Marc Rohlfs  
<[hidden email]> wrote:

> Hi all,
>
> is there a way to rewrite pom.xml files without loosing formatting,
> ordering and comments?
>
> We need to (programmatically) do several changes on Maven POMs, e.g.  
> adding
> and removing dependencies and properties. Currently we're using
> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> pom.xml files, but in the output files, all comments are removed, the XML
> nodes are reordered and formatting (indentations, empty lines) is lost.
> Does anybody know a way how to read and write POM files without loosing
> formatting ordering and comments?
>
> Best regards
> Marc

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Oliver B. Fischer-2
In reply to this post by Marc Rohlfs-2
I do it with the release tools for jQAssitant with XSLT like this
https://github.com/buschmais/jqa-release-tool/blob/master/core/src/main/resources/xsl/update-version-property.xsl

The Versions plugin does it via Stax.

Best,

Oliver

Am 29.11.18 um 17:11 schrieb Marc Rohlfs:

> Hi all,
>
> is there a way to rewrite pom.xml files without loosing formatting,
> ordering and comments?
>
> We need to (programmatically) do several changes on Maven POMs, e.g. adding
> and removing dependencies and properties. Currently we're using
> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> pom.xml files, but in the output files, all comments are removed, the XML
> nodes are reordered and formatting (indentations, empty lines) is lost.
> Does anybody know a way how to read and write POM files without loosing
> formatting ordering and comments?
>
> Best regards
> Marc
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Matthieu BROUILLARD-3
@Marc Rohlfs : AFAIK if you do a modification in the POM (as project object
model) in memory (via a plugin probably) then the pom.xml file is already
behind you and comments are already lost during the loading phase of the
POM. Whatever the materialization of the POM you choose, comments will be
lost.


On Fri, Nov 30, 2018 at 9:57 AM Oliver B. Fischer <[hidden email]>
wrote:

> I do it with the release tools for jQAssitant with XSLT like this
>
> https://github.com/buschmais/jqa-release-tool/blob/master/core/src/main/resources/xsl/update-version-property.xsl
>
> The Versions plugin does it via Stax.
>
> Best,
>
> Oliver
>
> Am 29.11.18 um 17:11 schrieb Marc Rohlfs:
> > Hi all,
> >
> > is there a way to rewrite pom.xml files without loosing formatting,
> > ordering and comments?
> >
> > We need to (programmatically) do several changes on Maven POMs, e.g.
> adding
> > and removing dependencies and properties. Currently we're using
> > the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> > pom.xml files, but in the output files, all comments are removed, the XML
> > nodes are reordered and formatting (indentations, empty lines) is lost.
> > Does anybody know a way how to read and write POM files without loosing
> > formatting ordering and comments?
> >
> > Best regards
> > Marc
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Matthieu BROUILLARD-3
You say you do modification in the POM to add/remove dependencies &
properties.
Do you really need to modify the pom.xml of your project for that?
You could also do those additions using a plugin/extension and work on the
POM and just deploy a materialized pom.xml from the POM for publication
purposes without having to touch the original pom.xml file.

Matthieu

On Fri, Nov 30, 2018 at 12:13 PM Matthieu BROUILLARD <[hidden email]>
wrote:

> @Marc Rohlfs : AFAIK if you do a modification in the POM (as project
> object model) in memory (via a plugin probably) then the pom.xml file is
> already behind you and comments are already lost during the loading phase
> of the POM. Whatever the materialization of the POM you choose, comments
> will be lost.
>
>
> On Fri, Nov 30, 2018 at 9:57 AM Oliver B. Fischer <
> [hidden email]> wrote:
>
>> I do it with the release tools for jQAssitant with XSLT like this
>>
>> https://github.com/buschmais/jqa-release-tool/blob/master/core/src/main/resources/xsl/update-version-property.xsl
>>
>> The Versions plugin does it via Stax.
>>
>> Best,
>>
>> Oliver
>>
>> Am 29.11.18 um 17:11 schrieb Marc Rohlfs:
>> > Hi all,
>> >
>> > is there a way to rewrite pom.xml files without loosing formatting,
>> > ordering and comments?
>> >
>> > We need to (programmatically) do several changes on Maven POMs, e.g.
>> adding
>> > and removing dependencies and properties. Currently we're using
>> > the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
>> > pom.xml files, but in the output files, all comments are removed, the
>> XML
>> > nodes are reordered and formatting (indentations, empty lines) is lost.
>> > Does anybody know a way how to read and write POM files without loosing
>> > formatting ordering and comments?
>> >
>> > Best regards
>> > Marc
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

Marc Rohlfs-2
In reply to this post by Marc Rohlfs-2
Hi all,

many thanks for Your suggestions. I already check the different plugin
implementations (except tidy-maven-plugin) before writing my post - should
have probably mentioned them in my post, I'm sorry. Unfortunately none of
them really seems to help me with what I like/need to achieve, expect of
the JDom parser approach that was implemented by Robert Scholte for the
maven-release-plugin version 3.0 - which hasn't been continued nor
released for 2 1/2 years now.

@Robert: I'd really like to pick up Your approach. Looks very useful to me,
not only for the maven-release-plugin. If You don't mind, I'd invest a
little time to transfer it to a new library and extend it for my use cases.

@Anton: DecentXML is an interesting library, too. I'll surely remember this
one.

@Matthieu: Besides some other use cases, we basically need this for a
migration of a very huge/complex project setup into a new project layout.
For this, (re)calculate our projects (including dependencies, properties
etc) and we need to continuously transfer changes between old and new
project layout for a transition period.

Best regards
Marc


On Thu, 29 Nov 2018 at 17:11, Marc Rohlfs <[hidden email]> wrote:

> Hi all,
>
> is there a way to rewrite pom.xml files without loosing formatting,
> ordering and comments?
>
> We need to (programmatically) do several changes on Maven POMs, e.g.
> adding and removing dependencies and properties. Currently we're using
> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
> pom.xml files, but in the output files, all comments are removed, the XML
> nodes are reordered and formatting (indentations, empty lines) is lost.
> Does anybody know a way how to read and write POM files without loosing
> formatting ordering and comments?
>
> Best regards
> Marc
>
Reply | Threaded
Open this post in threaded view
|

Re: How to rewrite POMs retaining the XML structure

rfscholte
On Mon, 03 Dec 2018 11:47:58 +0100, Marc Rohlfs  
<[hidden email]> wrote:

> Hi all,
>
> many thanks for Your suggestions. I already check the different plugin
> implementations (except tidy-maven-plugin) before writing my post -  
> should
> have probably mentioned them in my post, I'm sorry. Unfortunately none of
> them really seems to help me with what I like/need to achieve, expect of
> the JDom parser approach that was implemented by Robert Scholte for the
> maven-release-plugin version 3.0 - which hasn't been continued nor
> released for 2 1/2 years now.
>
> @Robert: I'd really like to pick up Your approach. Looks very useful to  
> me,
> not only for the maven-release-plugin. If You don't mind, I'd invest a
> little time to transfer it to a new library and extend it for my use  
> cases.

That would be great. I guess I was working on it before I had to switch to  
JPMS/Project Jigsaw support.
Since then focus was on keeping all our ~100 subprojects running on more  
Java versions.
The maven-release-plugin is not dead. There are more things that should be  
improved for 3.0.0, but based on business value I need to focus on other  
topics. Will definitely work on it again in the future!

Robert

>
> @Anton: DecentXML is an interesting library, too. I'll surely remember  
> this
> one.
>
> @Matthieu: Besides some other use cases, we basically need this for a
> migration of a very huge/complex project setup into a new project layout.
> For this, (re)calculate our projects (including dependencies, properties
> etc) and we need to continuously transfer changes between old and new
> project layout for a transition period.
>
> Best regards
> Marc
>
>
> On Thu, 29 Nov 2018 at 17:11, Marc Rohlfs <[hidden email]>  
> wrote:
>
>> Hi all,
>>
>> is there a way to rewrite pom.xml files without loosing formatting,
>> ordering and comments?
>>
>> We need to (programmatically) do several changes on Maven POMs, e.g.
>> adding and removing dependencies and properties. Currently we're using
>> the MavenXpp3Reader and MavenXpp3Writer classes to read and write the
>> pom.xml files, but in the output files, all comments are removed, the  
>> XML
>> nodes are reordered and formatting (indentations, empty lines) is lost.
>> Does anybody know a way how to read and write POM files without loosing
>> formatting ordering and comments?
>>
>> Best regards
>> Marc

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]