use of org.jdom2.filter.ContentFilter in project pom-manipulation-ext by release-engineering.
the class PomIO method write.
private void write(final Project project, final File pom, final Model model) throws ManipulationException {
try {
final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation() : null;
MavenJDOMWriter mjw = new MavenJDOMWriter(model);
// We possibly could store the EOL type in the Project when we first read
// the file but we would then have to do a dual read, then write as opposed
// to a read, then read + write now.
LineSeparator ls = determineEOL(pom);
mjw.setLineSeparator(ls);
mjw.write(model, pom, new DocumentModifier() {
@Override
public void postProcess(final Document doc) {
// Only add the modified by to the top level pom.
if (project.isExecutionRoot()) {
final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT)).iterator();
while (it.hasNext()) {
final Comment c = (Comment) it.next();
if (c.toString().contains(MODIFIED_BY)) {
it.remove();
}
}
doc.addContent(Collections.<Content>singletonList(new Comment("\nModified by POM Manipulation Extension for Maven " + manifestInformation + "\n")));
}
}
});
} catch (final IOException e) {
throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
} catch (final JDOMException e) {
throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom, e.getMessage());
}
}
Aggregations