public static void writeFile(Log log, GeneratorModel<?, ?> model, String targetDir) throws MojoExecutionException {
        if(model.generateClazzWithTemplates() == null || model.generateClazzWithTemplates().size() < 1) {
            return;
        }
        for(Map.Entry<String, String> templateEntry : model.generateClazzWithTemplates().entrySet()) {
            Template template;
            try {
                template = Velocity.getTemplate(templateEntry.getValue(), "UTF-8");
            } catch(Exception e) {
                log.error("Failed to retrieve Template " + templateEntry.getValue(), e);
                throw new MojoExecutionException("Failed to retrieve Template " + templateEntry.getValue(), e);
            }
            try {
                File pckDir = new File(targetDir + model.getTargetFolder());
                if(!pckDir.exists()) {
                    pckDir.mkdirs();
                }
                try(OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(pckDir.getAbsolutePath() + File.separator + templateEntry.getKey() + ".java"), "UTF-8")) {
                    log.info("Creating file " + pckDir.getAbsolutePath() + File.separator + templateEntry.getKey() + ".java");
                    VelocityContext context = new VelocityContext();
                    context.put("model", model);
                    context.put("tool", new ModelTools());
                    context.put("clazzName", templateEntry.getKey());
                    template.merge(context, fw);
                }
            } catch(IOException e) {
                log.error("Failed to write the generated file " + templateEntry.getKey(), e);
                throw new MojoExecutionException("Failed to write the generated file " + templateEntry.getKey(), e);
            }
        }
    }
public static void writeFile ( Log log , GeneratorModel < ? , ? > model , String targetDir ) throws MojoExecutionException { if ( model . generateClazzWithTemplates ( ) == null || model . generateClazzWithTemplates ( ) . size ( ) < 1 ) { return ; } for ( Map . Entry < String , String > templateEntry : model . generateClazzWithTemplates ( ) . entrySet ( ) ) { Template template ; try { template = Velocity . getTemplate ( templateEntry . getValue ( ) , "UTF-8" ) ; } catch ( Exception e ) { log . error ( "Failed to retrieve Template " + templateEntry . getValue ( ) , e ) ; throw new MojoExecutionException ( "Failed to retrieve Template " + templateEntry . getValue ( ) , e ) ; } try { File pckDir = new File ( targetDir + model . getTargetFolder ( ) ) ; if ( ! pckDir . exists ( ) ) { pckDir . mkdirs ( ) ; } try ( OutputStreamWriter fw = new OutputStreamWriter ( new FileOutputStream ( pckDir . getAbsolutePath ( ) + File . separator + templateEntry . getKey ( ) + ".java" ) , "UTF-8" ) ) { log . info ( "Creating file " + pckDir . getAbsolutePath ( ) + File . separator + templateEntry . getKey ( ) + ".java" ) ; VelocityContext context = new VelocityContext ( ) ; context . put ( "model" , model ) ; context . put ( "tool" , new ModelTools ( ) ) ; context . put ( "clazzName" , templateEntry . getKey ( ) ) ; template . merge ( context , fw ) ; } } catch ( IOException e ) { log . error ( "Failed to write the generated file " + templateEntry . getKey ( ) , e ) ; throw new MojoExecutionException ( "Failed to write the generated file " + templateEntry . getKey ( ) , e ) ; } } }
@param log       the logger
@param model     the generator model
@param targetDir the target path for generation
@throws MojoExecutionException on errors