Skip to content

Commit

Permalink
Reuse task terminals (#748)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
badsyntax authored Oct 11, 2020
1 parent 54a0724 commit e4d56e1
Show file tree
Hide file tree
Showing 45 changed files with 258 additions and 84 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build & Publish
on:
push:
branches: [master]
pull_request:
branches: [master]
release:
Expand All @@ -15,7 +16,7 @@ jobs:
- name: Use Java 8
uses: actions/setup-java@v1
with:
java-version: '8'
java-version: "8"
architecture: x64
- name: Use Node 12.16.2
uses: actions/setup-node@v1
Expand All @@ -34,7 +35,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_SONARCLOUD_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
JAVA_HOME: ''
JAVA_HOME: ""
- name: Upload lib
uses: actions/upload-artifact@v2
with:
Expand All @@ -45,12 +46,12 @@ jobs:
# lib generated in the previous step for a better real-world test.
test-extension:
needs: [build-and-analyse]
name: 'Test Java ${{ matrix.java-version }} - Node ${{ matrix.node-version }} - ${{ matrix.os }}'
name: "Test Java ${{ matrix.java-version }} - Node ${{ matrix.node-version }} - ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.16.2]
java-version: ['8', '11']
java-version: ["8", "11"]
os: [ubuntu-latest, windows-latest]
# os: [ubuntu-latest, windows-latest, macos-latest]
steps:
Expand All @@ -70,7 +71,7 @@ jobs:
arguments: extension:build
wrapper-cache-enabled: false
env:
NODE_OPTIONS: '--max-old-space-size=4096'
NODE_OPTIONS: "--max-old-space-size=4096"
- name: Download lib
uses: actions/download-artifact@v2
with:
Expand Down Expand Up @@ -112,8 +113,8 @@ jobs:
arguments: testVsCode
wrapper-cache-enabled: false
env:
DISPLAY: ':99.0'
CI: 'true'
DISPLAY: ":99.0"
CI: "true"
- name: Stop Gradle daemon for root project
uses: eskatos/gradle-command-action@v1
with:
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A Gradle build can have one or more projects. Projects are listed in a flat list

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.

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

</details>
<details><summary>Run tasks</summary>
Expand All @@ -47,7 +47,7 @@ Tasks can be run via:

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.

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

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

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

</details>

<details><summary>Control task terminal behaviour</summary>

`"gradle.reuseTerminals": "task"` (default):

<img src="./images/reuse-terminals-task.gif" />

`"gradle.reuseTerminals": "all"`:

<img src="./images/reuse-terminals-all.gif" />

`"gradle.reuseTerminals": "off"`:

<img src="./images/reuse-terminals-off.gif" />

</details>

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

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.
Expand Down Expand Up @@ -153,20 +170,21 @@ The extension uses the Gradle wrapper to list daemons, and is quite a slow proce

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.autoDetect`: Automatically detect Gradle tasks ("on" or "off")
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task (boolean)
- `gradle.nestedProjects`: Process nested projects (boolean or an array of directories)
- `gradle.reuseTerminals`: Reuse task terminals ("task" [default], "all", or "off")
- `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)
- `gradle.debug`: Show extra debug info in the output panel (boolean)
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc) (boolean)

## Gradle & Java Settings

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

### Example Environment Variables

- `JAVE_HOME`
- `JAVA_HOME`
- `GRADLE_USER_HOME`

