public void acceptResult(CompilationResult cresult) {
try {
if (cresult.hasProblems()) {
IProblem[] cproblems = cresult.getProblems();
for (int i = 0; i < cproblems.length; i++) {
IProblem problem = cproblems[i];
if (problem.isError()) {
problemList.add(problem);
}
}
}
if (problemList.isEmpty()) {
ClassFile[] classFiles = cresult.getClassFiles();
for (int i = 0; i < classFiles.length; i++) {
ClassFile classFile = classFiles[i];
char[][] compoundName =
classFile.getCompoundName();
String className = "";
String sep = "";
for (int j = 0;
j < compoundName.length; j++) {
className += sep;
className += new String(compoundName[j]);
sep = ".";
}
byte[] bytes = classFile.getBytes();
String outFile = outputDir + "/" +
className.replace('.', '/') + ".class";
File parentFolder = new File(new File(outFile).getParent());
if(!parentFolder.exists())
parentFolder.mkdirs();
FileOutputStream fout =
new FileOutputStream(outFile);
BufferedOutputStream bos =
new BufferedOutputStream(fout);
bos.write(bytes);
bos.close();
}
}
} catch (IOException exc) {
Logger.error(this, "Compilation error", exc);
}
}
};
ICompilationUnit[] compilationUnits =
new ICompilationUnit[classNames.length];
for (int i = 0; i < compilationUnits.length; i++) {
String className = classNames[i];
compilationUnits[i] = new CompilationUnit(fileNames[i], className);
}
Compiler compiler = new Compiler(env,
policy,
coptions,
requestor,
problemFactory);
compiler.compile(compilationUnits);
List<DotCompilationProblem> dotProblemsList = new ArrayList<DotCompilationProblem> ();
if (!problemList.isEmpty()) {
for(IProblem problem : problemList) {
DotCompilationProblem p = new DotCompilationProblem(new String(problem.getOriginatingFileName()),
problem.getMessage(), problem.getSourceLineNumber(), problem.isError());
dotProblemsList.add(p);
}
}
return new DotCompilationProblems(dotProblemsList);