Skip to content

Commit

Permalink
Prepare for 2023.3: Do not depend on MacroManager.getInstance()
Browse files Browse the repository at this point in the history
Probably caused by this change
JetBrains/intellij-community@b3ed617#diff-737d7a5e2b283fc8b2a9c7f301e689e29a83629c1a3533053b813570da2e59f4R21

Before that, MacroManager was instantiated only if it was present in LangExtensions.xml (not a thing in Bazel Plugin tests).
Now, it is instantiated always, which results in a crash in expandMacros call in tests. Hence, we need a new way to disable
macro expansion in tests.
  • Loading branch information
tpasternak committed Sep 26, 2023
1 parent 9d3a13e commit 4f6c1a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 1 addition & 9 deletions base/src/com/google/idea/blaze/base/command/BlazeFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import com.google.idea.blaze.base.projectview.section.sections.SyncFlagsSection;
import com.google.idea.blaze.base.projectview.section.sections.TestFlagsSection;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.util.ProgramParametersConfigurator;
import com.intellij.ide.macro.MacroManager;
import com.intellij.openapi.project.Project;
import com.intellij.util.PlatformUtils;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -124,13 +123,6 @@ public static String getToolTagFlag() {

/** Expands any macros in the passed build flags. */
public static List<String> expandBuildFlags(List<String> flags) {
// The code below depends on there being a globally registered `MacroManager`.
// `MacroManager` is a final class with a private constructor, and therefore it can't be mocked.
// We have tests that manipulate flags, but are not interested in exercising this code.
// Therefore, we return early in those cases.
if (MacroManager.getInstance() == null) {
return flags;
}
// This built-in IntelliJ class will do macro expansion using
// both your environment and your Settings > Behavior > Path Variables
List<String> expandedFlags = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -94,6 +95,7 @@ public <T> void register(Class<T> klass, T instance) {

@Before
public final void setup() {
Registry.get("allow.macros.for.run.configurations").setValue(false);
testDisposable = new RootDisposable();
MockApplication application = TestUtils.createMockApplication(testDisposable);
MockProject mockProject = TestUtils.mockProject(application.getPicoContainer(), testDisposable);
Expand Down

0 comments on commit 4f6c1a0

Please sign in to comment.