{
Log log = getLog();
File baseDir = new File(directory);
if (baseDir.exists() && baseDir.isDirectory()) {
CompilerEnvirons env = createEnvironment();
ClassCompiler compiler = new ClassCompiler(env);
File targetDirFile = new File(targetPath);
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(baseDir);
scanner.setIncludes(new String[]{pattern});
scanner.scan();
for (String fn : scanner.getIncludedFiles()) {
File input = new File(baseDir, fn);
String baseName = getBaseName(fn);
String className = baseName.replaceAll("[/\\\\]", ".");
File output = new File(targetDirFile, baseName + ".class");
File srcOutput = new File(targetDirFile, baseName + ".js");
if (input.lastModified() >= output.lastModified()) {
if (output.getParentFile() != null) {
output.getParentFile().mkdirs();
}
log.info("Compiling " + fn + " to " + output.getPath());
try {
String source = loadSource(input);
Object[] bytes;
try {
bytes = compiler.compileToClassFiles(addPrefixes(source), input.getName(),
1, className);
} catch (RhinoException re) {
throw new MojoExecutionException(
"Error compiling script file " + fn + " :" + re.lineNumber() + ':' + re, re);
}