public void processTemplate()

in src/main/java/org/apache/maven/plugins/changes/announcement/AnnouncementMojo.java [597:634]


    public void processTemplate(Context context, File outputDirectory, String template, String announcementFile)
            throws VelocityException, MojoExecutionException {

        // Use the name of the template as a default value
        if (announcementFile == null || announcementFile.isEmpty()) {
            announcementFile = template;
        }

        if (!outputDirectory.exists()) {
            if (!outputDirectory.mkdirs()) {
                throw new MojoExecutionException("Failed to create directory " + outputDirectory);
            }
        }

        File f = new File(outputDirectory, announcementFile);

        VelocityEngine engine = velocity.getEngine();

        engine.setApplicationAttribute("baseDirectory", basedir);

        if (templateEncoding == null || templateEncoding.isEmpty()) {
            templateEncoding = Charset.defaultCharset().name();
            getLog().warn("File encoding has not been set, using platform encoding " + templateEncoding
                    + "; build is platform dependent!");
        }
        try (Writer writer = new OutputStreamWriter(new FileOutputStream(f), templateEncoding)) {
            Template velocityTemplate = engine.getTemplate(templateDirectory + "/" + template, templateEncoding);
            velocityTemplate.merge(context, writer);
            getLog().info("Created template " + f);
        } catch (ResourceNotFoundException ex) {
            throw new ResourceNotFoundException(
                    "Template not found. ( " + templateDirectory + "/" + template + " )", ex);
        } catch (VelocityException ve) {
            throw ve;
        } catch (RuntimeException | IOException e) {
            throw new MojoExecutionException(e.toString(), e);
        }
    }