-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Show Gradle commands in Project Manager's submenu (#1252)
- Loading branch information
Showing
7 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
import * as vscode from "vscode"; | ||
import * as path from "path"; | ||
import * as fse from "fs-extra"; | ||
import { GradleTaskTreeItem } from "../views"; | ||
import { Command } from "./Command"; | ||
import { GRADLE_BUILD_FILE_NAMES } from "../constant"; | ||
|
||
export const COMMAND_OPEN_BUILD_FILE = "gradle.openBuildFile"; | ||
|
||
async function run(taskItem: GradleTaskTreeItem): Promise<void> { | ||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(taskItem.task.definition.buildFile)); | ||
async function run(path: string): Promise<void> { | ||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(path)); | ||
} | ||
|
||
export class OpenBuildFileCommand extends Command { | ||
async run(taskItem: GradleTaskTreeItem): Promise<void> { | ||
return run(taskItem); | ||
async run(item: GradleTaskTreeItem | { uri: string }): Promise<void> { | ||
if (item instanceof GradleTaskTreeItem) { | ||
return run(item.task.definition.buildFile); | ||
} else if (item.uri) { | ||
const buildFilePath = await ensureBuildFilePath(item.uri); | ||
if (buildFilePath) { | ||
return run(buildFilePath); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export async function ensureBuildFilePath(projectUri: string): Promise<string | undefined> { | ||
const projectFsPath = vscode.Uri.parse(projectUri).fsPath; | ||
for (const buildFileName of GRADLE_BUILD_FILE_NAMES) { | ||
const buildFilePath: string = path.join(projectFsPath, buildFileName); | ||
if (await fse.pathExists(buildFilePath)) { | ||
return buildFilePath; | ||
} | ||
} | ||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as vscode from "vscode"; | ||
import { GradleTaskProvider } from "../tasks"; | ||
import { getRunTasks } from "../util/input"; | ||
import { Command } from "./Command"; | ||
|
||
export const COMMAND_RUN_TASKS = "gradle.runTasks"; | ||
|
||
export class RunTasksCommand extends Command { | ||
constructor(private readonly gradleTaskProvider: GradleTaskProvider) { | ||
super(); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
async run(item?: any): Promise<void> { | ||
if (item?.uri) { | ||
const foundTaskName = await getRunTasks(this.gradleTaskProvider, item.uri); | ||
if (foundTaskName) { | ||
const vscodeTask = this.gradleTaskProvider.getTasks().find((task) => task.name === foundTaskName); | ||
if (vscodeTask) { | ||
await vscode.tasks.executeTask(vscodeTask); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters