private void mergeTemplate ( String templateFilename , File folder , String javaFilename , boolean overwrite ) { final File javaFile = new File ( folder , javaFilename ) ; // create destination folder? File destinationFolder = javaFile . getParentFile ( ) ; if ( false == destinationFolder . exists ( ) ) { destinationFolder . mkdirs ( ) ; } // up-to-date? if ( false == javaFile . exists ( ) || overwrite ) { getLog ( ) . info ( "Merging " + templateFilename + " for " + javaFilename ) ; try { final PrintWriter writer = new PrintWriter ( javaFile ) ; Template template = Velocity . getTemplate ( templateFilename ) ; template . merge ( vc , writer ) ; writer . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( ResourceNotFoundException e ) { e . printStackTrace ( ) ; } catch ( ParseErrorException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } else { getLog ( ) . info ( "Skipping " + templateFilename + " for " + javaFilename ) ; } }
Merges a Velocity template for a specified file unless it already exists .