You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Julien HENRY <he...@yahoo.fr> on 2011/04/13 13:56:22 UTC
Maven API to partially edit pom.xml
Hi,
I would like to know if there is a standard Maven API to edit parts of a
pom.xml. I managed to parse a pom to a Model using ModelBuilder. Then I can do
some modifications and write Model to file using ModelWriter. But of course it
will completly rewrite the pom (loosing comments, writing unwanted tags like
default values, ...).
I looked at how versions-maven-plugin works and it seems it uses its own parser
(based on StAX) and then proceed with XPath to edit specific parts of the pom.
Is it still the recommended way? Is there a better solution with Maven 3 API?
Basically what I want is something like:
Model model = new Model("path/to/pom.xml");
model.setGroupId("foo");
model.write(); // Only groupId is changed in pom.xml
Thanks
Julien
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Maven API to partially edit pom.xml
Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi,
> Is it still the recommended way? Is there a better solution with Maven 3
> API?
I don't know a better one....I'm searching for a better solution as well, but i didn't one...
Kind regards
Karl Heinz Marbaise
--
MfG
Karl Heinz Marbaise
--
SoftwareEntwicklung Beratung Schulung Tel.: +49 (0) 2405 / 415 893
Dipl.Ing.(FH) Karl Heinz Marbaise ICQ#: 135949029
Hauptstrasse 177 USt.IdNr: DE191347579
52146 Würselen http://www.soebes.de
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Maven API to partially edit pom.xml
Posted by Brett Porter <br...@apache.org>.
We've got some techniques to do this in the release plugin as well.
It may be a good thing to build a solid API (either in Maven proper, or a shared module) either with this, the code from the release plugin, the versions plugin, or a combination of them all and then bring them all into line...
On 14/04/2011, at 12:00 AM, Jesse Glick wrote:
> On 04/13/2011 07:56 AM, Julien HENRY wrote:
>> I would like to know if there is a standard Maven API to edit parts of a
>> pom.xml. I managed to parse a pom to a Model using ModelBuilder. Then I can do
>> some modifications and write Model to file using ModelWriter. But of course it
>> will completly rewrite the pom (loosing comments, writing unwanted tags like
>> default values, ...).
>
> The main challenge is finding a library for high-fidelity XML round-trip structure editing, i.e. that preserves all details of whitespace and formatting for unmodified nodes. NetBeans has such a system (XAM/XDM) but the dependency tree is too deep for use in a Maven plugin. http://code.google.com/p/decentxml/ is the only such small library I can find. It has its own model rather than Document, DOMImplementationLS, etc., so your code would be tightly tied to that API. It does not appear to be published on Central and I am unsure how reliable it is, but it has a Maven POM utility already, and it seems to work as advertised in my testing - replacing a few element attribute values on some largish hand-edited XML files produced a minimal diff.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
--
Brett Porter
brett@apache.org
http://brettporter.wordpress.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Maven API to partially edit pom.xml
Posted by Julien HENRY <he...@yahoo.fr>.
Thanks Jesse for the pointer. Actually it is on central:
http://repo2.maven.org/maven2/de/pdark/decentxml/1.3/
Regards,
Julien
----- Message d'origine ----
> De : Jesse Glick <je...@oracle.com>
> À : dev@maven.apache.org
> Envoyé le : Mer 13 avril 2011, 16h 00min 21s
> Objet : Re: Maven API to partially edit pom.xml
>
> On 04/13/2011 07:56 AM, Julien HENRY wrote:
> > I would like to know if there is a standard Maven API to edit parts of a
> > pom.xml. I managed to parse a pom to a Model using ModelBuilder. Then I can
>do
> > some modifications and write Model to file using ModelWriter. But of course
>it
> > will completly rewrite the pom (loosing comments, writing unwanted tags
like
> > default values, ...).
>
> The main challenge is finding a library for high-fidelity XML round-trip
>structure editing, i.e. that preserves all details of whitespace and formatting
>for unmodified nodes. NetBeans has such a system (XAM/XDM) but the dependency
>tree is too deep for use in a Maven plugin. http://code.google.com/p/decentxml/
>is the only such small library I can find. It has its own model rather than
>Document, DOMImplementationLS, etc., so your code would be tightly tied to that
>API. It does not appear to be published on Central and I am unsure how reliable
>it is, but it has a Maven POM utility already, and it seems to work as
>advertised in my testing - replacing a few element attribute values on some
>largish hand-edited XML files produced a minimal diff.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Maven API to partially edit pom.xml
Posted by Jesse Glick <je...@oracle.com>.
On 04/13/2011 07:56 AM, Julien HENRY wrote:
> I would like to know if there is a standard Maven API to edit parts of a
> pom.xml. I managed to parse a pom to a Model using ModelBuilder. Then I can do
> some modifications and write Model to file using ModelWriter. But of course it
> will completly rewrite the pom (loosing comments, writing unwanted tags like
> default values, ...).
The main challenge is finding a library for high-fidelity XML round-trip structure editing, i.e. that preserves all details of whitespace and formatting for unmodified
nodes. NetBeans has such a system (XAM/XDM) but the dependency tree is too deep for use in a Maven plugin. http://code.google.com/p/decentxml/ is the only such small
library I can find. It has its own model rather than Document, DOMImplementationLS, etc., so your code would be tightly tied to that API. It does not appear to be
published on Central and I am unsure how reliable it is, but it has a Maven POM utility already, and it seems to work as advertised in my testing - replacing a few
element attribute values on some largish hand-edited XML files produced a minimal diff.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org