package com.intellij.idea;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.application.impl.PluginsFacade;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.util.InvalidDataException;

import java.io.IOException;

public class IdeaTestApplication extends CommandLineApplication {
  private DataProvider myDataContext;

  private IdeaTestApplication() {
    super(false, true, true, IdeaApplication.getComponentSetsDescriptor());

    PluginsFacade.INSTANCE = new PluginsFacade() {
      public IdeaPluginDescriptor getPlugin(PluginId id) {
        return PluginManager.getPlugin(id);
      }

      public IdeaPluginDescriptor[] getPlugins() {
        return PluginManager.getPlugins();
      }
    };
  }

  public void setDataProvider(DataProvider dataContext) {
    myDataContext = dataContext;
  }

  public Object getData(String dataId) {
    return myDataContext == null ? null : myDataContext.getData(dataId);
  }




  public static synchronized IdeaTestApplication getInstance() throws IOException, InvalidDataException {
    if (ourInstance == null) {
      new IdeaTestApplication();
      PluginsFacade.INSTANCE.getPlugins(); //initialization
      ApplicationManagerEx.getApplicationEx().load(null);
    }
    return (IdeaTestApplication)ourInstance;
  }
}

@@ -173,24 +173,183 @@
 taProvider;%0A
+import com.intellij.openapi.application.Result;%0Aimport com.intellij.openapi.application.WriteAction;%0Aimport com.intellij.openapi.application.ex.ApplicationEx;%0A
 import com.i
@@ -1541,16 +1541,42 @@
 on%0A     
+ final ApplicationEx app =
  Applica
@@ -1611,18 +1611,149 @@
 Ex()
-.load(null
+;%0A      new WriteAction() %7B%0A        protected void run(Result result) throws Throwable %7B%0A          app.load(null);%0A        %7D%0A      %7D.execute(
 );%0A 

test deadlock fixed.