Skip to content

Commit 2c0f943

Browse files
authored
Merge pull request #701 from badsyntax/run-build-api
Expose runBuild public API
2 parents 340e86a + c5a8206 commit 2c0f943

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

extension/src/api/Api.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ 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';
7+
import {
8+
getRunBuildCancellationKey,
9+
getRunTaskCommandCancellationKey,
10+
} from '../client/CancellationKeys';
811

912
export interface RunTaskOpts {
1013
projectFolder: string;
@@ -15,6 +18,14 @@ export interface RunTaskOpts {
1518
showOutputColors: boolean;
1619
}
1720

21+
export interface RunBuildOpts {
22+
projectFolder: string;
23+
args: ReadonlyArray<string>;
24+
input?: string;
25+
onOutput?: (output: Output) => void;
26+
showOutputColors: boolean;
27+
}
28+
1829
export interface CancelTaskOpts {
1930
projectFolder: string;
2031
taskName: string;
@@ -30,19 +41,25 @@ export class Api {
3041
) {}
3142

3243
public async runTask(opts: RunTaskOpts): Promise<void> {
44+
const taskArgs = (opts.args || []).filter(Boolean);
3345
const task = await this.findTask(opts.projectFolder, opts.taskName);
34-
const definition = task.definition as GradleTaskDefinition;
35-
const buildArgs = [definition.script]
36-
.concat(opts.args || [])
37-
.filter(Boolean);
38-
const cancellationKey = getRunTaskCommandCancellationKey(
46+
const runBuildArgs = [opts.taskName].concat(taskArgs);
47+
const runBuildOpts = {
48+
...opts,
49+
args: runBuildArgs,
50+
};
51+
return this.runBuild(runBuildOpts, task);
52+
}
53+
54+
public async runBuild(opts: RunBuildOpts, task?: vscode.Task): Promise<void> {
55+
const cancellationKey = getRunBuildCancellationKey(
3956
opts.projectFolder,
40-
opts.taskName
57+
opts.args
4158
);
4259
return this.client.runBuild(
4360
opts.projectFolder,
4461
cancellationKey,
45-
buildArgs,
62+
opts.args,
4663
opts.input,
4764
0,
4865
task,

0 commit comments

Comments
 (0)