Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Move Gradle Daemons implementation from Java into Typescript #1489

Merged
merged 25 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
343a6b7
merge
Jiaaming Apr 29, 2024
c78ddd4
Merge branch 'develop' of https://github.com/Jiaaming/vscode-gradle i…
Jiaaming Apr 29, 2024
18cb0de
Merge branch 'develop' of https://github.com/Jiaaming/vscode-gradle i…
Jiaaming May 11, 2024
8b48ce5
init new daemon ts class
Jiaaming May 13, 2024
9db21b5
finished basic getGradleStatus demo
Jiaaming May 13, 2024
a98d3b7
add wrapper & local installation get gradle status
Jiaaming May 13, 2024
f9060ec
finish stop daemon task in typescript
Jiaaming May 13, 2024
f597275
finish stop all daemons in typescript
Jiaaming May 14, 2024
2530ae6
format code lint
Jiaaming May 14, 2024
f48ba66
Merge branch 'develop' into revert-gd
Jiaaming May 14, 2024
ccbe159
lint and format
Jiaaming May 14, 2024
79d3e7b
format code lint
Jiaaming May 14, 2024
d12592d
add gradle daemon test and fix minors
Jiaaming May 14, 2024
de30aff
fix import bugs
Jiaaming May 14, 2024
64af954
fix test case
Jiaaming May 16, 2024
9a49ad6
fix minor bugs
Jiaaming May 16, 2024
63b2679
fix minors
Jiaaming May 16, 2024
a99a188
finish basic test cases for gradle daemons
Jiaaming May 16, 2024
905f81b
update gradle daemons & test cases
Jiaaming May 16, 2024
22e84c7
update gradle daemons & test cases
Jiaaming May 16, 2024
2337a96
update task server impl
Jiaaming May 20, 2024
4fcf41f
fix import error
Jiaaming May 20, 2024
88b645b
fix lint
Jiaaming May 20, 2024
7c7a9bb
fix daemon status bugs and add test
Jiaaming May 21, 2024
6e36030
fix daemon status bugs and add test
Jiaaming May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ export class Extension {
treeDataProvider: this.gradleTasksTreeDataProvider,
showCollapseAll: true,
});
this.gradleDaemonsTreeDataProvider = new GradleDaemonsTreeDataProvider(
this.context,
this.rootProjectsStore,
this.client
);
this.gradleDaemonsTreeDataProvider = new GradleDaemonsTreeDataProvider(this.context, this.rootProjectsStore);
this.gradleDaemonsTreeView = vscode.window.createTreeView(GRADLE_DAEMONS_VIEW, {
treeDataProvider: this.gradleDaemonsTreeDataProvider,
showCollapseAll: false,
Expand Down
4 changes: 2 additions & 2 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export class Commands {
COMMAND_REFRESH_DAEMON_STATUS,
new RefreshDaemonStatusCommand(this.gradleDaemonsTreeDataProvider)
);
this.registerCommand(COMMAND_STOP_DAEMONS, new StopDaemonsCommand(this.client, this.rootProjectsStore));
this.registerCommand(COMMAND_STOP_DAEMON, new StopDaemonCommand(this.client));
this.registerCommand(COMMAND_STOP_DAEMONS, new StopDaemonsCommand(this.rootProjectsStore));
this.registerCommand(COMMAND_STOP_DAEMON, new StopDaemonCommand());
this.registerCommand(COMMAND_EXPLORER_TREE, new ExplorerTreeCommand(this.gradleTasksTreeDataProvider));
this.registerCommand(COMMAND_EXPLORER_FLAT, new ExplorerFlatCommand(this.gradleTasksTreeDataProvider));
this.registerCommand(COMMAND_OPEN_SETTINGS, new OpenSettingsCommand());
Expand Down
24 changes: 19 additions & 5 deletions extension/src/commands/StopDaemonCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@ import { GradleDaemonTreeItem } from "../views";
import { confirmModal } from "../util/input";
import { logger } from "../logger";
import { Command } from "./Command";
import { GradleClient } from "../client";
import { execAsync } from "../util/execAsync";
import * as vscode from "vscode";
import { COMMAND_REFRESH_DAEMON_STATUS } from "./RefreshDaemonStatusCommand";

export const COMMAND_STOP_DAEMON = "gradle.stopDaemon";

export class StopDaemonCommand extends Command {
constructor(private client: GradleClient) {
constructor() {
super();
}
async run(treeItem: GradleDaemonTreeItem): Promise<void> {
if (!(await confirmModal("Are you sure you want to stop the daemon?"))) {
return;
}
const pid = treeItem.pid;
const stopDaemonReply = await this.client.stopDaemon(pid);
if (stopDaemonReply) {
logger.info(stopDaemonReply.getMessage());
try {
await this.stopDaemon(pid);
logger.info(`Successfully stopped daemon with PID ${pid}.`);
} catch (error) {
logger.error(`Failed to stop daemon with PID ${pid}: ${error.message}.`);
}
}

async stopDaemon(pid: string): Promise<void> {
if (!pid) {
throw new Error("PID is required to stop the daemon.");
}

const command = process.platform === "win32" ? `taskkill /PID ${pid} /F` : `kill ${pid}`;
await execAsync(command);
await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS);
}
}
44 changes: 32 additions & 12 deletions extension/src/commands/StopDaemonsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as vscode from "vscode";
import { confirmModal } from "../util/input";
import { StopDaemonsReply } from "../proto/gradle_pb";
import { logger } from "../logger";
import { Command } from "./Command";
import { RootProjectsStore } from "../stores";
import { GradleClient } from "../client";
import { getGradleConfig } from "../util/config";
import { GradleStatus } from "../views/gradleDaemons/services/GradleStatus";
import { GradleConnectionType } from "../views/gradleDaemons/models/GradleConnectionType";
import { GradleWrapper } from "../views/gradleDaemons/services/GradleWrapper";
import { GradleLocalInstallation } from "../views/gradleDaemons/services/GradleLocalInstallation";
import { COMMAND_REFRESH_DAEMON_STATUS } from "./RefreshDaemonStatusCommand";

export const COMMAND_STOP_DAEMONS = "gradle.stopDaemons";

export class StopDaemonsCommand extends Command {
constructor(private client: GradleClient, private rootProjectsStore: RootProjectsStore) {
constructor(private rootProjectsStore: RootProjectsStore) {
super();
}
async run(): Promise<void> {
Expand All @@ -20,14 +25,29 @@ export class StopDaemonsCommand extends Command {
return;
}
const gradleRootFolders = await this.rootProjectsStore.getProjectRootsWithUniqueVersions();
const promises: Promise<StopDaemonsReply | void>[] = gradleRootFolders.map((rootProject) =>
this.client.stopDaemons(rootProject.getProjectUri().fsPath)
);
const replies = await Promise.all(promises);
replies.forEach((reply) => {
if (reply) {
logger.info(reply.getMessage());
}
});
try {
const promises: Promise<void>[] = gradleRootFolders.map((rootProject) =>
this.stopDaemons(rootProject.getProjectUri().fsPath)
);
await Promise.all(promises);
logger.info(`Successfully stopped all daemons.`);
await vscode.commands.executeCommand(COMMAND_REFRESH_DAEMON_STATUS);
} catch (error) {
logger.error(`Failed to stop daemons: ${error.message}.`);
}
}

async stopDaemons(projectFolder: string): Promise<void> {
const gradleConfig = getGradleConfig();
const connectType = await GradleStatus.getConnectionType(gradleConfig);
if (connectType === GradleConnectionType.WRAPPER) {
const gradleExecution = new GradleWrapper(projectFolder);
await gradleExecution.exec(["--stop"]);
} else if (connectType === GradleConnectionType.LOCALINSTALLATION) {
const gradleExecution = new GradleLocalInstallation(gradleConfig.getGradleHome());
await gradleExecution.exec(["--stop"]);
} else {
logger.info("No daemons to stop.");
}
}
}
Loading
Loading