From 30cb7b88c7f5308f359d7e5b232cb70ea69e22eb Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Jun 2019 07:15:29 -0400 Subject: [PATCH] fix ProjectOpeningTest GitOrigin-RevId: 75548ee7fd3a7319c2b8d2d7c0dd57a48d202403 --- .../extensions/impl/ExtensionPointImpl.java | 23 +++++++++++++------ .../project/impl/ProjectOpeningTest.java | 13 ++++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java index 5595164341f7..9bacb909a33c 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java @@ -294,6 +294,13 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab assertBeforeProcessing(); CHECK_CANCELED.run(); + if (isInReadOnlyMode()) { + for (T extension : myExtensionsCache) { + consumer.accept(extension, myDescriptor /* doesn't matter for tests */); + } + return; + } + List adapters = myAdapters; int size = adapters.size(); if (size == 0) { @@ -376,6 +383,7 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab @NotNull private synchronized T[] processAdapters() { assertBeforeProcessing(); + assertNotReadOnlyMode(); long startTime = StartUpMeasurer.getCurrentTime(); @@ -473,7 +481,6 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab throw new IllegalStateException("Recursive processAdapters() detected. You must have called 'getExtensions()' from within your extension constructor - don't. " + "Either pass extension via constructor parameter or call getExtensions() later."); } - assertNotReadOnlyMode(); } // used in upsource @@ -529,13 +536,15 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab myExtensionsCacheAsArray = list.toArray(ArrayUtil.newArray(getExtensionClass(), 0)); POINTS_IN_READONLY_MODE.add(this); - if (oldList != null) { - for (T extension : oldList) { - notifyListenersOnRemove(extension, null, myListeners); + if (myListeners.length > 0) { + if (oldList != null) { + for (T extension : oldList) { + notifyListenersOnRemove(extension, null, myListeners); + } + } + for (T extension : list) { + notifyListenersOnAdd(extension, null, myListeners); } - } - for (T extension : list) { - notifyListenersOnAdd(extension, null, myListeners); } Disposer.register(parentDisposable, new Disposable() { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/project/impl/ProjectOpeningTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/project/impl/ProjectOpeningTest.java index 578c97b3f086..ed04bc8d183a 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/project/impl/ProjectOpeningTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/project/impl/ProjectOpeningTest.java @@ -17,25 +17,26 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; +import java.util.Collections; import static com.intellij.openapi.startup.StartupActivity.POST_STARTUP_ACTIVITY; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author Dmitry Avdeev */ public class ProjectOpeningTest extends PlatformTestCase { public void testOpenProjectCancelling() throws Exception { - File foo = createTempDir("foo"); Project project = null; MyStartupActivity activity = new MyStartupActivity(); - POST_STARTUP_ACTIVITY.getPoint(null).registerExtension(activity, getTestRootDisposable()); - + PlatformTestUtil.maskExtensions(POST_STARTUP_ACTIVITY, Collections.singletonList(activity), getTestRootDisposable()); try { ProjectManagerEx manager = ProjectManagerEx.getInstanceEx(); + File foo = createTempDir("foo"); project = manager.createProject(null, foo.getPath()); - assertFalse(manager.openProject(project)); - assertFalse(project.isOpen()); - assertTrue(activity.passed); + assertThat(manager.openProject(project)).isFalse(); + assertThat(project.isOpen()).isFalse(); + assertThat(activity.passed).isTrue(); } finally { closeProject(project);