private static GenerationItem[] doGenerate( @NotNull final CompileContext context, @NotNull final GenerationItem[] items, VirtualFile outputRootDirectory) { if (context.getProject().isDisposed()) { return EMPTY_GENERATION_ITEM_ARRAY; } // we have one item per module there, so clear output directory final String genRootPath = FileUtil.toSystemDependentName(outputRootDirectory.getPath()); final File genRootDir = new File(genRootPath); if (genRootDir.exists()) { if (!FileUtil.delete(genRootDir)) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot delete directory " + genRootPath, null, -1, -1); return EMPTY_GENERATION_ITEM_ARRAY; } if (!genRootDir.mkdir()) { context.addMessage( CompilerMessageCategory.ERROR, "Cannot create directory " + genRootPath, null, -1, -1); return EMPTY_GENERATION_ITEM_ARRAY; } } final List<GenerationItem> results = new ArrayList<GenerationItem>(items.length); for (final GenerationItem item : items) { if (item instanceof MyGenerationItem) { final MyGenerationItem genItem = (MyGenerationItem) item; if (!AndroidCompileUtil.isModuleAffected(context, genItem.myModule)) { continue; } boolean success = true; for (final VirtualFile sourceFile : genItem.myFiles) { final String depFolderOsPath = getDependencyFolder(context.getProject(), sourceFile, outputRootDirectory); try { final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys( AndroidRenderscript.execute( genItem.mySdkLocation, genItem.myAndroidTarget, sourceFile.getPath(), genRootPath, depFolderOsPath, genItem.myRawDirPath)); ApplicationManager.getApplication() .runReadAction( new Runnable() { public void run() { if (context.getProject().isDisposed()) { return; } addMessages(context, messages, sourceFile.getUrl()); } }); if (messages.get(CompilerMessageCategory.ERROR).size() > 0) { success = false; } } catch (final IOException e) { ApplicationManager.getApplication() .runReadAction( new Runnable() { public void run() { if (context.getProject().isDisposed()) return; context.addMessage( CompilerMessageCategory.ERROR, e.getMessage(), sourceFile.getUrl(), -1, -1); } }); success = false; } } if (success) { results.add(genItem); } } } outputRootDirectory.refresh(false, true); return results.toArray(new GenerationItem[results.size()]); }