https://github.com/commonjava/maven-model-jdom-support
JDom Modello writers for models found in core Apache Maven distribution
https://github.com/commonjava/maven-model-jdom-support
Last synced: 11 months ago
JSON representation
JDom Modello writers for models found in core Apache Maven distribution
- Host: GitHub
- URL: https://github.com/commonjava/maven-model-jdom-support
- Owner: Commonjava
- Created: 2011-03-10T18:07:49.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2021-12-09T13:24:28.000Z (over 4 years ago)
- Last Synced: 2025-04-08T14:07:04.331Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 56.6 KB
- Stars: 5
- Watchers: 8
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JDom Support for Common Maven Models
====================================
This project simply extracts the Modello source files from the Apache Maven distribution source zip, and re-runs the Modello Maven plugin on them using the 'jdom-writer' goal. The point of this exercise is to provide a reusable artifact that contains the JDom ModelWriter classes for common models found in Maven. The advantage to the JDom writers is that they can preserve existing order of elements, formatting, and comments.
Currently, this project produces writers for the following models:
- pom.xml
- settings.xml
- toolchains.xml
- maven-metadata.xml
Example
--------
To write changes to a Maven pom.xml, with formats/comments preserved:
File pom = new File( "pom.xml" );
Writer writer = null;
try
{
final SAXBuilder builder = new SAXBuilder();
builder.setIgnoringBoundaryWhitespace( false );
builder.setIgnoringElementContentWhitespace( false );
final Document doc = builder.build( pom );
String encoding = model.getModelEncoding();
if ( encoding == null )
{
encoding = "UTF-8";
}
final Format format = Format.getRawFormat().setEncoding( encoding ).setTextMode( TextMode.PRESERVE );
writer = WriterFactory.newWriter( pom, encoding );
new MavenJDOMWriter().write( model, doc, writer, format );
}
finally
{
IOUtil.close( writer );
}
To use this code, you'll have to add the JDom dependency to your project's pom.xml:
org.jdom
jdom
1.1