private void compileChunk(ModuleChunk chunk) throws IOException {
    final String chunkPresentableName = getPresentableNameFor(chunk);
    myModuleName = chunkPresentableName;

    // validate encodings
    if (chunk.getModuleCount() > 1) {
      validateEncoding(chunk, chunkPresentableName);
      // todo: validation for bytecode target?
    }

    runTransformingCompilers(chunk);

    final List<OutputDir> outs = new ArrayList<OutputDir>();
    File fileToDelete = getOutputDirsToCompileTo(chunk, outs);

    try {
      for (final OutputDir outputDir : outs) {
        chunk.setSourcesFilter(outputDir.getKind());
        doCompile(chunk, outputDir.getPath());
      }
    } finally {
      if (fileToDelete != null) {
        FileUtil.asyncDelete(fileToDelete);
      }
    }
  }
 private void restoreFromUndoStorage(final File dst) {
   String normPath = FileUtil.toSystemIndependentName(dst.getPath());
   for (Iterator<Pair<File, File>> it = myUndoStorageContents.iterator(); it.hasNext(); ) {
     Pair<File, File> e = it.next();
     final String p = FileUtil.toSystemIndependentName(e.first.getPath());
     if (p.startsWith(normPath)) {
       try {
         FileUtil.rename(e.second, e.first);
       } catch (IOException ex) {
         LOG.error(ex);
         FileUtil.asyncDelete(e.second);
       }
       it.remove();
     }
   }
   if (myStorageForUndo != null) {
     final File[] files = myStorageForUndo.listFiles();
     if (files == null || files.length == 0) {
       FileUtil.asyncDelete(myStorageForUndo);
       myStorageForUndo = null;
     }
   }
 }
  public void compile() throws CompilerException, CacheCorruptedException {
    Application application = ApplicationManager.getApplication();
    try {
      if (!myFilesToCompile.isEmpty()) {
        if (application.isUnitTestMode()) {
          saveTestData();
        }
        compileModules(buildModuleToFilesMap(myFilesToCompile));
      }
    } catch (SecurityException e) {
      throw new CompilerException(
          CompilerBundle.message("error.compiler.process.not.started", e.getMessage()), e);
    } catch (IllegalArgumentException e) {
      throw new CompilerException(e.getMessage(), e);
    } finally {
      for (final VirtualFile file : myModuleToTempDirMap.values()) {
        if (file != null) {
          final File ioFile = new File(file.getPath());
          FileUtil.asyncDelete(ioFile);
        }
      }
      myModuleToTempDirMap.clear();
    }

    if (!myFilesToCompile.isEmpty()
        && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) {
      // package-info.java hack
      final List<TranslatingCompiler.OutputItem> outputs =
          new ArrayList<TranslatingCompiler.OutputItem>();
      ApplicationManager.getApplication()
          .runReadAction(
              new Runnable() {
                public void run() {
                  for (final VirtualFile file : myFilesToCompile) {
                    if (PACKAGE_ANNOTATION_FILE_NAME.equals(file.getName())
                        && !myProcessedPackageInfos.contains(file)) {
                      outputs.add(new OutputItemImpl(file));
                    }
                  }
                }
              });
      if (!outputs.isEmpty()) {
        mySink.add(null, outputs, VirtualFile.EMPTY_ARRAY);
      }
    }
  }