protected void writePom( Model pom, File pomFile, String headerComment )
        throws MojoExecutionException
    {

        File parentFile = pomFile.getParentFile();
        if ( !parentFile.exists() )
        {
            boolean success = parentFile.mkdirs();
            if ( !success )
            {
                throw new MojoExecutionException( "Failed to create directory " + pomFile.getParent() );
            }
        }
        // MavenXpp3Writer could internally add the comment but does not expose such feature to API!
        // Instead we have to write POM XML to String and do post processing on that :(
        MavenXpp3Writer pomWriter = new MavenXpp3Writer();
        StringWriter stringWriter = new StringWriter( INITIAL_POM_WRITER_SIZE );
        try
        {
            pomWriter.write( stringWriter, pom );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "Internal I/O error!", e );
        }
        StringBuffer buffer = stringWriter.getBuffer();
        if ( !StringUtils.isEmpty( headerComment ) )
        {
            int projectStartIndex = buffer.indexOf( "<project" );
            if ( projectStartIndex >= 0 )
            {
                buffer.insert( projectStartIndex, "<!--" + headerComment + "-->\n" );
            }
            else
            {
                getLog().warn( "POM XML post-processing failed: no project tag found!" );
            }
        }
        writeStringToFile( buffer.toString(), pomFile, pom.getModelEncoding() );
    }
protected void writePom ( Model pom , File pomFile , String headerComment ) throws MojoExecutionException { File parentFile = pomFile . getParentFile ( ) ; if ( ! parentFile . exists ( ) ) { boolean success = parentFile . mkdirs ( ) ; if ( ! success ) { throw new MojoExecutionException ( "Failed to create directory " + pomFile . getParent ( ) ) ; } } MavenXpp3Writer pomWriter = new MavenXpp3Writer ( ) ; StringWriter stringWriter = new StringWriter ( INITIAL_POM_WRITER_SIZE ) ; try { pomWriter . write ( stringWriter , pom ) ; } catch ( IOException e ) { throw new MojoExecutionException ( "Internal I/O error!" , e ) ; } StringBuffer buffer = stringWriter . getBuffer ( ) ; if ( ! StringUtils . isEmpty ( headerComment ) ) { int projectStartIndex = buffer . indexOf ( "<project" ) ; if ( projectStartIndex >= 0 ) { buffer . insert ( projectStartIndex , "<!--" + headerComment + "-->\n" ) ; } else { getLog ( ) . warn ( "POM XML post-processing failed: no project tag found!" ) ; } } writeStringToFile ( buffer . toString ( ) , pomFile , pom . getModelEncoding ( ) ) ; }
Writes the given POM {@link Model} to the given {@link File}.

@param pom the {@link Model} of the POM to write.
@param pomFile the {@link File} where to write the given POM will be written to. {@link File#getParentFile()
Parent directories} are {@link File#mkdirs() created} automatically.
@param headerComment is the content of a potential XML comment at the top of the XML (after XML declaration and
before root tag). May be <code>null</code> if not present and to be omitted in target POM.
@throws MojoExecutionException if the operation failed (e.g. due to an {@link IOException}).