import org.example.*

apply plugin: "base"

task processTemplates(type: ProcessTemplates) {
    templateEngine = TemplateEngineType.FREEMARKER
    sourceFiles = fileTree("src/templates")
    templateData = new TemplateData("test", [year: 2012])
    outputDir = file("$buildDir/genOutput")
}

task processTemplatesAdHoc {
    inputs.property("engine", TemplateEngineType.FREEMARKER)
    inputs.files(fileTree("src/templates"))
    inputs.property("templateData.name", "docs")
    inputs.property("templateData.variables", [year: 2013])
    outputs.dir("$buildDir/genOutput2")

    doLast {
        // Process the templates here
        copy {
            into "$buildDir/genOutput2"
            from fileTree("src/templates")
            expand([year: 2013])
        }

    }
}

task processTemplatesRuntime(type: ProcessTemplatesNoAnnotations) {
    templateEngine = TemplateEngineType.FREEMARKER
    sourceFiles = fileTree("src/templates")
    templateData = new TemplateData("test", [year: 2014])
    outputDir = file("$buildDir/genOutput3")

    inputs.property("engine",templateEngine)
    inputs.files(sourceFiles)
    inputs.property("templateData.name", templateData.name)
    inputs.property("templateData.variables", templateData.variables)
    outputs.dir(outputDir)
}

task processTemplatesRuntimeConf(type: ProcessTemplatesNoAnnotations) {
    // ...
    templateEngine = TemplateEngineType.FREEMARKER
    templateData = new TemplateData("test", [year: 2014])
    outputDir = file("$buildDir/genOutput3")
    sourceFiles = fileTree("src/templates") {
        include "**/*.fm"
    }

    inputs.files(sourceFiles).skipWhenEmpty()
    // ...
    inputs.property("engine",templateEngine)
    inputs.property("templateData.name", templateData.name)
    inputs.property("templateData.variables", templateData.variables)
    outputs.dir(outputDir)
}

task packageFiles(type: Zip) {
    from processTemplates.outputs
}

task packageFiles2(type: Zip) {
    from processTemplates
}


build.dependsOn processTemplates, processTemplatesAdHoc, processTemplatesRuntime, processTemplatesRuntimeConf
