added support for copying directories

This commit is contained in:
Tony Tam 2012-10-07 09:46:58 -07:00
parent 51437245e4
commit aef4190624

View File

@ -491,7 +491,7 @@ class Codegen(config: CodegenConfig) {
"models" -> modelList) "models" -> modelList)
config.supportingFiles.map(file => { config.supportingFiles.map(file => {
val srcTemplate = file._1 val supportingFile = file._1
val outputDir = file._2 val outputDir = file._2
val destFile = file._3 val destFile = file._3
@ -499,9 +499,9 @@ class Codegen(config: CodegenConfig) {
val outputFolder = new File(outputFilename).getParent val outputFolder = new File(outputFilename).getParent
new File(outputFolder).mkdirs new File(outputFolder).mkdirs
if (srcTemplate.endsWith(".mustache")) { if (supportingFile.endsWith(".mustache")) {
val output = { val output = {
val resourceName = config.templateDir + File.separator + srcTemplate val resourceName = config.templateDir + File.separator + supportingFile
val is = getInputStream(resourceName) val is = getInputStream(resourceName)
if (is == null) if (is == null)
throw new Exception("Resource not found: " + resourceName) throw new Exception("Resource not found: " + resourceName)
@ -515,7 +515,13 @@ class Codegen(config: CodegenConfig) {
fw.close() fw.close()
println("wrote " + outputFilename) println("wrote " + outputFilename)
} else { } else {
val is = getInputStream(config.templateDir + File.separator + srcTemplate) val file = new File(config.templateDir + File.separator + supportingFile)
if(file.isDirectory()) {
// copy the whole directory
FileUtils.copyDirectory(file, new File(outputDir))
println("copied directory " + supportingFile)
} else {
val is = getInputStream(config.templateDir + File.separator + supportingFile)
val outputFile = new File(outputFilename) val outputFile = new File(outputFilename)
val parentDir = new File(outputFile.getParent) val parentDir = new File(outputFile.getParent)
if (parentDir != null && !parentDir.exists) { if (parentDir != null && !parentDir.exists) {
@ -525,6 +531,7 @@ class Codegen(config: CodegenConfig) {
println("copied " + outputFilename) println("copied " + outputFilename)
is.close is.close
} }
}
}) })
//a shutdown method will be added to scalate in an upcoming release //a shutdown method will be added to scalate in an upcoming release
engine.compiler.asInstanceOf[ScalaCompiler].compiler.askShutdown engine.compiler.asInstanceOf[ScalaCompiler].compiler.askShutdown