diff options
author | Shevek <[email protected]> | 2014-01-29 00:27:28 -0800 |
---|---|---|
committer | Shevek <[email protected]> | 2014-01-29 00:27:28 -0800 |
commit | f2b03d6787e89255d68f5398a8a8e0d544f12405 (patch) | |
tree | 5ac3913339715f4f514d02745a5ec8245bdad90c /buildSrc/src/main | |
parent | c06119b6d97f700f3843b5b5e5679ff522b47963 (diff) |
Use gradle-velocity-task.
Update PreprocessorListener to be an interface.
Make Source.getName() public.
Diffstat (limited to 'buildSrc/src/main')
-rw-r--r-- | buildSrc/src/main/groovy/VelocityPlugin.groovy | 33 | ||||
-rw-r--r-- | buildSrc/src/main/groovy/VelocityTask.groovy | 58 |
2 files changed, 0 insertions, 91 deletions
diff --git a/buildSrc/src/main/groovy/VelocityPlugin.groovy b/buildSrc/src/main/groovy/VelocityPlugin.groovy deleted file mode 100644 index cc8741a..0000000 --- a/buildSrc/src/main/groovy/VelocityPlugin.groovy +++ /dev/null @@ -1,33 +0,0 @@ -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.apache.velocity.VelocityContext -import org.apache.velocity.app.VelocityEngine -import org.apache.velocity.runtime.log.SystemLogChute - -class VelocityPluginExtension { - String inputDir = "src/main/velocity" - String outputDir = "build/generated-sources/velocity" - Map<String, Object> contextValues = [:] - def context(Closure closure) { - contextValues.with closure - } -} - -class VelocityPlugin implements Plugin<Project> { - void apply(Project project) { - - project.extensions.create("velocity", VelocityPluginExtension) - - project.task('velocityVpp', type: VelocityTask) { - description "Preprocesses velocity template files." - inputDir = project.file(project.velocity.inputDir) - outputDir = project.file(project.velocity.outputDir) - contextValues = project.velocity.contextValues - } - - project.compileJava.dependsOn(project.velocityVpp) - project.sourceSets.main.java.srcDir project.velocity.outputDir - - } -} - diff --git a/buildSrc/src/main/groovy/VelocityTask.groovy b/buildSrc/src/main/groovy/VelocityTask.groovy deleted file mode 100644 index 6a36903..0000000 --- a/buildSrc/src/main/groovy/VelocityTask.groovy +++ /dev/null @@ -1,58 +0,0 @@ -import org.apache.velocity.VelocityContext -import org.apache.velocity.app.VelocityEngine -import org.apache.velocity.runtime.log.SystemLogChute -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction - -class VelocityTask extends DefaultTask { - - @InputDirectory - File inputDir - - @OutputDirectory - File outputDir - - String filter = '**/*.java' - - File includeDir - - Map<String, Object> contextValues = [:] - - @TaskAction - void run() { - outputDir.deleteDir() - outputDir.mkdirs() - // println "Velocity: $inputDir -> $outputDir" - - VelocityEngine engine = new VelocityEngine() - engine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, SystemLogChute.class.name) - engine.setProperty(VelocityEngine.RESOURCE_LOADER, "file") - engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_CACHE, "true") - if (includeDir != null) - engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, includeDir.getAbsolutePath()) - def inputFiles = project.fileTree( - dir: inputDir, - include: filter - ) - inputFiles.visit { e -> - if (e.file.isFile()) { - File outputFile = e.relativePath.getFile(outputDir) - VelocityContext context = new VelocityContext() - contextValues.each { context.put(it.key, it.value) } - context.put('project', project) - context.put('package', e.relativePath.parent.segments.join('.')) - context.put('class', e.relativePath.lastName.replaceFirst("\\.java\$", "")) - // println "Parsing ${e.file}" - e.file.withReader { reader -> - outputFile.parentFile.mkdirs() - outputFile.withWriter { writer -> - engine.evaluate(context, writer, e.relativePath.toString(), reader) - } - } - } - } - } -} - |