Skip to content

Commit e4d56e1

Browse files
authored
Reuse task terminals (#748)
* Reuse task terminals * Add more options for gradle.reuseTerminals with tests * Remove test debug * Remove some duplicated config * Reduce some duplicated code * Fix tests * Update README * Update task description * Files org * Fix import paths * Fix config imports * Copy util types to npm package * Restrict push CI to master branch * Format github actions file * Add reuseTerminals screencasts * Move util stuff into util dir * Ignore generated files * Move to util
1 parent 54a0724 commit e4d56e1

Some content is hidden

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

45 files changed

+258
-84
lines changed

.github/workflows/main.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Build & Publish
22
on:
33
push:
4+
branches: [master]
45
pull_request:
56
branches: [master]
67
release:
@@ -15,7 +16,7 @@ jobs:
1516
- name: Use Java 8
1617
uses: actions/setup-java@v1
1718
with:
18-
java-version: '8'
19+
java-version: "8"
1920
architecture: x64
2021
- name: Use Node 12.16.2
2122
uses: actions/setup-node@v1
@@ -34,7 +35,7 @@ jobs:
3435
env:
3536
GITHUB_TOKEN: ${{ secrets.GITHUB_SONARCLOUD_TOKEN }}
3637
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37-
JAVA_HOME: ''
38+
JAVA_HOME: ""
3839
- name: Upload lib
3940
uses: actions/upload-artifact@v2
4041
with:
@@ -45,12 +46,12 @@ jobs:
4546
# lib generated in the previous step for a better real-world test.
4647
test-extension:
4748
needs: [build-and-analyse]
48-
name: 'Test Java ${{ matrix.java-version }} - Node ${{ matrix.node-version }} - ${{ matrix.os }}'
49+
name: "Test Java ${{ matrix.java-version }} - Node ${{ matrix.node-version }} - ${{ matrix.os }}"
4950
runs-on: ${{ matrix.os }}
5051
strategy:
5152
matrix:
5253
node-version: [12.16.2]
53-
java-version: ['8', '11']
54+
java-version: ["8", "11"]
5455
os: [ubuntu-latest, windows-latest]
5556
# os: [ubuntu-latest, windows-latest, macos-latest]
5657
steps:
@@ -70,7 +71,7 @@ jobs:
7071
arguments: extension:build
7172
wrapper-cache-enabled: false
7273
env:
73-
NODE_OPTIONS: '--max-old-space-size=4096'
74+
NODE_OPTIONS: "--max-old-space-size=4096"
7475
- name: Download lib
7576
uses: actions/download-artifact@v2
7677
with:
@@ -112,8 +113,8 @@ jobs:
112113
arguments: testVsCode
113114
wrapper-cache-enabled: false
114115
env:
115-
DISPLAY: ':99.0'
116-
CI: 'true'
116+
DISPLAY: ":99.0"
117+
CI: "true"
117118
- name: Stop Gradle daemon for root project
118119
uses: eskatos/gradle-command-action@v1
119120
with:

README.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A Gradle build can have one or more projects. Projects are listed in a flat list
3434

3535
When you expand a project, tasks are listed in a tree, grouped by the task group. You can toggle the display of the tasks by clicking on the `Show Flat List`/`Show Tree` button in the treeview header.
3636

37-
<img src="./images/gradle-tasks-view.png" width="350" alt="Gradle Tasks View" />
37+
<img src="images/gradle-tasks-view.png" width="350" alt="Gradle Tasks View" />
3838

3939
</details>
4040
<details><summary>Run tasks</summary>
@@ -47,7 +47,7 @@ Tasks can be run via:
4747

4848
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.
4949

50-
<img src="./images/task-run.png" width="350" alt="Gradle Tasks Running" />
50+
<img src="images/task-run.png" width="350" alt="Gradle Tasks Running" />
5151

5252
A task will be run a vscode terminal where you can view the task output.
5353

@@ -60,6 +60,23 @@ Tasks run via the `Run a Gradle Build` command are not reflected in any of the t
6060
<img src="./images/run-build.png" width="650" alt="Run Gradle Build" />
6161

6262
</details>
63+
64+
<details><summary>Control task terminal behaviour</summary>
65+
66+
`"gradle.reuseTerminals": "task"` (default):
67+
68+
<img src="./images/reuse-terminals-task.gif" />
69+
70+
`"gradle.reuseTerminals": "all"`:
71+
72+
<img src="./images/reuse-terminals-all.gif" />
73+
74+
`"gradle.reuseTerminals": "off"`:
75+
76+
<img src="./images/reuse-terminals-off.gif" />
77+
78+
</details>
79+
6380
<details><summary>Debug JavaExec tasks</summary>
6481

6582
This extension provides an experimental feature to debug [JavaExec](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html) tasks. Before using this feature you need to install the [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug) and [Language Support for Java](https://marketplace.visualstudio.com/items?itemName=redhat.java) extensions.
@@ -153,20 +170,21 @@ The extension uses the Gradle wrapper to list daemons, and is quite a slow proce
153170

154171
This extension contributes the following settings:
155172

156-
- `gradle.autoDetect`: Automatically detect Gradle tasks
157-
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task
173+
- `gradle.autoDetect`: Automatically detect Gradle tasks ("on" or "off")
174+
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task (boolean)
158175
- `gradle.nestedProjects`: Process nested projects (boolean or an array of directories)
176+
- `gradle.reuseTerminals`: Reuse task terminals ("task" [default], "all", or "off")
159177
- `gradle.javaDebug`: Debug JavaExec tasks (see below for usage)
160-
- `gradle.debug`: Show extra debug info in the output panel
161-
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc)
178+
- `gradle.debug`: Show extra debug info in the output panel (boolean)
179+
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc) (boolean)
162180

