Re: Writing poms from mojos
The shade plugin can also create a “dependency reduced” pom. Dan > On Sep 2, 2015, at 10:13 PM, Barrie Treloarwrote: > > There are ~3000 plugins in Maven Central ( > http://search.maven.org/#search|ga|1|p%3A%22maven-plugin%22). My eyes > glazed over after scanning through the first 100 to see if there are plugin > names to indicate if they might re-write poms. > > So I'll stick with the available plugins list ( > http://maven.apache.org/plugins/) and it looks like the only plugins that > modify the pom are: > * release > * versions > > I've also looked at m2eclipse (https://github.com/eclipse/m2e-core.git) to > see how it rewrites poms. m2eclipse can get away with working with the > Eclipse provided StructuredModels to grab a dom version of the editor and > just rewrite that one section, knowing that it doesn't need to rewrite the > whole file. > > The Maven plugins on the other hand need to stream in the file and preserve > all the kooky white space and commenting, as well as update just the > sections they want to modify. > > The release plugin uses org.jdom.Element to manipulate rewrites, and > org.jdom.output.XMLOutputter with a raw formatter to write the pom file out. > > The versions plugin uses StringBuilder as an in memory copy of the pom file > and the StAX2 api to manipulate rewrites, and an XmlStreamWriter to write > the pom file out. > > Have I missed any plugins? > > For such a small number of plugins that need to make rewrites it probably > not necessary to have this functionality offered in Maven directly... -- Daniel Kulp dk...@apache.org - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
Well as the initial author of tidy and versions it should be no surprise that I use the same tricks! I had been working on a verbatim XML pull parser implementation... Always ends up on the back burner. Basically my idea is to store the actual verbatim text in the XML event objects. That way if you get passed one from the reader you just output the raw input, if you get passed a programmatically created one then you create the output. There are two modes of an XML pull parser, the mode that passes INTs as event types and the mode that passes event objects. This trick can only work with the latter obviously. When writing both of those plugins I used the plan of my design as a seed for the architecture... I do note, however, that it's 6-7 years now that I have been trying and failing to write this pull parser. On Thursday, September 3, 2015, Barrie Treloarwrote: > tidy-maven-plugin (https://github.com/mojohaus/tidy-maven-plugin) works > similar to versions plugin. > > It uses a String copy of pom and for the non-trivial tidy tasks an > XMLEventReader from StAX api to manipulate rewrites, and > plexus.util.FileUtils.fileWrite to write the pom file out. > -- Sent from my phone
Re: Writing poms from mojos
Like I mentioned earlier, tycho-versions-plugin uses decentxml to manipulate pom.xml files. There is more or less complete version refactroing engine implementation there, but actual pom changes go through MutablePomFile [1]. The advantages of decentxml is that it has good and easy to use API and it provides "perfect" file-model-file roundtrip. [1] http://git.eclipse.org/c/tycho/org.eclipse.tycho.git/tree/tycho-release/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/pom/MutablePomFile.java -- Regards, Igor On Wed, Sep 2, 2015, at 10:13 PM, Barrie Treloar wrote: > There are ~3000 plugins in Maven Central ( > http://search.maven.org/#search|ga|1|p%3A%22maven-plugin%22). My eyes > glazed over after scanning through the first 100 to see if there are > plugin > names to indicate if they might re-write poms. > > So I'll stick with the available plugins list ( > http://maven.apache.org/plugins/) and it looks like the only plugins that > modify the pom are: > * release > * versions > > I've also looked at m2eclipse (https://github.com/eclipse/m2e-core.git) > to > see how it rewrites poms. m2eclipse can get away with working with the > Eclipse provided StructuredModels to grab a dom version of the editor and > just rewrite that one section, knowing that it doesn't need to rewrite > the > whole file. > > The Maven plugins on the other hand need to stream in the file and > preserve > all the kooky white space and commenting, as well as update just the > sections they want to modify. > > The release plugin uses org.jdom.Element to manipulate rewrites, and > org.jdom.output.XMLOutputter with a raw formatter to write the pom file > out. > > The versions plugin uses StringBuilder as an in memory copy of the pom > file > and the StAX2 api to manipulate rewrites, and an XmlStreamWriter to write > the pom file out. > > Have I missed any plugins? > > For such a small number of plugins that need to make rewrites it probably > not necessary to have this functionality offered in Maven directly... - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
On 3 September 2015 at 20:49, Igor Fedorenkowrote: > Like I mentioned earlier, tycho-versions-plugin > Thanks, and especially for the link into the source file. That save me effort. I saw Tycho earlier and read m2eclipse. oops.
Re: Writing poms from mojos
On 4 September 2015 at 02:49, Daniel Kulpwrote: > > The shade plugin can also create a “dependency reduced” pom. Thanks. The dependency reduced pom is completely regenerated by MavenJDOMWriter.updateModel and doesn't attempt to keep any of the original pom's formatting. It uses jdom to generate the xml.
Re: Writing poms from mojos
tidy-maven-plugin rewrites POMs. http://www.mojohaus.org/tidy-maven-plugin/ On Wed, Sep 2, 2015 at 10:13 PM, Barrie Treloarwrote: > There are ~3000 plugins in Maven Central ( > http://search.maven.org/#search|ga|1|p%3A%22maven-plugin%22). My eyes > glazed over after scanning through the first 100 to see if there are plugin > names to indicate if they might re-write poms. > > So I'll stick with the available plugins list ( > http://maven.apache.org/plugins/) and it looks like the only plugins that > modify the pom are: > * release > * versions > > I've also looked at m2eclipse (https://github.com/eclipse/m2e-core.git) to > see how it rewrites poms. m2eclipse can get away with working with the > Eclipse provided StructuredModels to grab a dom version of the editor and > just rewrite that one section, knowing that it doesn't need to rewrite the > whole file. > > The Maven plugins on the other hand need to stream in the file and preserve > all the kooky white space and commenting, as well as update just the > sections they want to modify. > > The release plugin uses org.jdom.Element to manipulate rewrites, and > org.jdom.output.XMLOutputter with a raw formatter to write the pom file out. > > The versions plugin uses StringBuilder as an in memory copy of the pom file > and the StAX2 api to manipulate rewrites, and an XmlStreamWriter to write > the pom file out. > > Have I missed any plugins? > > For such a small number of plugins that need to make rewrites it probably > not necessary to have this functionality offered in Maven directly... - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
There are ~3000 plugins in Maven Central ( http://search.maven.org/#search|ga|1|p%3A%22maven-plugin%22). My eyes glazed over after scanning through the first 100 to see if there are plugin names to indicate if they might re-write poms. So I'll stick with the available plugins list ( http://maven.apache.org/plugins/) and it looks like the only plugins that modify the pom are: * release * versions I've also looked at m2eclipse (https://github.com/eclipse/m2e-core.git) to see how it rewrites poms. m2eclipse can get away with working with the Eclipse provided StructuredModels to grab a dom version of the editor and just rewrite that one section, knowing that it doesn't need to rewrite the whole file. The Maven plugins on the other hand need to stream in the file and preserve all the kooky white space and commenting, as well as update just the sections they want to modify. The release plugin uses org.jdom.Element to manipulate rewrites, and org.jdom.output.XMLOutputter with a raw formatter to write the pom file out. The versions plugin uses StringBuilder as an in memory copy of the pom file and the StAX2 api to manipulate rewrites, and an XmlStreamWriter to write the pom file out. Have I missed any plugins? For such a small number of plugins that need to make rewrites it probably not necessary to have this functionality offered in Maven directly...
Re: Writing poms from mojos
tidy-maven-plugin (https://github.com/mojohaus/tidy-maven-plugin) works similar to versions plugin. It uses a String copy of pom and for the non-trivial tidy tasks an XMLEventReader from StAX api to manipulate rewrites, and plexus.util.FileUtils.fileWrite to write the pom file out.
Re: Writing poms from mojos
I've just looked at versions-maven-plugin, where a custom XMLEventReader (ModifiedPomXMLEventReader) is used to rebuild the pom file. A custom class is used because StAX API (JSR-173) are not good round-trip rewriting bwhile/b keeping all unchanged bytes in the file as is. For example, the StAX API specifies that codeCR/code characters will be stripped. Current implementations do not keep quot; and apos; characters consistent.
Re: Writing poms from mojos
+1 jvz On Aug 26, 2015, at 7:20 AM, Igor Fedorenko igor...@fastmail.com wrote: I used decentxml quite successfully for this purpose in Tycho and elsewhere. -- Regards, Igor On August 26, 2015 3:40:13 AM Barrie Treloar baerr...@gmail.com wrote: The release plugin has AbstractRewritePomsPhase which uses a lot of private methods to do its work. Is there a more utilitarian way of writing a pom? I really only need to fiddle with a couple of values in an existing pom (keeping whitespaces/formatting/etc) and re-write it. - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
Hello Barrie, I need something to introduce a parent element in our company pom. The idea is to make e.g. spring-boot the uppermost parent or to introduce needed dependencies and reconfigure mojos for this while keeping the rest in sync. I was thinking about writing a plugin for this as well. Regards Mirko -- Sent from my mobile Am 26.08.2015 13:50 schrieb Barrie Treloar baerr...@gmail.com: On 26 August 2015 at 20:41, Robert Scholte rfscho...@apache.org wrote: depending on what you want, maybe flattened-maven-plugin[1] can come to the rescue. I need the mojo I am hacking to rewrite the pom's to bend to my will. I'm probably a week away from having a working git magic plugin working.
Re: Writing poms from mojos
So, I'm sensing that rewriting the pom is a free-for-all and not something we do through a Maven API.
Re: Writing poms from mojos
I used decentxml quite successfully for this purpose in Tycho and elsewhere. -- Regards, Igor On August 26, 2015 3:40:13 AM Barrie Treloar baerr...@gmail.com wrote: The release plugin has AbstractRewritePomsPhase which uses a lot of private methods to do its work. Is there a more utilitarian way of writing a pom? I really only need to fiddle with a couple of values in an existing pom (keeping whitespaces/formatting/etc) and re-write it. - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Writing poms from mojos
The release plugin has AbstractRewritePomsPhase which uses a lot of private methods to do its work. Is there a more utilitarian way of writing a pom? I really only need to fiddle with a couple of values in an existing pom (keeping whitespaces/formatting/etc) and re-write it.
Re: Writing poms from mojos
depending on what you want, maybe flattened-maven-plugin[1] can come to the rescue. [1] http://www.mojohaus.org/flatten-maven-plugin/ Op Wed, 26 Aug 2015 13:07:14 +0200 schreef Barrie Treloar baerr...@gmail.com: On 26 August 2015 at 20:10, Robert Scholte rfscho...@apache.org wrote: I still have this wish to replace the JDom implementation with Woodstox, so all kinds of dirty tricks can be removed. I would gamble on that approach. I can't wait :) My itch is already burning so I'll live with the damned version now. I think I can repurpose the release plugins AbstractRewritePomsPhases :) But I've yet to attempt that hackery. - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
On 26 August 2015 at 20:41, Robert Scholte rfscho...@apache.org wrote: depending on what you want, maybe flattened-maven-plugin[1] can come to the rescue. I need the mojo I am hacking to rewrite the pom's to bend to my will. I'm probably a week away from having a working git magic plugin working.
Re: Writing poms from mojos
I still have this wish to replace the JDom implementation with Woodstox, so all kinds of dirty tricks can be removed. I would gamble on that approach. Robert Op Wed, 26 Aug 2015 09:40:09 +0200 schreef Barrie Treloar baerr...@gmail.com: The release plugin has AbstractRewritePomsPhase which uses a lot of private methods to do its work. Is there a more utilitarian way of writing a pom? I really only need to fiddle with a couple of values in an existing pom (keeping whitespaces/formatting/etc) and re-write it. - To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org
Re: Writing poms from mojos
On 26 August 2015 at 20:10, Robert Scholte rfscho...@apache.org wrote: I still have this wish to replace the JDom implementation with Woodstox, so all kinds of dirty tricks can be removed. I would gamble on that approach. I can't wait :) My itch is already burning so I'll live with the damned version now. I think I can repurpose the release plugins AbstractRewritePomsPhases :) But I've yet to attempt that hackery.