Skip to content

Commit

Permalink
Merge pull request #510 from badsyntax/run-anything
Browse files Browse the repository at this point in the history
Add feature to run any gradle build
  • Loading branch information
badsyntax authored Jun 18, 2020
2 parents e2376e8 + 47769c6 commit 15149eb
Show file tree
Hide file tree
Showing 52 changed files with 953 additions and 888 deletions.
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The extension models the project hierarchical structure using the vscode treeVie

Gradle tasks can be run through either the [treeView](https://code.visualstudio.com/api/extension-guides/tree-view) or the Command Palette.

The tasks use the gRPC client to call the `runTask` server method. Similar to getting project data, Gradle progress and output (`STDERR` & `STDOUT`) is streamed to the client. Tasks are run in a custom vscode terminal.
Tasks are run via the `runBuild` gRPC method. Similar to getting project data, Gradle progress and output (`STDERR` & `STDOUT`) is streamed to the client. Tasks are run in a custom vscode terminal. The `runBuild` gRPC method accepts a list of arguments which are passed to the `BuildLauncher`.

## The Build System

Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ When you expand a project, tasks are listed in a tree, grouped by the task group
</details>
<details><summary>Run tasks</summary>

Tasks can be run via the `Gradle Tasks`, `Pinned Tasks` or `Recent Tasks` treeviews, or as vscode tasks via `Command Palette => Run Task`.
Tasks can be run via:

- `Gradle Tasks`, `Pinned Tasks` or `Recent Tasks` treeviews
- `Run Task` command
- `Run a Gradle Build` command

A running task will be shown with an animated "spinner" icon in the treeviews, along with `Cancel Task` & `Restart Task` buttons. The `Cancel Task` button will gracefully cancel the task. The `Restart Task` button will first cancel the task, then restart it.

Expand All @@ -45,6 +49,10 @@ Send a SIGINT signal (ctrl/cmd + c) in the terminal to gracefully cancel it.

<img src="./images/task-output.png" width="650" alt="Gradle Tasks Output" />

Tasks run via the `Run a Gradle Build` command are not reflected in any of the treeviews. Use this command to specify your own Gradle build arguments, for example to run multiple tasks or to exclude tasks.

<img src="./images/run-build.png" width="650" alt="Run Gradle Build" />

</details>
<details><summary>Debug JavaExec tasks</summary>

Expand Down Expand Up @@ -135,7 +143,7 @@ This extension contributes the following settings:

- `gradle.autoDetect`: Automatically detect Gradle tasks
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task
- `gradle.nestedProjects`: Support nested projects (boolean or an array of directories)
- `gradle.nestedProjects`: Process nested projects (boolean or an array of directories)
- `gradle.javaDebug`: Debug JavaExec tasks (see below for usage)
- `gradle.debug`: Show extra debug info in the output panel
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc)
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ allprojects {
subprojects {
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.diffplug.gradle.spotless'

repositories {
maven {
Expand Down
20 changes: 14 additions & 6 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
"dark": "resources/dark/run.svg"
}
},
{
"command": "gradle.runBuild",
"title": "Run a Gradle Build",
"icon": {
"light": "resources/light/console.svg",
"dark": "resources/dark/console.svg"
}
},
{
"command": "gradle.pinTask",
"title": "Pin Task"
Expand Down Expand Up @@ -186,7 +194,7 @@
"title": "Open Task Build File"
},
{
"command": "gradle.cancelTask",
"command": "gradle.cancelBuild",
"title": "Cancel Task"
},
{
Expand Down Expand Up @@ -221,10 +229,6 @@
"dark": "resources/dark/list-tree.svg"
}
},
{
"command": "gradle.killGradleProcess",
"title": "Kill Gradle task process"
},
{
"command": "gradle.showProcessMessage",
"title": "Show Gradle process information message box"
Expand Down Expand Up @@ -341,7 +345,7 @@
"when": "false"
},
{
"command": "gradle.cancelTask",
"command": "gradle.cancelBuild",
"when": "false"
},
{
Expand Down Expand Up @@ -402,6 +406,10 @@
},
{
"command": "gradle.openSettings",
"when": "view == gradleTasksView"
},
{
"command": "gradle.runBuild",
"when": "view == gradleTasksView",
"group": "navigation@0"
},
Expand Down
21 changes: 17 additions & 4 deletions extension/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from '../logger';
import { GradleTasksTreeDataProvider } from '../views';
import { GradleTaskDefinition } from '../tasks';
import { GradleClient } from '../client';
import { getRunTaskCommandCancellationKey } from '../client/CancellationKeys';

export interface RunTaskOpts {
projectFolder: string;
Expand All @@ -30,20 +31,32 @@ export class Api {

public async runTask(opts: RunTaskOpts): Promise<void> {
const task = await this.findTask(opts.projectFolder, opts.taskName);
return this.client.runTask(
const buildArgs = [task.definition.script]
.concat(opts.args)
.filter(Boolean);
const cancellationKey = getRunTaskCommandCancellationKey(
opts.projectFolder,
task,
opts.args,
opts.taskName
);
return this.client.runBuild(
opts.projectFolder,
cancellationKey,
buildArgs,
opts.input,
0,
task,
opts.onOutput,
opts.showOutputColors
);
}

public async cancelRunTask(opts: CancelTaskOpts): Promise<void> {
const task = await this.findTask(opts.projectFolder, opts.taskName);
return this.client.cancelRunTask(task);
const cancellationKey = getRunTaskCommandCancellationKey(
opts.projectFolder,
opts.taskName
);
return this.client.cancelBuild(cancellationKey, task);
}

private async findTask(
Expand Down
17 changes: 17 additions & 0 deletions extension/src/client/CancellationKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function getBuildCancellationKey(rootProjectFolder: string): string {
return 'getBuild' + rootProjectFolder;
}

export function getRunBuildCancellationKey(
rootProjectFolder: string,
args: ReadonlyArray<string>
): string {
return 'runBuild' + rootProjectFolder + args.join('');
}

export function getRunTaskCommandCancellationKey(
rootProjectFolder: string,
taskName: string
): string {
return 'runTask' + rootProjectFolder + taskName;
}
Loading

0 comments on commit 15149eb

Please sign in to comment.