以下代码仅适用于我的开发环境。但是,它会在生产中引发错误(如下所述)。
class ThemeBuilder {
def compileTheme(basePath, courseID, desiredColor) {
def outputCSSFilename = basePath + 'themes/' + courseID.toString() + '.css'
def tmpFilename = basePath + courseID.toString() + '_tmp.scss'
def sourceFilename = basePath + 'theme-builder-source.scss'
def source = new File(sourceFilename)
def tmp = new File(tmpFilename)
def pattern = ~/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
def matches = pattern.matcher(desiredColor).matches()
// Checks existence of the path for themes
def dir = new File(basePath + 'themes')
if (! dir.exists()) dir.mkdirs()
// Validate color
if (!matches) desiredColor = '#4F9C91'
// Replace placeholder color with desired color
tmp.withWriter { w ->
source.eachLine { line ->
w << line.replaceAll('brand-primary: #F7DC40', 'brand-primary: ' + desiredColor) + System.getProperty('line.separator')
}
}
// Compilation process
def cmd = 'sass ' + tmpFilename + ' ' + outputCSSFilename + ' --style compact'
def result = cmd.execute()
result.waitFor()
//////////////// Debugging ////////////////
// println "Text output: ${ result.text }"
// println "Return code: ${ result.exitValue() }"
// println "stderr: ${ result.err.text }"
// println "stdout: ${ result.in.text }"
//////////////////////////////////////////
// Remove tmp file
tmp.delete()
}
}
错误:
2014-10-22 14:41:28,886 [http-bio-8080-exec-19] ERROR errors.GrailsExceptionResolver - IOException occurred when processing request: [PUT] /pemaap/course/update
error=2, No such file or directory. Stacktrace follows:
java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at br.com.tokenlab.pemaap.ThemeBuilder.compileTheme(ThemeBuilder.groovy:32)
请注意,问题从第32行开始,与行def result = cmd.execute()
完全对应。
我无法检查tomcat7用户(ps aux | grep tomcat)是否能够执行root用户安装的sass,或者实际上是否缺少某些必需文件。有没有人经历过这个?
Obs:服务器在Ubuntu 14.04.1 LTS上运行。