_Note, the VS Code settings take precedence over the environment variables._
Expand Down
10 changes: 10 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,16 @@
"default": false,
"description": "Discover Gradle projects in nested sub-directories"
},
"gradle.reuseTerminals": {
"enum": [
"task",
"off",
"all"
],
"default": "task",
"scope": "window",
"description": "Reuse task terminals behaviour"
},
"gradle.debug": {
"type": "boolean",
"default": false,
Expand Down
1 change: 0 additions & 1 deletion extension/src/async/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions extension/src/client/GradleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import {

import { GradleClient as GrpcClient } from '../proto/gradle_grpc_pb';
import { logger, LoggerStream, LogVerbosity, Logger } from '../logger';
import { EventWaiter } from '../events';
import { EventWaiter } from '../util';
import { GradleServer } from '../server';
import { ProgressHandler } from '../progress';
import { getGradleConfig, getConfigJavaDebug } from '../config';
import { getGradleConfig, getConfigJavaDebug } from '../util';
import { removeCancellingTask, restartQueuedTask } from '../tasks/taskUtil';
import {
COMMAND_REFRESH_DAEMON_STATUS,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/ClearAllPinnedTasksCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { confirmModal } from '../input';
import { confirmModal } from '../util/input';
import { PinnedTasksStore } from '../stores';
import { Command } from './Command';

Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/ClearAllRecentTasksCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { confirmModal } from '../input';
import { confirmModal } from '../util/input';
import { RecentTasksStore } from '../stores';
import { Command } from './Command';

Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/CloseAllTaskTerminalsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { confirmModal } from '../input';
import { confirmModal } from '../util/input';
import { TaskTerminalsStore } from '../stores';
import { Command } from './Command';

Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/PinTaskWithArgsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GradleTaskTreeItem, PinnedTasksTreeDataProvider } from '../views';
import { GradleTaskDefinition } from '../tasks';
import { getTaskArgs } from '../input';
import { getTaskArgs } from '../util/input';
import { Command } from './Command';

export const COMMAND_PIN_TASK_WITH_ARGS = 'gradle.pinTaskWithArgs';
Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/RunBuildCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { parseArgsStringToArgv } from 'string-argv';
import { getGradleCommand, getRootProjectFolder } from '../input';
import { getGradleCommand, getRootProjectFolder } from '../util/input';
import { GradleRunnerTerminal } from '../terminal';
import { getRunBuildCancellationKey } from '../client/CancellationKeys';
import { Command } from './Command';
Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/StopDaemonCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GradleDaemonTreeItem } from '../views';
import { confirmModal } from '../input';
import { confirmModal } from '../util/input';
import { logger } from '../logger';
import { Command } from './Command';
import { GradleClient } from '../client';
Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/StopDaemonsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { confirmModal } from '../input';
import { confirmModal } from '../util/input';
import { StopDaemonsReply } from '../proto/gradle_pb';
import { logger } from '../logger';
import { Command } from './Command';
Expand Down
1 change: 0 additions & 1 deletion extension/src/decorators/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion extension/src/events/index.ts

This file was deleted.

15 changes: 6 additions & 9 deletions extension/src/extension/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Api } from '../api';
import { GradleClient } from '../client';
import { GradleServer } from '../server';
import { Icons } from '../icons';
import {
getConfigFocusTaskInExplorer,
getConfigIsDebugEnabled,
} from '../config';
import { getConfigFocusTaskInExplorer, getConfigIsDebugEnabled } from '../util';
import {
GradleDaemonsTreeDataProvider,
PinnedTasksTreeDataProvider,
Expand All @@ -32,7 +29,7 @@ import {
RECENT_TASKS_VIEW,
} from '../views/constants';
import { focusTaskInGradleTasksTree } from '../views/viewUtil';
import { FileWatcher } from '../watcher';
import { FileWatcher } from '../util';
import { COMMAND_RENDER_TASK, COMMAND_REFRESH } from '../commands';
import { Commands } from '../commands/Commands';

Expand Down Expand Up @@ -263,16 +260,16 @@ export class Extension {
event.affectsConfiguration('java.import.gradle.java.home')
) {
await this.restartServer();
}
if (
} else if (
event.affectsConfiguration('gradle.javaDebug') ||
event.affectsConfiguration('gradle.nestedProjects')
) {
this.rootProjectsStore.clear();
await this.refresh();
await this.activate();
}
if (event.affectsConfiguration('gradle.debug')) {
} else if (event.affectsConfiguration('gradle.reuseTerminals')) {
await this.refresh();
} else if (event.affectsConfiguration('gradle.debug')) {
const debug = getConfigIsDebugEnabled();
Logger.setLogVerbosity(
debug ? LogVerbosity.DEBUG : LogVerbosity.INFO
Expand Down
2 changes: 1 addition & 1 deletion extension/src/rootProject/RootProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { Environment } from '../proto/gradle_pb';
import { JavaDebug } from '../config';
import { JavaDebug } from '../util';

export class RootProject {
private environment?: Environment;
Expand Down
1 change: 1 addition & 0 deletions extension/src/rootProject/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './RootProject';
2 changes: 1 addition & 1 deletion extension/src/server/serverUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConfigGradleJavaHome } from '../config';
import { getConfigGradleJavaHome } from '../util';

export function getGradleServerCommand(): string {
const platform = process.platform;
Expand Down
2 changes: 1 addition & 1 deletion extension/src/stores/EventedStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { debounce } from '../decorators';
import { debounce } from '../util';

export abstract class EventedStore<V> implements vscode.Disposable {
private readonly _onDidChange: vscode.EventEmitter<V | null> = new vscode.EventEmitter<
Expand Down
2 changes: 1 addition & 1 deletion extension/src/stores/RootProjectsStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { getNestedProjectsConfig, getConfigJavaDebug } from '../config';
import { getNestedProjectsConfig, getConfigJavaDebug } from '../util';
import { StoreMap } from '.';
import { isGradleRootProject } from '../util';
import { RootProject } from '../rootProject/RootProject';
Expand Down
8 changes: 5 additions & 3 deletions extension/src/tasks/GradleTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as vscode from 'vscode';
import { EventWaiter } from '../events';
import { EventWaiter } from '../util';
import { GradleTaskDefinition } from '.';
import { logger } from '../logger';
import { createTaskFromDefinition, loadTasksForProjectRoots } from './taskUtil';
import { TaskId } from '../stores/types';
import { RootProjectsStore, TaskTerminalsStore } from '../stores';
import { RootProject } from '../rootProject/RootProject';
import { getConfigJavaDebug } from '../config';
import { getConfigJavaDebug, getConfigReuseTerminals } from '../util';
import { GradleClient } from '../client';

export class GradleTaskProvider
Expand Down Expand Up @@ -64,11 +64,13 @@ export class GradleTaskProvider
vscode.Uri.file(gradleTaskDefinition.projectFolder),
javaDebug
);
const reuseTerminals = getConfigReuseTerminals();
return createTaskFromDefinition(
this.taskTerminalsStore,
gradleTaskDefinition,
rootProject,
this.client
this.client,
reuseTerminals
);
}

Expand Down
Loading

0 comments on commit e4d56e1

Please sign in to comment.