inject ProgressManager as dependency instead of using getInstance() (EA-23312 - NPE: ProjectManagerImpl.loadProjectWithProgress)

This commit is contained in:
Dmitry Jemerov
2010-11-11 13:33:33 +03:00
parent 7603d11781
commit 4e9a900577
2 changed files with 9 additions and 6 deletions
@@ -20,6 +20,7 @@ import com.intellij.conversion.ConversionService;
import com.intellij.conversion.impl.ConversionResultImpl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vfs.ex.VirtualFileManagerEx;
@@ -33,8 +34,8 @@ import java.io.IOException;
* @author mike
*/
public class IdeaProjectManagerImpl extends ProjectManagerImpl {
public IdeaProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx) {
super(virtualFileManagerEx);
public IdeaProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx, ProgressManager progressManager) {
super(virtualFileManagerEx, progressManager);
}
@NotNull
@@ -101,6 +101,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
private final AtomicInteger myReloadBlockCount = new AtomicInteger(0);
private final Map<Project, String> myProjects = new WeakHashMap<Project, String>();
private static final int MAX_LEAKY_PROJECTS = 42;
private final ProgressManager myProgressManager;
private static ProjectManagerListener[] getListeners(Project project) {
List<ProjectManagerListener> array = project.getUserData(LISTENERS_IN_PROJECT_KEY);
@@ -108,7 +109,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
return ContainerUtil.toArray(array, new ProjectManagerListener[array.size()]);
}
public ProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx) {
public ProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx, ProgressManager progressManager) {
myProgressManager = progressManager;
Application app = ApplicationManager.getApplication();
MessageBus messageBus = app.getMessageBus();
MessageBusConnection connection = messageBus.connect(app);
@@ -382,7 +384,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
boolean ok = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() {
public void run() {
startupManager.runStartupActivities();
}
@@ -461,9 +463,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
}
final Project[] project = new Project[1];
boolean ok = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() {
public void run() {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
final ProgressIndicator indicator = myProgressManager.getProgressIndicator();
try {
if (indicator != null) {
indicator.setText(ProjectBundle.message("loading.components.for", filePath));