Skip to content

Commit 47885d0

Browse files
committed
adding README
1 parent f27de40 commit 47885d0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
JDom Support for Common Maven Models
2+
====================================
3+
4+
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.
5+
6+
Currently, this project produces writers for the following models:
7+
8+
- pom.xml
9+
- settings.xml
10+
- toolchains.xml
11+
- maven-metadata.xml
12+
13+
Examples
14+
--------
15+
16+
To write changes to a Maven pom.xml, with formats/comments preserved:
17+
18+
File pom = new File( "pom.xml" );
19+
Writer writer = null;
20+
try
21+
{
22+
final SAXBuilder builder = new SAXBuilder();
23+
builder.setIgnoringBoundaryWhitespace( false );
24+
builder.setIgnoringElementContentWhitespace( false );
25+
26+
final Document doc = builder.build( pom );
27+
28+
String encoding = model.getModelEncoding();
29+
if ( encoding == null )
30+
{
31+
encoding = "UTF-8";
32+
}
33+
34+
final Format format = Format.getRawFormat().setEncoding( encoding ).setTextMode( TextMode.PRESERVE );
35+
36+
writer = WriterFactory.newWriter( pom, encoding );
37+
38+
new MavenJDOMWriter().write( model, doc, writer, format );
39+
}
40+
finally
41+
{
42+
IOUtil.close( writer );
43+
}
44+

0 commit comments

Comments
 (0)