*/
protected void compile(String name, File baseDirectory, String encoding)
throws LanguageException {
try {
LanguageCompiler compiler = (LanguageCompiler)this.compilerClass.newInstance();
// AbstractJavaCompiler is LogEnabled
if (compiler instanceof LogEnabled) {
((LogEnabled)compiler).enableLogging(getLogger());
}
if (compiler instanceof Serviceable) {
((Serviceable)compiler).service(this.manager);
}
int pos = name.lastIndexOf(File.separatorChar);
String filename = name.substring(pos + 1);
final String basePath = baseDirectory.getCanonicalPath();
String filepath = basePath + File.separator + name + "." + getSourceExtension();
compiler.setFile(filepath);
compiler.setSource(basePath);
compiler.setDestination(basePath);
compiler.setClasspath(basePath + this.classpath);
compiler.setCompilerComplianceLevel(compilerComplianceLevel);
if (encoding != null) {
compiler.setEncoding(encoding);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Compiling " + filepath);
}
if (!compiler.compile()) {
StringBuffer message = new StringBuffer("Error compiling ");
message.append(filename);
message.append(":\n");
List errors = compiler.getErrors();
CompilerError[] compilerErrors = new CompilerError[errors.size()];
errors.toArray(compilerErrors);
throw new LanguageException(message.toString(), filepath, compilerErrors);
}