From 34e089628a03c7c2ea86c24303ff3dd306907dad Mon Sep 17 00:00:00 2001 From: Jiaming <71547730+Jiaaming@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:30:57 +0800 Subject: [PATCH] refactor - Rename to taskServerClient & remove gradle daemon status (#1531) --- extension/src/Extension.ts | 6 +- extension/src/api/Api.ts | 4 +- .../src/client/GradleBuildContentProvider.ts | 4 +- .../{GradleClient.ts => TaskServerClient.ts} | 88 +------------------ extension/src/client/index.ts | 2 +- extension/src/commands/CancelBuildCommand.ts | 4 +- extension/src/commands/Commands.ts | 4 +- .../src/commands/CreateProjectCommand.ts | 4 +- extension/src/commands/DebugTaskCommand.ts | 4 +- .../src/commands/DebugTaskWithArgsCommand.ts | 4 +- extension/src/commands/RestartTaskCommand.ts | 4 +- extension/src/commands/RunBuildCommand.ts | 4 +- extension/src/commands/RunTaskCommand.ts | 8 +- .../src/commands/RunTaskWithArgsCommand.ts | 4 +- extension/src/createProject/types.ts | 4 +- extension/src/tasks/GradleTaskProvider.ts | 4 +- extension/src/tasks/taskUtil.ts | 26 +++--- .../src/terminal/GradleRunnerTerminal.ts | 4 +- .../defaultProject/DefaultProjectProvider.ts | 4 +- .../DefaultProjectsTreeDataProvider.ts | 4 +- .../GradleTasksTreeDataProvider.ts | 4 +- .../RecentTasksTreeDataProvider.ts | 4 +- .../github/badsyntax/gradle/DaemonStatus.java | 36 -------- .../badsyntax/gradle/GradleExecution.java | 10 --- .../gradle/GradleLocalInstallation.java | 45 ---------- .../badsyntax/gradle/GradleWrapper.java | 58 ------------ .../github/badsyntax/gradle/TaskService.java | 21 ----- .../handlers/GetDaemonsStatusHandler.java | 77 ---------------- .../gradle/handlers/StopDaemonHandler.java | 41 --------- .../gradle/handlers/StopDaemonsHandler.java | 73 --------------- 30 files changed, 58 insertions(+), 501 deletions(-) rename extension/src/client/{GradleClient.ts => TaskServerClient.ts} (85%) delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/DaemonStatus.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/GradleExecution.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/GradleLocalInstallation.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/GradleWrapper.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/GetDaemonsStatusHandler.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonHandler.java delete mode 100644 gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonsHandler.java diff --git a/extension/src/Extension.ts b/extension/src/Extension.ts index 540921d3d..52a2ae2f4 100644 --- a/extension/src/Extension.ts +++ b/extension/src/Extension.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { commands, window } from "vscode"; import { logger, LogVerbosity, Logger } from "./logger"; import { Api } from "./api"; -import { GradleClient } from "./client"; +import { TaskServerClient } from "./client"; import { GradleServer } from "./server"; import { Icons } from "./icons"; import { GradleDaemonsTreeDataProvider, RecentTasksTreeDataProvider, GradleTasksTreeDataProvider } from "./views"; @@ -42,7 +42,7 @@ import { BspProxy } from "./bs/BspProxy"; export class Extension { private readonly bspProxy: BspProxy; - private readonly taskServerClient: GradleClient; + private readonly taskServerClient: TaskServerClient; private readonly server: GradleServer; private readonly pinnedTasksStore: PinnedTasksStore; private readonly recentTasksStore: RecentTasksStore; @@ -91,7 +91,7 @@ export class Extension { const statusBarItem = vscode.window.createStatusBarItem(); this.bspProxy = new BspProxy(this.context, bspLogger); this.server = new GradleServer({ host: "localhost" }, context, serverLogger, this.bspProxy); - this.taskServerClient = new GradleClient(this.server, statusBarItem, clientLogger); + this.taskServerClient = new TaskServerClient(this.server, statusBarItem, clientLogger); this.pinnedTasksStore = new PinnedTasksStore(context); this.recentTasksStore = new RecentTasksStore(); this.taskTerminalsStore = new TaskTerminalsStore(); diff --git a/extension/src/api/Api.ts b/extension/src/api/Api.ts index 7d428e9b4..c3b0bdd27 100644 --- a/extension/src/api/Api.ts +++ b/extension/src/api/Api.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { Output } from "../proto/gradle_pb"; import { Logger, logger } from "../logger"; import { GradleTasksTreeDataProvider } from "../views"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { Icons } from "../icons"; import { getRunBuildCancellationKey } from "../client/CancellationKeys"; import { GradleTaskProvider } from "../tasks"; @@ -40,7 +40,7 @@ export interface CancelBuildOpts { export class Api { constructor( - private readonly client: GradleClient, + private readonly client: TaskServerClient, private readonly tasksTreeDataProvider: GradleTasksTreeDataProvider, private readonly gradleTaskProvider: GradleTaskProvider, private readonly icons: Icons diff --git a/extension/src/client/GradleBuildContentProvider.ts b/extension/src/client/GradleBuildContentProvider.ts index a320bba1f..89a855c11 100644 --- a/extension/src/client/GradleBuildContentProvider.ts +++ b/extension/src/client/GradleBuildContentProvider.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import AwaitLock from "await-lock"; -import { GradleClient } from "."; +import { TaskServerClient } from "."; import { syncGradleBuild } from "../languageServer/languageServer"; import { GradleBuild } from "../proto/gradle_pb"; import { RootProject } from "../rootProject"; @@ -13,7 +13,7 @@ const lock = new AwaitLock(); export class GradleBuildContentProvider { private cachedBuild: Map = new Map(); - constructor(private readonly client: GradleClient) {} + constructor(private readonly client: TaskServerClient) {} public async getGradleBuild(rootProject: RootProject): Promise { await lock.acquireAsync(); diff --git a/extension/src/client/GradleClient.ts b/extension/src/client/TaskServerClient.ts similarity index 85% rename from extension/src/client/GradleClient.ts rename to extension/src/client/TaskServerClient.ts index 43178a93b..eef2ac63c 100644 --- a/extension/src/client/GradleClient.ts +++ b/extension/src/client/TaskServerClient.ts @@ -10,12 +10,6 @@ import { GradleBuild, Environment, GradleConfig, - GetDaemonsStatusReply, - GetDaemonsStatusRequest, - StopDaemonsReply, - StopDaemonsRequest, - StopDaemonRequest, - StopDaemonReply, RunBuildRequest, RunBuildReply, CancelBuildRequest, @@ -48,7 +42,7 @@ function logBuildEnvironment(environment: Environment): void { logger.info("Gradle Version:", gradleEnv.getGradleVersion()); } -export class GradleClient implements vscode.Disposable { +export class TaskServerClient implements vscode.Disposable { private readonly connectDeadline = 30; // seconds private grpcClient: GrpcClient | null = null; private readonly _onDidConnect: vscode.EventEmitter = new vscode.EventEmitter(); @@ -360,86 +354,6 @@ export class GradleClient implements vscode.Disposable { } } - public async getDaemonsStatus( - projectFolder: string, - cancelToken: vscode.CancellationToken - ): Promise { - await this.waitForConnect(); - logger.debug("Get daemon status"); - const request = new GetDaemonsStatusRequest(); - request.setProjectDir(projectFolder); - try { - return await new Promise((resolve, reject) => { - const stream = this.grpcClient!.getDaemonsStatus( - request, - (err: grpc.ServiceError | null, getDaemonsStatusReply: GetDaemonsStatusReply | undefined) => { - if (err) { - reject(err); - } else { - resolve(getDaemonsStatusReply); - } - } - ); - cancelToken.onCancellationRequested(() => stream.cancel()); - }); - } catch (err) { - const errMessage = err.details || err.message; - if (cancelToken.isCancellationRequested) { - logger.debug("Get daemon status:", errMessage); - } else { - logger.error("Unable to get daemon status:", errMessage); - } - } - } - - public async stopDaemons(projectFolder: string): Promise { - await this.waitForConnect(); - const request = new StopDaemonsRequest(); - request.setProjectDir(projectFolder); - try { - return await new Promise((resolve, reject) => { - this.grpcClient!.stopDaemons( - request, - (err: grpc.ServiceError | null, stopDaemonsReply: StopDaemonsReply | undefined) => { - if (err) { - reject(err); - } else { - resolve(stopDaemonsReply); - } - } - ); - }); - } catch (err) { - logger.error("Error stopping daemons:", err.details || err.message); - } finally { - await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS); - } - } - - public async stopDaemon(pid: string): Promise { - await this.waitForConnect(); - const request = new StopDaemonRequest(); - request.setPid(pid); - try { - return await new Promise((resolve, reject) => { - this.grpcClient!.stopDaemon( - request, - (err: grpc.ServiceError | null, stopDaemonReply: StopDaemonReply | undefined) => { - if (err) { - reject(err); - } else { - resolve(stopDaemonReply); - } - } - ); - }); - } catch (err) { - logger.error("Error stopping daemon:", err.details || err.message); - } finally { - await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS); - } - } - public async getNormalizedPackageName(name: string): Promise { await this.waitForConnect(); const request = new ExecuteCommandRequest(); diff --git a/extension/src/client/index.ts b/extension/src/client/index.ts index 13f62b255..b9db3247e 100644 --- a/extension/src/client/index.ts +++ b/extension/src/client/index.ts @@ -1 +1 @@ -export * from "./GradleClient"; +export * from "./TaskServerClient"; diff --git a/extension/src/commands/CancelBuildCommand.ts b/extension/src/commands/CancelBuildCommand.ts index 00d0ad89a..595607fad 100644 --- a/extension/src/commands/CancelBuildCommand.ts +++ b/extension/src/commands/CancelBuildCommand.ts @@ -2,11 +2,11 @@ import * as vscode from "vscode"; import { cancelBuild } from "../tasks/taskUtil"; import { logger } from "../logger"; import { Command } from "./Command"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_CANCEL_BUILD = "gradle.cancelBuild"; export class CancelBuildCommand extends Command { - constructor(private client: GradleClient) { + constructor(private client: TaskServerClient) { super(); } async run(cancellationKey: string, task?: vscode.Task): Promise { diff --git a/extension/src/commands/Commands.ts b/extension/src/commands/Commands.ts index 419d76262..9bd929659 100644 --- a/extension/src/commands/Commands.ts +++ b/extension/src/commands/Commands.ts @@ -66,7 +66,7 @@ import { COMMAND_RUN_TASK_DOUBLE_CLICK, RunTaskDoubleClickCommand, } from "."; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider"; import { PinnedTasksStore, RecentTasksStore, RootProjectsStore, TaskTerminalsStore } from "../stores"; import { GradleTaskProvider } from "../tasks"; @@ -88,7 +88,7 @@ export class Commands { private gradleTasksTreeDataProvider: GradleTasksTreeDataProvider, private recentTasksTreeDataProvider: RecentTasksTreeDataProvider, private gradleDaemonsTreeDataProvider: GradleDaemonsTreeDataProvider, - private client: GradleClient, + private client: TaskServerClient, private rootProjectsStore: RootProjectsStore, private taskTerminalsStore: TaskTerminalsStore, private recentTasksStore: RecentTasksStore, diff --git a/extension/src/commands/CreateProjectCommand.ts b/extension/src/commands/CreateProjectCommand.ts index ebc4e2856..62fe163ad 100644 --- a/extension/src/commands/CreateProjectCommand.ts +++ b/extension/src/commands/CreateProjectCommand.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as vscode from "vscode"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { getRunTaskCommandCancellationKey } from "../client/CancellationKeys"; import { selectProjectTypeStep } from "../createProject/SelectProjectTypeStep"; import { selectScriptDSLStep } from "../createProject/SelectScriptDSLStep"; @@ -15,7 +15,7 @@ export const COMMAND_CREATE_PROJECT = "gradle.createProject"; export const COMMAND_CREATE_PROJECT_ADVANCED = "gradle.createProjectAdvanced"; export class CreateProjectCommand extends Command { - constructor(private client: GradleClient) { + constructor(private client: TaskServerClient) { super(); } diff --git a/extension/src/commands/DebugTaskCommand.ts b/extension/src/commands/DebugTaskCommand.ts index 6742cec5a..436b04c59 100644 --- a/extension/src/commands/DebugTaskCommand.ts +++ b/extension/src/commands/DebugTaskCommand.ts @@ -2,11 +2,11 @@ import { GradleTaskTreeItem } from "../views"; import { runTask } from "../tasks/taskUtil"; import { Command } from "./Command"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_DEBUG_TASK = "gradle.debugTask"; export class DebugTaskCommand extends Command { - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); } async run(treeItem: GradleTaskTreeItem, args = ""): Promise { diff --git a/extension/src/commands/DebugTaskWithArgsCommand.ts b/extension/src/commands/DebugTaskWithArgsCommand.ts index ceb319b16..88511e7ba 100644 --- a/extension/src/commands/DebugTaskWithArgsCommand.ts +++ b/extension/src/commands/DebugTaskWithArgsCommand.ts @@ -3,11 +3,11 @@ import { runTaskWithArgs } from "../tasks/taskUtil"; import { logger } from "../logger"; import { Command } from "./Command"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_DEBUG_TASK_WITH_ARGS = "gradle.debugTaskWithArgs"; export class DebugTaskWithArgsCommand extends Command { - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); } async run(treeItem: GradleTaskTreeItem): Promise { diff --git a/extension/src/commands/RestartTaskCommand.ts b/extension/src/commands/RestartTaskCommand.ts index ff4814ee2..7b9a943c4 100644 --- a/extension/src/commands/RestartTaskCommand.ts +++ b/extension/src/commands/RestartTaskCommand.ts @@ -1,11 +1,11 @@ import { GradleTaskTreeItem } from "../views"; import { getTaskExecution, queueRestartTask } from "../tasks/taskUtil"; import { Command } from "./Command"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_RESTART_TASK = "gradle.restartTask"; export class RestartTaskCommand extends Command { - constructor(private client: GradleClient) { + constructor(private client: TaskServerClient) { super(); } async run(treeItem: GradleTaskTreeItem): Promise { diff --git a/extension/src/commands/RunBuildCommand.ts b/extension/src/commands/RunBuildCommand.ts index 1e7ae6a0b..672c86b94 100644 --- a/extension/src/commands/RunBuildCommand.ts +++ b/extension/src/commands/RunBuildCommand.ts @@ -5,11 +5,11 @@ import { GradleRunnerTerminal } from "../terminal"; import { getRunBuildCancellationKey } from "../client/CancellationKeys"; import { Command } from "./Command"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_RUN_BUILD = "gradle.runBuild"; export class RunBuildCommand extends Command { - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); } async run(): Promise { diff --git a/extension/src/commands/RunTaskCommand.ts b/extension/src/commands/RunTaskCommand.ts index 8e14fd7d7..fb0435b0c 100644 --- a/extension/src/commands/RunTaskCommand.ts +++ b/extension/src/commands/RunTaskCommand.ts @@ -2,20 +2,20 @@ import { GradleTaskTreeItem } from "../views"; import { runTask } from "../tasks/taskUtil"; import { Command } from "./Command"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { DoubleClickChecker } from "../util/DoubleClickChecker"; export const COMMAND_RUN_TASK = "gradle.runTask"; export const COMMAND_RUN_TASK_DOUBLE_CLICK = "gradle.runTaskDoubleClick"; -async function run(treeItem: GradleTaskTreeItem, rootProjectsStore: RootProjectsStore, client: GradleClient) { +async function run(treeItem: GradleTaskTreeItem, rootProjectsStore: RootProjectsStore, client: TaskServerClient) { if (treeItem && treeItem.task) { await runTask(rootProjectsStore, treeItem.task, client); } } export class RunTaskCommand extends Command { - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); } @@ -27,7 +27,7 @@ export class RunTaskCommand extends Command { export class RunTaskDoubleClickCommand extends Command { private doubleClickChecker: DoubleClickChecker; - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); this.doubleClickChecker = new DoubleClickChecker(); } diff --git a/extension/src/commands/RunTaskWithArgsCommand.ts b/extension/src/commands/RunTaskWithArgsCommand.ts index 0991352b3..7fa3274e3 100644 --- a/extension/src/commands/RunTaskWithArgsCommand.ts +++ b/extension/src/commands/RunTaskWithArgsCommand.ts @@ -3,11 +3,11 @@ import { runTaskWithArgs } from "../tasks/taskUtil"; import { logger } from "../logger"; import { Command } from "./Command"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export const COMMAND_RUN_TASK_WITH_ARGS = "gradle.runTaskWithArgs"; export class RunTaskWithArgsCommand extends Command { - constructor(private rootProjectsStore: RootProjectsStore, private client: GradleClient) { + constructor(private rootProjectsStore: RootProjectsStore, private client: TaskServerClient) { super(); } async run(treeItem: GradleTaskTreeItem): Promise { diff --git a/extension/src/createProject/types.ts b/extension/src/createProject/types.ts index 44eec269c..d15c35f72 100644 --- a/extension/src/createProject/types.ts +++ b/extension/src/createProject/types.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; export interface IProjectCreationMetadata { isAdvanced: boolean; @@ -14,7 +14,7 @@ export interface IProjectCreationMetadata { targetFolder: string; steps: IProjectCreationStep[]; nextStep?: IProjectCreationStep; - client: GradleClient; + client: TaskServerClient; } export interface IProjectCreationStep { diff --git a/extension/src/tasks/GradleTaskProvider.ts b/extension/src/tasks/GradleTaskProvider.ts index 257b2f482..3bd19b33d 100644 --- a/extension/src/tasks/GradleTaskProvider.ts +++ b/extension/src/tasks/GradleTaskProvider.ts @@ -4,7 +4,7 @@ import { logger } from "../logger"; import { loadTasksForProjectRoots, resolveTaskFromDefinition } from "./taskUtil"; import { TaskId } from "../stores/types"; import { RootProjectsStore } from "../stores"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { EventWaiter } from "../util/EventWaiter"; import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider"; @@ -16,7 +16,7 @@ export class GradleTaskProvider implements vscode.TaskProvider, vscode.Disposabl constructor( private readonly rootProjectsStore: RootProjectsStore, - private readonly client: GradleClient, + private readonly client: TaskServerClient, private readonly gradleBuildContentProvider: GradleBuildContentProvider ) {} diff --git a/extension/src/tasks/taskUtil.ts b/extension/src/tasks/taskUtil.ts index 0f484b3a0..f951394ab 100644 --- a/extension/src/tasks/taskUtil.ts +++ b/extension/src/tasks/taskUtil.ts @@ -17,7 +17,7 @@ import { getTaskArgs } from "../util/input"; import { COMMAND_RENDER_TASK } from "../commands"; import { RootProject } from "../rootProject/RootProject"; import { getRunTaskCommandCancellationKey } from "../client/CancellationKeys"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; import { RootProjectsStore } from "../stores"; import { getConfigIsAutoDetectionEnabled, getConfigReuseTerminals, getAllowParallelRun } from "../util/config"; import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider"; @@ -50,7 +50,11 @@ export function isTaskRunning(task: vscode.Task, args?: TaskArgs): boolean { return getTaskExecution(task, args) !== undefined; } -export async function cancelBuild(client: GradleClient, cancellationKey: string, task?: vscode.Task): Promise { +export async function cancelBuild( + client: TaskServerClient, + cancellationKey: string, + task?: vscode.Task +): Promise { if (task && isTaskRunning(task)) { cancellingTasks.set(task.definition.id, task); await vscode.commands.executeCommand(COMMAND_RENDER_TASK, task); @@ -102,7 +106,7 @@ export function removeCancellingTask(task: vscode.Task): void { } } -export async function queueRestartTask(client: GradleClient, task: vscode.Task): Promise { +export async function queueRestartTask(client: TaskServerClient, task: vscode.Task): Promise { if (isTaskRunning(task)) { const definition = task.definition as GradleTaskDefinition; restartingTasks.set(definition.id, task); @@ -124,7 +128,7 @@ export function buildTaskName(definition: GradleTaskDefinition): string { export function createTaskFromDefinition( definition: Required, rootProject: RootProject, - client: GradleClient, + client: TaskServerClient, useUniqueId = false ): vscode.Task { if (getAllowParallelRun() && useUniqueId) { @@ -167,7 +171,7 @@ export function createTaskFromDefinition( export function resolveTaskFromDefinition( definition: Required, workspaceFolder: vscode.WorkspaceFolder, - client: GradleClient + client: TaskServerClient ): vscode.Task | undefined { const taskName = buildTaskName(definition); const task = new vscode.Task( @@ -221,7 +225,7 @@ export function resolveTaskFromDefinition( function createVSCodeTaskFromGradleTask( gradleTask: GradleTask, rootProject: RootProject, - client: GradleClient, + client: TaskServerClient, args = "" ): vscode.Task { const taskPath = gradleTask.getPath(); @@ -248,7 +252,7 @@ function createVSCodeTaskFromGradleTask( export function getVSCodeTasksFromGradleProject( rootProject: RootProject, gradleProject: GradleProject, - client: GradleClient + client: TaskServerClient ): vscode.Task[] { let projects: Array = [gradleProject]; const vsCodeTasks: vscode.Task[] = []; @@ -265,7 +269,7 @@ export function getVSCodeTasksFromGradleProject( } export async function loadTasksForProjectRoots( - client: GradleClient, + client: TaskServerClient, rootProjects: ReadonlyArray, gradleBuildContentProvider: GradleBuildContentProvider ): Promise { @@ -307,7 +311,7 @@ export async function loadTasksForProjectRoots( export async function runTask( rootProjectsStore: RootProjectsStore, task: vscode.Task, - client: GradleClient, + client: TaskServerClient, args = "", debug = false ): Promise { @@ -350,7 +354,7 @@ export async function runTask( export async function runTaskWithArgs( rootProjectsStore: RootProjectsStore, task: vscode.Task, - client: GradleClient, + client: TaskServerClient, debug = false ): Promise { const args = await getTaskArgs(); @@ -365,7 +369,7 @@ export function cloneTask( rootProjectsStore: RootProjectsStore, task: vscode.Task, args: string, - client: GradleClient, + client: TaskServerClient, javaDebug = false, useUniqueId = false ): vscode.Task { diff --git a/extension/src/terminal/GradleRunnerTerminal.ts b/extension/src/terminal/GradleRunnerTerminal.ts index abeb9d02e..a77c0caa3 100644 --- a/extension/src/terminal/GradleRunnerTerminal.ts +++ b/extension/src/terminal/GradleRunnerTerminal.ts @@ -9,7 +9,7 @@ import { RootProject } from "../rootProject/RootProject"; import { isTaskRunning } from "../tasks/taskUtil"; import { COMMAND_CANCEL_BUILD } from "../commands"; import { GradleTaskDefinition } from "../tasks"; -import { GradleClient } from "../client"; +import { TaskServerClient } from "../client"; const NL = "\n"; const CR = "\r"; @@ -27,7 +27,7 @@ export class GradleRunnerTerminal implements vscode.Pseudoterminal { private readonly rootProject: RootProject, private readonly args: string[], private readonly cancellationKey: string, - private readonly client: GradleClient + private readonly client: TaskServerClient ) { if (isTest()) { // TODO: this is only needed for the tests. Find a better way to test task output in the tests. diff --git a/extension/src/views/defaultProject/DefaultProjectProvider.ts b/extension/src/views/defaultProject/DefaultProjectProvider.ts index 505e8f8cd..05d770cdf 100644 --- a/extension/src/views/defaultProject/DefaultProjectProvider.ts +++ b/extension/src/views/defaultProject/DefaultProjectProvider.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as vscode from "vscode"; -import { GradleClient } from "../../client"; +import { TaskServerClient } from "../../client"; import { isLanguageServerStarted } from "../../languageServer/languageServer"; import { RootProject } from "../../rootProject"; import { GradleTaskDefinition } from "../../tasks"; @@ -30,7 +30,7 @@ export class DefaultProjectProvider { this.defaultTasks = []; } - public async getDefaultTasks(rootProjects: RootProject[], client: GradleClient): Promise { + public async getDefaultTasks(rootProjects: RootProject[], client: TaskServerClient): Promise { if (this.defaultTasks.length) { return this.defaultTasks; } diff --git a/extension/src/views/defaultProject/DefaultProjectsTreeDataProvider.ts b/extension/src/views/defaultProject/DefaultProjectsTreeDataProvider.ts index 73dde7141..89b87af65 100644 --- a/extension/src/views/defaultProject/DefaultProjectsTreeDataProvider.ts +++ b/extension/src/views/defaultProject/DefaultProjectsTreeDataProvider.ts @@ -4,7 +4,7 @@ import * as vscode from "vscode"; import * as path from "path"; import { GradleTasksTreeDataProvider, GroupTreeItem, ProjectTreeItem } from ".."; -import { GradleClient } from "../../client"; +import { TaskServerClient } from "../../client"; import { RootProjectsStore } from "../../stores"; import { GradleTaskProvider } from "../../tasks"; import { DefaultProjectProvider } from "./DefaultProjectProvider"; @@ -18,7 +18,7 @@ export class DefaultProjectsTreeDataProvider implements vscode.TreeDataProvider< constructor( private readonly gradleTaskProvider: GradleTaskProvider, private readonly rootProjectStore: RootProjectsStore, - private readonly client: GradleClient, + private readonly client: TaskServerClient, private readonly icons: Icons ) { this.defaultProjectProvider = new DefaultProjectProvider(); diff --git a/extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts b/extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts index 882188c5f..b37f0a931 100644 --- a/extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts +++ b/extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts @@ -21,7 +21,7 @@ import { ProjectTaskTreeItem } from "./ProjectTaskTreeItem"; import { GradleDependencyProvider } from "../../dependencies/GradleDependencyProvider"; import { findRootProject } from "../../client/utils"; import { TaskArgs, TaskId } from "../../stores/types"; -import { GradleClient } from "../../client"; +import { TaskServerClient } from "../../client"; import { buildPinnedTaskTreeItem } from "./utils"; import { PinnedTasksTreeItem } from "./PinnedTasksTreeItem"; import { PinnedTasksRootProjectTreeItem } from "./PinnedTasksRootProjectTreeItem"; @@ -65,7 +65,7 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider = new Map(); @@ -65,7 +65,7 @@ export class RecentTasksTreeDataProvider implements vscode.TreeDataProvider this.refresh()); diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/DaemonStatus.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/DaemonStatus.java deleted file mode 100644 index 95803bddc..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/DaemonStatus.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.badsyntax.gradle; - -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; - -public class DaemonStatus { - private GradleExecution gradleExecution; - - // 56783 IDLE 6.4 - // 39762 STOPPED (other compatible daemons were started ...) - private static final Pattern STATUS_REGEX = Pattern.compile("^\\s+([0-9]+)\\s+([A-Z]+)\\s+([\\p{ASCII}]+)$"); - - public DaemonStatus(GradleExecution gradleExecution) { - this.gradleExecution = gradleExecution; - } - - public synchronized List get() throws GradleExecutionException { - ArrayList daemonStatus = new ArrayList<>(); - String processOutput = gradleExecution.exec("--status", "--quiet"); - Stream.of(processOutput.split("\n")).forEach(line -> { - Matcher statusMatcher = STATUS_REGEX.matcher(line); - if (statusMatcher.matches()) { - String pid = statusMatcher.group(1); - String status = statusMatcher.group(2); - String info = statusMatcher.group(3); - daemonStatus.add(DaemonInfo.newBuilder().setPid(pid).setInfo(info) - .setStatus(DaemonInfo.DaemonStatus.valueOf(status)).build()); - } - }); - return daemonStatus; - } -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleExecution.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleExecution.java deleted file mode 100644 index 6b32d9e51..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleExecution.java +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -package com.github.badsyntax.gradle; - -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; - -public interface GradleExecution { - public String exec(String... args) throws GradleExecutionException; -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleLocalInstallation.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleLocalInstallation.java deleted file mode 100644 index 4a307de58..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleLocalInstallation.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -package com.github.badsyntax.gradle; - -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; -import com.github.badsyntax.gradle.exceptions.ProcessException; -import com.github.badsyntax.gradle.process.Process; -import com.github.badsyntax.gradle.process.ProcessOutput; -import java.io.File; -import java.io.IOException; -import java.util.stream.Collectors; - -public class GradleLocalInstallation implements GradleExecution { - private File localInstallation; - private static final String GRADLE_EXECUTION_UNIX = "gradle"; - private static final String GRADLE_EXECUTION_WINDOWS = "gradle.bat"; - - public GradleLocalInstallation(File localInstallation) { - this.localInstallation = localInstallation; - } - - public synchronized String exec(String... args) throws GradleExecutionException { - try { - if (args.length == 0) { - throw new GradleExecutionException("No gradle args supplied"); - } - File binFolder = localInstallation.toPath().resolve("bin").toFile(); - Process process = new Process(binFolder); - process.setUnixCommand(GRADLE_EXECUTION_UNIX); - process.setWindowsCommand(GRADLE_EXECUTION_WINDOWS); - process.exec(args); - ProcessOutput processOutput = process.getProcessOutput(); - String stdErrString = processOutput.getStdErr().lines().collect(Collectors.joining("\n")); - String stdOutString = processOutput.getStdOut().lines().collect(Collectors.joining("\n")); - process.close(); - if (stdErrString.length() > 0) { - throw new GradleExecutionException(String.format("Error running gradle: %s", stdErrString)); - } - return stdOutString; - } catch (IOException | ProcessException e) { - throw new GradleExecutionException(String.format("Error running gradle: %s", e.getMessage())); - } - } -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleWrapper.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleWrapper.java deleted file mode 100644 index df64a491a..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/GradleWrapper.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.badsyntax.gradle; - -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; -import com.github.badsyntax.gradle.exceptions.ProcessException; -import com.github.badsyntax.gradle.process.Process; -import com.github.badsyntax.gradle.process.ProcessOutput; -import com.github.badsyntax.gradle.utils.Utils; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.stream.Collectors; - -public class GradleWrapper implements GradleExecution { - private File projectRoot; - private static final String GRADLE_WRAPPER_UNIX = "gradlew"; - private static final String GRADLE_WRAPPER_WINDOWS = "gradlew.bat"; - private static final Path GRADLE_WRAPPER_PROPERTIES_PATH = Paths.get("gradle", "wrapper", - "gradle-wrapper.properties"); - - public GradleWrapper(File projectRoot) { - this.projectRoot = projectRoot; - } - - public synchronized String exec(String... args) throws GradleExecutionException { - try { - if (args.length == 0) { - throw new GradleExecutionException("No wrapper args supplied"); - } - Process process = new Process(projectRoot); - process.setUnixCommand(GRADLE_WRAPPER_UNIX); - process.setWindowsCommand(GRADLE_WRAPPER_WINDOWS); - process.exec(args); - ProcessOutput processOutput = process.getProcessOutput(); - String stdErrString = processOutput.getStdErr().lines().collect(Collectors.joining("\n")); - String stdOutString = processOutput.getStdOut().lines().collect(Collectors.joining("\n")); - process.close(); - if (stdErrString.length() > 0) { - throw new GradleExecutionException(String.format("Error running gradle wrapper: %s", stdErrString)); - } - return stdOutString; - } catch (IOException | ProcessException e) { - throw new GradleExecutionException(String.format("Error running gradle wrapper: %s", e.getMessage())); - } - } - - public static boolean hasValidWrapper(File projectRoot) { - if (!Utils.isValidFile(projectRoot)) { - return false; - } - File propertiesFile = projectRoot.toPath().resolve(GRADLE_WRAPPER_PROPERTIES_PATH).toFile(); - boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win"); - File wrapperFile = isWindows - ? projectRoot.toPath().resolve(GRADLE_WRAPPER_WINDOWS).toFile() - : projectRoot.toPath().resolve(GRADLE_WRAPPER_UNIX).toFile(); - return Utils.isValidFile(propertiesFile) && Utils.isValidFile(wrapperFile); - } -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/TaskService.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/TaskService.java index 135be3e14..7bd01beae 100644 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/TaskService.java +++ b/gradle-server/src/main/java/com/github/badsyntax/gradle/TaskService.java @@ -4,10 +4,7 @@ import com.github.badsyntax.gradle.handlers.CancelBuildsHandler; import com.github.badsyntax.gradle.handlers.ExecuteCommandHandler; import com.github.badsyntax.gradle.handlers.GetBuildHandler; -import com.github.badsyntax.gradle.handlers.GetDaemonsStatusHandler; import com.github.badsyntax.gradle.handlers.RunBuildHandler; -import com.github.badsyntax.gradle.handlers.StopDaemonHandler; -import com.github.badsyntax.gradle.handlers.StopDaemonsHandler; import io.grpc.stub.StreamObserver; public class TaskService extends GradleGrpc.GradleImplBase { @@ -36,24 +33,6 @@ public void cancelBuilds(CancelBuildsRequest req, StreamObserver responseObserver) { - GetDaemonsStatusHandler getDaemonsStatusHandler = new GetDaemonsStatusHandler(req, responseObserver); - getDaemonsStatusHandler.run(); - } - - @Override - public void stopDaemons(StopDaemonsRequest req, StreamObserver responseObserver) { - StopDaemonsHandler stopDaemonsHandler = new StopDaemonsHandler(req, responseObserver); - stopDaemonsHandler.run(); - } - - @Override - public void stopDaemon(StopDaemonRequest req, StreamObserver responseObserver) { - StopDaemonHandler stopDaemonHandler = new StopDaemonHandler(req, responseObserver); - stopDaemonHandler.run(); - } - @Override public void executeCommand(ExecuteCommandRequest req, StreamObserver responseObserver) { ExecuteCommandHandler executeCommandHandler = new ExecuteCommandHandler(req, responseObserver); diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/GetDaemonsStatusHandler.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/GetDaemonsStatusHandler.java deleted file mode 100644 index 946cf31a3..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/GetDaemonsStatusHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.github.badsyntax.gradle.handlers; - -import com.github.badsyntax.gradle.DaemonInfo; -import com.github.badsyntax.gradle.DaemonStatus; -import com.github.badsyntax.gradle.ErrorMessageBuilder; -import com.github.badsyntax.gradle.GetDaemonsStatusReply; -import com.github.badsyntax.gradle.GetDaemonsStatusRequest; -import com.github.badsyntax.gradle.GradleLocalInstallation; -import com.github.badsyntax.gradle.GradleProjectConnectionType; -import com.github.badsyntax.gradle.GradleProjectConnector; -import com.github.badsyntax.gradle.GradleWrapper; -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; -import io.grpc.stub.StreamObserver; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GetDaemonsStatusHandler { - private static final Logger logger = LoggerFactory.getLogger(GetDaemonsStatusHandler.class.getName()); - - private GetDaemonsStatusRequest req; - private StreamObserver responseObserver; - - public GetDaemonsStatusHandler(GetDaemonsStatusRequest req, - StreamObserver responseObserver) { - this.req = req; - this.responseObserver = responseObserver; - } - - public synchronized void run() { - DaemonStatus daemonStatus = null; - GradleProjectConnectionType connectionType = GradleProjectConnector.getConnectionType(); - if (connectionType == GradleProjectConnectionType.WRAPPER) { - File projectRoot = new File(req.getProjectDir()); - // get daemon status needs to use wrapper execution - // when java.import.gradle.wrapper.enabled is set to true - if (!GradleWrapper.hasValidWrapper(projectRoot)) { - replyWithSuccess(new ArrayList<>()); - return; - } - GradleWrapper gradleWrapper = new GradleWrapper(projectRoot); - daemonStatus = new DaemonStatus(gradleWrapper); - } else if (connectionType == GradleProjectConnectionType.LOCALINSTALLATION) { - String localInstallation = GradleProjectConnector.getLocalInstallation(); - GradleLocalInstallation gradleLocalInstallation = new GradleLocalInstallation(new File(localInstallation)); - daemonStatus = new DaemonStatus(gradleLocalInstallation); - } else if (connectionType == GradleProjectConnectionType.SPECIFICVERSION) { - // Currently we can't find a way to get daemon status of specific version - // We can neither get the executable path of this case, so return an empty list - // to indicate - replyWithSuccess(new ArrayList<>()); - return; - } - if (daemonStatus == null) { - replyWithError(new Exception("Get daemon status failed. Please check your Gradle Settings.")); - return; - } - try { - List status = daemonStatus.get(); - replyWithSuccess(status); - } catch (GradleExecutionException e) { - logger.error(e.getMessage()); - replyWithError(e); - } - } - - public void replyWithError(Exception e) { - responseObserver.onError(ErrorMessageBuilder.build(e)); - } - - public void replyWithSuccess(List status) { - responseObserver.onNext(GetDaemonsStatusReply.newBuilder().addAllDaemonInfo(status).build()); - responseObserver.onCompleted(); - } -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonHandler.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonHandler.java deleted file mode 100644 index 399c5b7d8..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.badsyntax.gradle.handlers; - -import com.github.badsyntax.gradle.ErrorMessageBuilder; -import com.github.badsyntax.gradle.StopDaemonReply; -import com.github.badsyntax.gradle.StopDaemonRequest; -import com.github.badsyntax.gradle.process.Process; -import io.grpc.stub.StreamObserver; -import java.io.IOException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class StopDaemonHandler { - private static final Logger logger = LoggerFactory.getLogger(StopDaemonHandler.class.getName()); - - private StopDaemonRequest req; - private StreamObserver responseObserver; - - public StopDaemonHandler(StopDaemonRequest req, StreamObserver responseObserver) { - this.req = req; - this.responseObserver = responseObserver; - } - - public void run() { - try { - Process.kill(req.getPid()); - replyWithSuccess(String.format("Killed daemon with PID %s", req.getPid())); - } catch (IOException e) { - logger.error(e.getMessage()); - replyWithError(e); - } - } - - private void replyWithError(Exception e) { - responseObserver.onError(ErrorMessageBuilder.build(e)); - } - - private void replyWithSuccess(String message) { - responseObserver.onNext(StopDaemonReply.newBuilder().setMessage(message).build()); - responseObserver.onCompleted(); - } -} diff --git a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonsHandler.java b/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonsHandler.java deleted file mode 100644 index 8c94bd140..000000000 --- a/gradle-server/src/main/java/com/github/badsyntax/gradle/handlers/StopDaemonsHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.badsyntax.gradle.handlers; - -import com.github.badsyntax.gradle.ErrorMessageBuilder; -import com.github.badsyntax.gradle.GradleExecution; -import com.github.badsyntax.gradle.GradleLocalInstallation; -import com.github.badsyntax.gradle.GradleProjectConnectionType; -import com.github.badsyntax.gradle.GradleProjectConnector; -import com.github.badsyntax.gradle.GradleWrapper; -import com.github.badsyntax.gradle.StopDaemonsReply; -import com.github.badsyntax.gradle.StopDaemonsRequest; -import com.github.badsyntax.gradle.exceptions.GradleExecutionException; -import io.grpc.stub.StreamObserver; -import java.io.File; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class StopDaemonsHandler { - private static final Logger logger = LoggerFactory.getLogger(StopDaemonsHandler.class.getName()); - - private StopDaemonsRequest req; - private StreamObserver responseObserver; - - public StopDaemonsHandler(StopDaemonsRequest req, StreamObserver responseObserver) { - this.req = req; - this.responseObserver = responseObserver; - } - - public void run() { - File projectRoot = new File(req.getProjectDir()); - try { - GradleExecution gradleExecution = null; - GradleProjectConnectionType connectionType = GradleProjectConnector.getConnectionType(); - if (connectionType == GradleProjectConnectionType.WRAPPER) { - if (!GradleWrapper.hasValidWrapper(projectRoot)) { - // When java.import.gradle.wrapper.enabled is set to true but no wrapper - // properties file - // is found, - // We'll show no daemon status, so stopping a daemon in this case is not - // supported. - replyWithError(new Exception("Unsupported operation.")); - return; - } - gradleExecution = new GradleWrapper(projectRoot); - } else if (connectionType == GradleProjectConnectionType.LOCALINSTALLATION) { - String localInstallation = GradleProjectConnector.getLocalInstallation(); - gradleExecution = new GradleLocalInstallation(new File(localInstallation)); - } else if (connectionType == GradleProjectConnectionType.SPECIFICVERSION) { - // We disabled stop all daemons in the client when specifies a gradle version - // So here will not be reached - replyWithError(new Exception("Unsupported operation.")); - return; - } - if (gradleExecution == null) { - replyWithError(new Exception("Stop daemons failed. Please check your Gradle Settings.")); - return; - } - String stopOutput = gradleExecution.exec("--stop"); - replyWithSuccess(stopOutput); - responseObserver.onCompleted(); - } catch (GradleExecutionException e) { - logger.error(e.getMessage()); - replyWithError(e); - } - } - - private void replyWithError(Exception e) { - responseObserver.onError(ErrorMessageBuilder.build(e)); - } - - private void replyWithSuccess(String message) { - responseObserver.onNext(StopDaemonsReply.newBuilder().setMessage(message).build()); - } -}