src/main/java/org/fuin/srcgen4j/core/velocity/VelocityGenerator.java
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);
            }
        }

    }
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);
            }
        }

    }
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.

@param context
Context to use.
@param artifactName
Unique name of the generated artifact.
@param templateName
Name of the template to use.
@param filename
Filename relative to the target directory.

@throws GenerateException
Error merging the template
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 .