[tests] Don't steal focus when automatically rerunning tests

Prevents the build toolwindow from stealing the focus when an automatic build is triggered by the automatic test runner when the code is uncompilable. #IDEA-335769 Fixed

GitOrigin-RevId: d6bd1f9fade4fab3c91b25bbe788f870aaf123bc
This commit is contained in:
Bart van Helvert
2025-10-27 16:22:47 +00:00
committed by intellij-monorepo-bot
parent 5e2fb82872
commit 1c5b5f9f7b
7 changed files with 49 additions and 9 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.compiler.progress;
import com.intellij.build.*;
@@ -52,11 +52,21 @@ public class BuildOutputService implements BuildViewService {
private final @NotNull Project myProject;
private final @NotNull BuildProgress<BuildProgressDescriptor> myBuildProgress;
private final @NotNull @NlsContexts.TabTitle String myContentName;
private final boolean myCompilationStartedAutomatically;
private final ConsolePrinter myConsolePrinter;
public BuildOutputService(@NotNull Project project, @NotNull @NlsContexts.TabTitle String contentName) {
this(project, contentName, false);
}
public BuildOutputService(
@NotNull Project project,
@NotNull @NlsContexts.TabTitle String contentName,
boolean compilationStartedAutomatically
) {
myProject = project;
myContentName = contentName;
myCompilationStartedAutomatically = compilationStartedAutomatically;
myBuildProgress = BuildViewManager.createBuildProgress(project);
myConsolePrinter = new ConsolePrinter(myBuildProgress);
}
@@ -101,6 +111,11 @@ public class BuildOutputService implements BuildViewService {
})
.withContextActions(contextActions.toArray(AnAction.EMPTY_ARRAY));
if (myCompilationStartedAutomatically) {
// When compilation is triggered automatically (e.g., by auto test run), avoid stealing focus
buildDescriptor.setActivateToolWindowWhenFailed(false);
}
myBuildProgress.start(new BuildProgressDescriptor() {
@Override
public @NotNull String getTitle() {
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.compiler.progress;
import com.intellij.compiler.CompilerManagerImpl;
@@ -67,7 +67,7 @@ public final class CompilerTask extends Task.Backgroundable {
mySessionId = myContentId; // by default sessionID should be unique, just as content ID
if (SystemProperties.getBooleanProperty("ide.jps.use.build.tool.window", true)) {
myBuildViewService = new BuildOutputService(project, contentName);
myBuildViewService = new BuildOutputService(project, contentName, myCompilationStartedAutomatically);
} else {
myBuildViewService = new CompilerMessagesService(project, myContentId, contentName, headlessMode);
}