boolean hasErrors = unitResult.hasErrors();
if (!hasErrors || proceedOnError()) {
Collection<ClassFile> classFiles = unitResult.compiledTypes.values();
boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null);
for (Iterator<ClassFile> iter = classFiles.iterator(); iter.hasNext();) {
ClassFile classFile = iter.next();
String filename = new String(classFile.fileName());
String classname = filename.replace('/', '.');
filename = filename.replace('/', File.separatorChar) + ".class";
try {
if (buildConfig.getOutputJar() == null) {
String outfile = writeDirectoryEntry(unitResult, classFile, filename);
getWorld().classWriteEvent(classFile.getCompoundName());
if (environmentSupportsIncrementalCompilation) {
if (!classname.endsWith("$ajcMightHaveAspect")) {
ResolvedType type = getBcelWorld().resolve(classname);
if (type.isAspect()) {
state.recordAspectClassFile(outfile);
}
}
}
} else {
writeZipEntry(classFile, filename);
}
if (shouldAddAspectName && !classname.endsWith("$ajcMightHaveAspect")) {
addAspectName(classname, unitResult.getFileName());
}
} catch (IOException ex) {
IMessage message = EclipseAdapterUtils.makeErrorMessage(new String(unitResult.fileName),
CANT_WRITE_RESULT, ex);
handler.handleMessage(message);
}
}
state.noteNewResult(unitResult);
unitResult.compiledTypes.clear(); // free up references to AjClassFile instances
}
if (unitResult.hasProblems() || unitResult.hasTasks()) {
IProblem[] problems = unitResult.getAllProblems();
for (int i = 0; i < problems.length; i++) {
IMessage message = EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problems[i], getBcelWorld(),
progressListener);
handler.handleMessage(message);
}
}
}
private String writeDirectoryEntry(CompilationResult unitResult, ClassFile classFile, String filename)
throws IOException {
File destinationPath = buildConfig.getOutputDir();
if (buildConfig.getCompilationResultDestinationManager() != null) {
destinationPath = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(
new File(new String(unitResult.fileName)));
}
String outFile;
if (destinationPath == null) {
outFile = new File(filename).getName();
outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath();
} else {
outFile = new File(destinationPath, filename).getPath();
}
try {
BufferedOutputStream os = FileUtil.makeOutputStream(new File(outFile));
os.write(classFile.getBytes());
os.close();
} catch (FileNotFoundException fnfe) {
IMessage msg = new Message("unable to write out class file: '" + filename + "' - reason: " + fnfe.getMessage(),
IMessage.ERROR, null, new SourceLocation(new File(outFile), 0));
handler.handleMessage(msg);
}
if (buildConfig.getCompilationResultDestinationManager() != null) {
buildConfig.getCompilationResultDestinationManager().reportFileWrite(outFile,
CompilationResultDestinationManager.FILETYPE_CLASS);
}
return outFile;
}
private void writeZipEntry(ClassFile classFile, String name) throws IOException {
name = name.replace(File.separatorChar, '/');
ZipEntry newEntry = new ZipEntry(name); // ??? get compression scheme right
zos.putNextEntry(newEntry);
zos.write(classFile.getBytes());
zos.closeEntry();
}
private void addAspectName(String name, char[] fileContainingAspect) {
BcelWorld world = getBcelWorld();