163181
## Gradle & Java Settings
164182

165183
Set Gradle & Java options with standard environment variables or standard Gradle settings (eg via `gradle.properties` or task configuration).
166184

167185
### Example Environment Variables
168186

169-
- `JAVE_HOME`
187+
- `JAVA_HOME`
170188
- `GRADLE_USER_HOME`
171189

172190
_Note, the VS Code settings take precedence over the environment variables._

extension/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,16 @@
592592
"default": false,
593593
"description": "Discover Gradle projects in nested sub-directories"
594594
},
595+
"gradle.reuseTerminals": {
596+
"enum": [
597+
"task",
598+
"off",
599+
"all"
600+
],
601+
"default": "task",
602+
"scope": "window",
603+
"description": "Reuse task terminals behaviour"
604+
},
595605
"gradle.debug": {
596606
"type": "boolean",
597607
"default": false,

extension/src/async/index.ts

-1
This file was deleted.

extension/src/client/GradleClient.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import {
2626

2727
import { GradleClient as GrpcClient } from '../proto/gradle_grpc_pb';
2828
import { logger, LoggerStream, LogVerbosity, Logger } from '../logger';
29-
import { EventWaiter } from '../events';
29+
import { EventWaiter } from '../util';
3030
import { GradleServer } from '../server';
3131
import { ProgressHandler } from '../progress';
32-
import { getGradleConfig, getConfigJavaDebug } from '../config';
32+
import { getGradleConfig, getConfigJavaDebug } from '../util';
3333
import { removeCancellingTask, restartQueuedTask } from '../tasks/taskUtil';
3434
import {
3535
COMMAND_REFRESH_DAEMON_STATUS,

extension/src/commands/ClearAllPinnedTasksCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { confirmModal } from '../input';
1+
import { confirmModal } from '../util/input';
22
import { PinnedTasksStore } from '../stores';
33
import { Command } from './Command';
44

extension/src/commands/ClearAllRecentTasksCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { confirmModal } from '../input';
1+
import { confirmModal } from '../util/input';
22
import { RecentTasksStore } from '../stores';
33
import { Command } from './Command';
44

extension/src/commands/CloseAllTaskTerminalsCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { confirmModal } from '../input';
1+
import { confirmModal } from '../util/input';
22
import { TaskTerminalsStore } from '../stores';
33
import { Command } from './Command';
44

extension/src/commands/PinTaskWithArgsCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GradleTaskTreeItem, PinnedTasksTreeDataProvider } from '../views';
22
import { GradleTaskDefinition } from '../tasks';
3-
import { getTaskArgs } from '../input';
3+
import { getTaskArgs } from '../util/input';
44
import { Command } from './Command';
55

66
export const COMMAND_PIN_TASK_WITH_ARGS = 'gradle.pinTaskWithArgs';

extension/src/commands/RunBuildCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import { parseArgsStringToArgv } from 'string-argv';
3-
import { getGradleCommand, getRootProjectFolder } from '../input';
3+
import { getGradleCommand, getRootProjectFolder } from '../util/input';
44
import { GradleRunnerTerminal } from '../terminal';
55
import { getRunBuildCancellationKey } from '../client/CancellationKeys';
66
import { Command } from './Command';

extension/src/commands/StopDaemonCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GradleDaemonTreeItem } from '../views';
2-
import { confirmModal } from '../input';
2+
import { confirmModal } from '../util/input';
33
import { logger } from '../logger';
44
import { Command } from './Command';
55
import { GradleClient } from '../client';

extension/src/commands/StopDaemonsCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { confirmModal } from '../input';
2+
import { confirmModal } from '../util/input';
33
import { StopDaemonsReply } from '../proto/gradle_pb';
44
import { logger } from '../logger';
55
import { Command } from './Command';

extension/src/decorators/index.ts

-1
This file was deleted.

extension/src/events/index.ts

-1
This file was deleted.

extension/src/extension/Extension.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { Api } from '../api';
44
import { GradleClient } from '../client';
55
import { GradleServer } from '../server';
66
import { Icons } from '../icons';
7-
import {
8-
getConfigFocusTaskInExplorer,
9-
getConfigIsDebugEnabled,
10-
} from '../config';
7+
import { getConfigFocusTaskInExplorer, getConfigIsDebugEnabled } from '../util';
118
import {
129
GradleDaemonsTreeDataProvider,
1310
PinnedTasksTreeDataProvider,
@@ -32,7 +29,7 @@ import {
3229
RECENT_TASKS_VIEW,
3330
} from '../views/constants';
3431
import { focusTaskInGradleTasksTree } from '../views/viewUtil';
35-
import { FileWatcher } from '../watcher';
32+
import { FileWatcher } from '../util';
3633
import { COMMAND_RENDER_TASK, COMMAND_REFRESH } from '../commands';
3734
import { Commands } from '../commands/Commands';
3835

@@ -263,16 +260,16 @@ export class Extension {
263260
event.affectsConfiguration('java.import.gradle.java.home')
264261
) {
265262
await this.restartServer();
266-
}
267-
if (
263+
} else if (
268264
event.affectsConfiguration('gradle.javaDebug') ||
269265
event.affectsConfiguration('gradle.nestedProjects')
270266
) {
271267
this.rootProjectsStore.clear();
272268
await this.refresh();
273269
await this.activate();
274-
}
275-
if (event.affectsConfiguration('gradle.debug')) {
270+
} else if (event.affectsConfiguration('gradle.reuseTerminals')) {
271+
await this.refresh();
272+
} else if (event.affectsConfiguration('gradle.debug')) {
276273
const debug = getConfigIsDebugEnabled();
277274
Logger.setLogVerbosity(
278275
debug ? LogVerbosity.DEBUG : LogVerbosity.INFO

extension/src/rootProject/RootProject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import { Environment } from '../proto/gradle_pb';
3-
import { JavaDebug } from '../config';
3+
import { JavaDebug } from '../util';
44

55
export class RootProject {
66
private environment?: Environment;

extension/src/rootProject/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './RootProject';

extension/src/server/serverUtil.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getConfigGradleJavaHome } from '../config';
1+
import { getConfigGradleJavaHome } from '../util';
22

33
export function getGradleServerCommand(): string {
44
const platform = process.platform;

extension/src/stores/EventedStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { debounce } from '../decorators';
2+
import { debounce } from '../util';
33

44
export abstract class EventedStore<V> implements vscode.Disposable {
55
private readonly _onDidChange: vscode.EventEmitter<V | null> = new vscode.EventEmitter<

extension/src/stores/RootProjectsStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
3-
import { getNestedProjectsConfig, getConfigJavaDebug } from '../config';
3+
import { getNestedProjectsConfig, getConfigJavaDebug } from '../util';
44
import { StoreMap } from '.';
55
import { isGradleRootProject } from '../util';
66
import { RootProject } from '../rootProject/RootProject';

extension/src/tasks/GradleTaskProvider.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as vscode from 'vscode';
2-
import { EventWaiter } from '../events';
2+
import { EventWaiter } from '../util';
33
import { GradleTaskDefinition } from '.';
44
import { logger } from '../logger';
55
import { createTaskFromDefinition, loadTasksForProjectRoots } from './taskUtil';
66
import { TaskId } from '../stores/types';
77
import { RootProjectsStore, TaskTerminalsStore } from '../stores';
88
import { RootProject } from '../rootProject/RootProject';
9-
import { getConfigJavaDebug } from '../config';
9+
import { getConfigJavaDebug, getConfigReuseTerminals } from '../util';
1010
import { GradleClient } from '../client';
1111

1212
export class GradleTaskProvider
@@ -64,11 +64,13 @@ export class GradleTaskProvider
6464
vscode.Uri.file(gradleTaskDefinition.projectFolder),
6565
javaDebug
6666
);
67+
const reuseTerminals = getConfigReuseTerminals();
6768
return createTaskFromDefinition(
6869
this.taskTerminalsStore,
6970
gradleTaskDefinition,
7071
rootProject,
71-
this.client
72+
this.client,
73+
reuseTerminals
7274
);
7375
}
7476

0 commit comments

Comments
 (0)