Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #95 from rnc/master
Browse files Browse the repository at this point in the history
For for #91 (newline output) and upgrade jdom-support (for #94)
  • Loading branch information
jdcasey committed Oct 21, 2013
2 parents bb8a219 + 5010621 commit 9501678
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/redhat/rcm/version/util/PomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.Text;
import org.jdom.filter.ContentFilter;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
Expand Down Expand Up @@ -150,7 +149,25 @@ public static File writeModifiedPom( final Model model, final File pom, final Pr
.add( "Writing modified POM: %s", out );

writer = WriterFactory.newWriter( out, encoding );
new XMLOutputter( format ).output( doc, writer );

final List<?> rootComments = doc.getContent ( new ContentFilter( ContentFilter.COMMENT ) );

XMLOutputter xmlo = new XMLOutputter ( format )
{
@Override
protected void printComment(Writer out, Comment comment)
throws IOException {
super.printComment (out, comment);

// If root level comments exist and is the current Comment object
// output an extra newline to tidy the output
if (rootComments.contains( comment) )
{
out.write(System.getProperty( "line.separator" ));
}
}
};
xmlo.output( doc, writer );

if ( relocatePom && !out.equals( pom ) )
{
Expand Down

0 comments on commit 9501678

Please sign in to comment.