From e448d4703b0d151c7462c2a94907d8bc3336b438 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 28 Aug 2023 13:11:07 +0800 Subject: [PATCH] Add settings to control when to open the build output Signed-off-by: Sheng Chen --- extension/package.json | 15 +++++++++++++++ extension/src/bs/BuildServerController.ts | 12 +++++++++++- extension/src/util/config.ts | 12 ++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/extension/package.json b/extension/package.json index a3eb33fe..17408204 100644 --- a/extension/package.json +++ b/extension/package.json @@ -837,6 +837,21 @@ ], "markdownDescription": "[Experimental] Use build server to synchronize Gradle project when enabled. When set to `auto`, the build server will be enabled in Visual Studio Code - Insiders.", "default": "auto" + }, + "java.gradle.buildServer.openBuildOutput": { + "type": "string", + "enum": [ + "neverOpen", + "openOnBuildStart", + "openOnBuildFailure" + ], + "enumDescriptions": [ + "Never automatically open build output.", + "Open the build output when the build starts.", + "Open the build output when the build fails." + ], + "default": "openOnBuildFailure", + "description": "Controls when the build output should open." } } }, diff --git a/extension/src/bs/BuildServerController.ts b/extension/src/bs/BuildServerController.ts index 5352cb12..9cfafaf3 100644 --- a/extension/src/bs/BuildServerController.ts +++ b/extension/src/bs/BuildServerController.ts @@ -1,6 +1,7 @@ import { Disposable, ExtensionContext, OutputChannel, commands, languages, window } from "vscode"; import { GradleBuildLinkProvider } from "./GradleBuildLinkProvider"; import { sendInfo } from "vscode-extension-telemetry-wrapper"; +import { OpenBuildOutputValue, getOpenBuildOutput } from "../util/config"; const APPEND_BUILD_LOG_CMD = "_java.gradle.buildServer.appendBuildLog"; const LOG_CMD = "_java.gradle.buildServer.log"; @@ -23,7 +24,16 @@ export class BuildServerController implements Disposable { commands.registerCommand(APPEND_BUILD_LOG_CMD, (msg: string) => { if (msg) { this.buildOutputChannel.appendLine(msg); - if (/^BUILD (SUCCESSFUL|FAILED)/m.test(msg)) { + const openBehavior: OpenBuildOutputValue = getOpenBuildOutput(); + if (openBehavior === OpenBuildOutputValue.NEVER) { + return; + } + + const pattern = + openBehavior === OpenBuildOutputValue.ON_BUILD_START + ? /^> Build starts at /m + : /^BUILD FAILED/m; + if (pattern.test(msg)) { this.buildOutputChannel.show(true); } } diff --git a/extension/src/util/config.ts b/extension/src/util/config.ts index 15629cd3..609fd8e8 100644 --- a/extension/src/util/config.ts +++ b/extension/src/util/config.ts @@ -114,6 +114,18 @@ export function getAllowParallelRun(): boolean { return vscode.workspace.getConfiguration("gradle").get("allowParallelRun", false); } +export function getOpenBuildOutput(): OpenBuildOutputValue { + return vscode.workspace + .getConfiguration("java.gradle.buildServer") + .get("openBuildOutput", OpenBuildOutputValue.ON_BUILD_FAILURE); +} + +export enum OpenBuildOutputValue { + NEVER = "neverOpen", + ON_BUILD_START = "openOnBuildStart", + ON_BUILD_FAILURE = "openOnBuildFailure", +} + export enum ProjectOpenBehaviourValue { INTERACTIVE = "Interactive", OPEN = "Open",