protected final void merge ( final VelocityContext context , final String artifactName , final String templateName , final String filename ) throws GenerateException { final GeneratedFile genFile = getTargetFile ( artifactName , filename , templateName ) ; if ( genFile . isSkip ( ) ) { LOG . debug ( "Omitted already existing file: {} [{}]" , genFile , templateName ) ; } else { LOG . debug ( "Start merging velocity template: {} [{}]" , genFile , templateName ) ; // Merge content try { final Writer writer = new FileWriter ( genFile . getTmpFile ( ) ) ; try { final Template template = ve . getTemplate ( templateName ) ; template . merge ( context , writer ) ; } finally { writer . close ( ) ; } genFile . persist ( ) ; } catch ( final IOException ex ) { throw new GenerateException ( "Error merging template '" + templateName + "' to '" + filename + "'!" , ex ) ; } } }
Merges the template and context into a file . If the directory of the file does not exists the full directory path to it will be created .