Skip to content

Commit 15149eb

Browse files
authored
Merge pull request #510 from badsyntax/run-anything
Add feature to run any gradle build
2 parents e2376e8 + 47769c6 commit 15149eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+953
-888
lines changed

ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The extension models the project hierarchical structure using the vscode treeVie
2626

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

29-
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.
29+
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`.
3030

3131
## The Build System
3232

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ When you expand a project, tasks are listed in a tree, grouped by the task group
3333
</details>
3434
<details><summary>Run tasks</summary>
3535

36-
Tasks can be run via the `Gradle Tasks`, `Pinned Tasks` or `Recent Tasks` treeviews, or as vscode tasks via `Command Palette => Run Task`.
36+
Tasks can be run via:
37+
38+
- `Gradle Tasks`, `Pinned Tasks` or `Recent Tasks` treeviews
39+
- `Run Task` command
40+
- `Run a Gradle Build` command
3741

3842
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.
3943

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

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

52+
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.
53+
54+
<img src="./images/run-build.png" width="650" alt="Run Gradle Build" />
55+
4856
</details>
4957
<details><summary>Debug JavaExec tasks</summary>
5058

@@ -135,7 +143,7 @@ This extension contributes the following settings:
135143

136144
- `gradle.autoDetect`: Automatically detect Gradle tasks
137145
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task
138-
- `gradle.nestedProjects`: Support nested projects (boolean or an array of directories)
146+
- `gradle.nestedProjects`: Process nested projects (boolean or an array of directories)
139147
- `gradle.javaDebug`: Debug JavaExec tasks (see below for usage)
140148
- `gradle.debug`: Show extra debug info in the output panel
141149
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc)

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ allprojects {
2828
subprojects {
2929
apply plugin: 'java'
3030
apply plugin: 'com.google.protobuf'
31+
apply plugin: 'com.diffplug.gradle.spotless'
3132

3233
repositories {
3334
maven {

extension/package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@
9393
"dark": "resources/dark/run.svg"
9494
}
9595
},
96+
{
97+
"command": "gradle.runBuild",
98+
"title": "Run a Gradle Build",
99+
"icon": {
100+
"light": "resources/light/console.svg",
101+
"dark": "resources/dark/console.svg"
102+
}
103+
},
96104
{
97105
"command": "gradle.pinTask",
98106
"title": "Pin Task"
@@ -186,7 +194,7 @@
186194
"title": "Open Task Build File"
187195
},
188196
{
189-
"command": "gradle.cancelTask",
197+
"command": "gradle.cancelBuild",
190198
"title": "Cancel Task"
191199
},
192200
{
@@ -221,10 +229,6 @@
221229
"dark": "resources/dark/list-tree.svg"
222230
}
223231
},
224-
{
225-
"command": "gradle.killGradleProcess",
226-
"title": "Kill Gradle task process"
227-
},
228232
{
229233
"command": "gradle.showProcessMessage",
230234
"title": "Show Gradle process information message box"
@@ -341,7 +345,7 @@
341345
"when": "false"
342346
},
343347
{
344-
"command": "gradle.cancelTask",
348+
"command": "gradle.cancelBuild",
345349
"when": "false"
346350
},
347351
{
@@ -402,6 +406,10 @@
402406
},
403407
{
404408
"command": "gradle.openSettings",
409+
"when": "view == gradleTasksView"
410+
},
411+
{
412+
"command": "gradle.runBuild",
405413
"when": "view == gradleTasksView",
406414
"group": "navigation@0"
407415
},

extension/src/api/Api.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { logger } from '../logger';
44
import { GradleTasksTreeDataProvider } from '../views';
55
import { GradleTaskDefinition } from '../tasks';
66
import { GradleClient } from '../client';
7+
import { getRunTaskCommandCancellationKey } from '../client/CancellationKeys';
78

89
export interface RunTaskOpts {
910
projectFolder: string;
@@ -30,20 +31,32 @@ export class Api {
3031

3132
public async runTask(opts: RunTaskOpts): Promise<void> {
3233
const task = await this.findTask(opts.projectFolder, opts.taskName);
33-
return this.client.runTask(
34+
const buildArgs = [task.definition.script]
35+
.concat(opts.args)
36+
.filter(Boolean);
37+
const cancellationKey = getRunTaskCommandCancellationKey(
3438
opts.projectFolder,
35-
task,
36-
opts.args,
39+
opts.taskName
40+
);
41+
return this.client.runBuild(
42+
opts.projectFolder,
43+
cancellationKey,
44+
buildArgs,
3745
opts.input,
3846
0,
47+
task,
3948
opts.onOutput,
4049
opts.showOutputColors
4150
);
4251
}
4352

4453
public async cancelRunTask(opts: CancelTaskOpts): Promise<void> {
4554
const task = await this.findTask(opts.projectFolder, opts.taskName);
46-
return this.client.cancelRunTask(task);
55+
const cancellationKey = getRunTaskCommandCancellationKey(
56+
opts.projectFolder,
57+
opts.taskName
58+
);
59+
return this.client.cancelBuild(cancellationKey, task);
4760
}
4861

4962
private async findTask(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function getBuildCancellationKey(rootProjectFolder: string): string {
2+
return 'getBuild' + rootProjectFolder;
3+
}
4+
5+
export function getRunBuildCancellationKey(
6+
rootProjectFolder: string,
7+
args: ReadonlyArray<string>
8+
): string {
9+
return 'runBuild' + rootProjectFolder + args.join('');
10+
}
11+
12+
export function getRunTaskCommandCancellationKey(
13+
rootProjectFolder: string,
14+
taskName: string
15+
): string {
16+
return 'runTask' + rootProjectFolder + taskName;
17+
}

0 commit comments

Comments
 (0)