<commit_before>package org.anarres.gradle.plugin.velocity;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.log.SystemLogChute;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.EmptyFileVisitor;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;

/**
 * A bare velocity task.
 *
 * You may use this to do arbitrary velocity processing without
 * necessarily applying the plugin.
 *
 * @author shevek
 */
public class VelocityTask extends DefaultTask {

    @InputDirectory
    public File inputDir;
    @OutputDirectory
    public File outputDir;

    @Input
    public String filter = "**/*.java";
    @Optional
    @InputDirectory
    public File includeDir;
    @Input
    public Map<String, Object> contextValues = new HashMap<String, Object>();

    public VelocityTask() {
        doLast(new Action<Task>() {

            @Override
            public void execute(Task task) {
                DefaultGroovyMethods.deleteDir(outputDir);
                outputDir.mkdirs();

                final VelocityEngine engine = new VelocityEngine();
                setProperty(engine, VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
                setProperty(engine, VelocityEngine.RESOURCE_LOADER, "file");
                setProperty(engine, VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true");<commit_msg>Add comment on Velocity's file path syntax.<commit_after>package org.anarres.gradle.plugin.velocity;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.log.SystemLogChute;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.EmptyFileVisitor;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;

/**
 * A bare velocity task.
 *
 * You may use this to do arbitrary velocity processing without
 * necessarily applying the plugin.
 *
 * @author shevek
 */
public class VelocityTask extends DefaultTask {

    @InputDirectory
    public File inputDir;
    @OutputDirectory
    public File outputDir;

    @Input
    public String filter = "**/*.java";
    @Optional
    @InputDirectory
    public File includeDir;
    @Input
    public Map<String, Object> contextValues = new HashMap<String, Object>();

    public VelocityTask() {
        doLast(new Action<Task>() {

            @Override
            public void execute(Task task) {
                DefaultGroovyMethods.deleteDir(outputDir);
                outputDir.mkdirs();

                final VelocityEngine engine = new VelocityEngine();
                setProperty(engine, VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.getName());
                setProperty(engine, VelocityEngine.RESOURCE_LOADER, "file");
                setProperty(engine, VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true");
                // FILE_RESOURCE_LOADER_PATH actually takes a comma separated list. 
{'fraction_non_alphanumeric': 0.09701679618952118, 'fraction_numerical': 0.0, 'mean_word_length': 3.6721311475409837, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4044665', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1114, 'n_words': 252}