From 45fc036a6918e266ff4249f8836408e36c9c852f Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sat, 9 May 2020 18:24:06 +0100 Subject: [PATCH] Rename types package and fix tests --- .github/workflows/publish.yml | 4 ++-- .vscode/settings.json | 2 +- extension/build.gradle | 2 +- extension/src/tasks.ts | 13 ++++++++++++- extension/src/test/gradle/extension.test.ts | 4 ++-- {types-package => npm-package}/.eslintignore | 0 {types-package => npm-package}/.eslintrc.json | 0 {types-package => npm-package}/.gitignore | 0 {types-package => npm-package}/.npmignore | 0 {types-package => npm-package}/.npmrc | 0 {types-package => npm-package}/.prettierignore | 0 {types-package => npm-package}/.prettierrc.json | 0 {types-package => npm-package}/README.md | 0 {types-package => npm-package}/build.gradle | 15 +++++++++++++-- npm-package/index.ts | 11 +++++++++++ {types-package => npm-package}/package-lock.json | 0 {types-package => npm-package}/package.json | 0 {types-package => npm-package}/tsconfig.json | 0 settings.gradle | 2 +- types-package/index.ts | 10 ---------- 20 files changed, 43 insertions(+), 20 deletions(-) rename {types-package => npm-package}/.eslintignore (100%) rename {types-package => npm-package}/.eslintrc.json (100%) rename {types-package => npm-package}/.gitignore (100%) rename {types-package => npm-package}/.npmignore (100%) rename {types-package => npm-package}/.npmrc (100%) rename {types-package => npm-package}/.prettierignore (100%) rename {types-package => npm-package}/.prettierrc.json (100%) rename {types-package => npm-package}/README.md (100%) rename {types-package => npm-package}/build.gradle (74%) create mode 100644 npm-package/index.ts rename {types-package => npm-package}/package-lock.json (100%) rename {types-package => npm-package}/package.json (100%) rename {types-package => npm-package}/tsconfig.json (100%) delete mode 100644 types-package/index.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 642d3546..ee1647af 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,12 +16,12 @@ jobs: - name: Build & prepare extension uses: eskatos/gradle-command-action@v1 with: - arguments: extension:prepareForRelease types-package:build -x buildTypeScript -x buildTypeScriptTests + arguments: extension:prepareForRelease npm-package:build -x buildTypeScript -x buildTypeScriptTests - name: Publish types env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | - cd types-package + cd npm-package tag=${GITHUB_REF#refs/tags/} echo "Setting package version $tag" npm --no-git-tag-version version "$tag" diff --git a/.vscode/settings.json b/.vscode/settings.json index 15f2dd58..6e7e279c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ }, "typescript.tsc.autoDetect": "off", "eslint.validate": ["javascript", "typescript"], - "eslint.workingDirectories": ["extension","types-package"], + "eslint.workingDirectories": ["extension","npm-package"], "java.configuration.updateBuildConfiguration": "automatic", "cSpell.language": "en-GB", "cSpell.words": [ diff --git a/extension/build.gradle b/extension/build.gradle index a5754a44..42ed3d63 100644 --- a/extension/build.gradle +++ b/extension/build.gradle @@ -151,7 +151,7 @@ task buildTypeScriptTests(type: CrossPlatformExec) { } task bundle(type: CrossPlatformExec) { - dependsOn ':tasks-server:build', ':types-package:build', copyProtoJs, copyProtoTs + dependsOn ':tasks-server:build', ':npm-package:build', copyProtoJs, copyProtoTs group 'build' description 'Bundles the extension files for release' buildDir = 'dist' diff --git a/extension/src/tasks.ts b/extension/src/tasks.ts index 10598031..cea52ab0 100644 --- a/extension/src/tasks.ts +++ b/extension/src/tasks.ts @@ -15,7 +15,7 @@ import { } from './config'; import { logger } from './logger'; import { GradleTasksClient } from './client'; -import { waitOnTcp } from './util'; +import { waitOnTcp, isTest } from './util'; import { Output, GradleProject, @@ -23,6 +23,7 @@ import { GradleBuild, } from './proto/gradle_tasks_pb'; import { SERVER_TASK_NAME } from './server'; +import { OutputBuffer } from './OutputBuffer'; const localize = nls.loadMessageBundle(); @@ -454,6 +455,12 @@ class CustomBuildTaskTerminal implements vscode.Pseudoterminal { } private async doBuild(): Promise { + // This is only required in the tests, so we can check the stdout of the task + const stdOutBuffer = new OutputBuffer(Output.OutputType.STDOUT); + stdOutBuffer.onOutputLine((output: string) => { + logger.info(output); + }); + const args: string[] = this.task.definition.args.split(' ').filter(Boolean); try { const javaDebugEnabled = this.task.definition.javaDebug; @@ -467,12 +474,16 @@ class CustomBuildTaskTerminal implements vscode.Pseudoterminal { javaDebugPort, (output: Output): void => { this.handleOutput(output.getMessageByte()); + if (isTest()) { + stdOutBuffer.write(output.getMessageByte()); + } } ); if (javaDebugEnabled) { await this.startJavaDebug(javaDebugPort!); } await runTask; + stdOutBuffer.dispose(); vscode.commands.executeCommand( 'gradle.updateJavaProjectConfiguration', vscode.Uri.file(this.task.definition.buildFile) diff --git a/extension/src/test/gradle/extension.test.ts b/extension/src/test/gradle/extension.test.ts index dbc8d66b..a3c7f88a 100644 --- a/extension/src/test/gradle/extension.test.ts +++ b/extension/src/test/gradle/extension.test.ts @@ -129,14 +129,14 @@ describe(fixtureName, () => { let hasMessage = false; const stdOutBuffer = new OutputBuffer(Output.OutputType.STDOUT); stdOutBuffer.onOutputLine((message: string) => { - if (message === 'Hello, World!') { + if (message.trim() === 'Hello, World!') { hasMessage = true; } }); const runTaskOpts = { projectFolder: fixturePath, taskName: 'hello', - showOutputColors: true, + showOutputColors: false, onOutput: (output: Output): void => { stdOutBuffer.write(output.getMessageByte()); }, diff --git a/types-package/.eslintignore b/npm-package/.eslintignore similarity index 100% rename from types-package/.eslintignore rename to npm-package/.eslintignore diff --git a/types-package/.eslintrc.json b/npm-package/.eslintrc.json similarity index 100% rename from types-package/.eslintrc.json rename to npm-package/.eslintrc.json diff --git a/types-package/.gitignore b/npm-package/.gitignore similarity index 100% rename from types-package/.gitignore rename to npm-package/.gitignore diff --git a/types-package/.npmignore b/npm-package/.npmignore similarity index 100% rename from types-package/.npmignore rename to npm-package/.npmignore diff --git a/types-package/.npmrc b/npm-package/.npmrc similarity index 100% rename from types-package/.npmrc rename to npm-package/.npmrc diff --git a/types-package/.prettierignore b/npm-package/.prettierignore similarity index 100% rename from types-package/.prettierignore rename to npm-package/.prettierignore diff --git a/types-package/.prettierrc.json b/npm-package/.prettierrc.json similarity index 100% rename from types-package/.prettierrc.json rename to npm-package/.prettierrc.json diff --git a/types-package/README.md b/npm-package/README.md similarity index 100% rename from types-package/README.md rename to npm-package/README.md diff --git a/types-package/build.gradle b/npm-package/build.gradle similarity index 74% rename from types-package/build.gradle rename to npm-package/build.gradle index 6758b76d..630b9814 100644 --- a/types-package/build.gradle +++ b/npm-package/build.gradle @@ -1,4 +1,4 @@ -description = 'vscode-gradle :: types' +description = 'vscode-gradle :: npm-package' def isWindows = System.getProperty('os.name').toLowerCase().contains('windows') @@ -17,6 +17,13 @@ task copyProtoLib(type: Copy) { into protoLib } +task copyOutputBuffer(type: Copy) { + group 'copy' + description 'Copies OutputBuffer helper class' + from file("../extension/src/OutputBuffer.ts") + into 'lib' +} + task copyPublicApiTypes(type: Copy) { group 'copy' description 'Copies publc API types' @@ -39,4 +46,8 @@ task compileTypeScript(type: CrossPlatformExec) { commandLine 'npm', 'run', 'compile' } -assemble.finalizedBy npmInstall, compileTypeScript, copyProtoLib, copyPublicApiTypes +assemble.finalizedBy npmInstall, + compileTypeScript, + copyProtoLib, + copyPublicApiTypes, + copyOutputBuffer diff --git a/npm-package/index.ts b/npm-package/index.ts new file mode 100644 index 00000000..c235c70f --- /dev/null +++ b/npm-package/index.ts @@ -0,0 +1,11 @@ +import * as vscode from 'vscode'; +import { Output } from './lib/proto/gradle_tasks_pb'; +import { RunTaskHandler, RunTaskOpts } from './lib/runTask'; +import { OutputBuffer } from './lib/OutputBuffer'; + +interface ExtensionApi { + runTask: RunTaskHandler; + onTasksLoaded: vscode.Event; +} + +export { Output, RunTaskHandler, RunTaskOpts, OutputBuffer, ExtensionApi }; diff --git a/types-package/package-lock.json b/npm-package/package-lock.json similarity index 100% rename from types-package/package-lock.json rename to npm-package/package-lock.json diff --git a/types-package/package.json b/npm-package/package.json similarity index 100% rename from types-package/package.json rename to npm-package/package.json diff --git a/types-package/tsconfig.json b/npm-package/tsconfig.json similarity index 100% rename from types-package/tsconfig.json rename to npm-package/tsconfig.json diff --git a/settings.gradle b/settings.gradle index 2214130b..8410a896 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'vscode-gradle' include('tasks-server') include('extension') -include('types-package') +include('npm-package') diff --git a/types-package/index.ts b/types-package/index.ts deleted file mode 100644 index c0b40c7f..00000000 --- a/types-package/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as vscode from 'vscode'; -import { Output, RunTaskRequest } from './lib/proto/gradle_tasks_pb'; -import { RunTaskHandler, RunTaskOpts } from './lib/runTask'; - -export { Output, RunTaskRequest, RunTaskHandler, RunTaskOpts }; - -export interface ExtensionApi { - runTask: RunTaskHandler; - onTasksLoaded: vscode.Event; -}