Example usage for org.jdom2.filter ContentFilter COMMENT

List of usage examples for org.jdom2.filter ContentFilter COMMENT

Introduction

In this page you can find the example usage for org.jdom2.filter ContentFilter COMMENT.

Prototype

int COMMENT

To view the source code for org.jdom2.filter ContentFilter COMMENT.

Click Source Link

Document

Mask for JDOM Comment objects

Usage

From source file:org.commonjava.maven.ext.io.PomIO.java

License:Apache License

private void write(final Project project, final File pom, final Model model) throws ManipulationException {
    try {//from w  w  w . j ava  2s .  c  om
        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());
    }
}