From 5fc5969e5a716b59273b6d9a7623148934d7f8e4 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Diniz de Araujo Date: Wed, 3 Apr 2024 22:13:26 -0300 Subject: [PATCH] FUSETOOLS2-2314: Provide extra parameter when running and debugging with JBang Signed-off-by: Marcelo Henrique Diniz de Araujo --- CHANGELOG.md | 1 + README.md | 1 + package.json | 5 ++ src/task/CamelJBangTaskProvider.ts | 21 +++++- ...el.extra.launch.parameter.settings.test.ts | 65 +++++++++++++++++++ src/ui-test/tests/camel.settings.test.ts | 36 +++++++++- src/ui-test/utils.ts | 1 + 7 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 src/test/suite/camel.extra.launch.parameter.settings.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index cccd8476..f4572f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the "vscode-debug-adapter-apache-camel" extension will be ## 0.13.0 - Update default Camel version used for Camel JBang from 4.4.0 to 4.5.0 +- Add support for custom parameters while running or debugging a camel application. ## 0.12.0 diff --git a/README.md b/README.md index 1e79d5d0..08275935 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ This is the Visual Studio Code exte - It requires a valid Camel file defined in Yaml DSL (`.yaml|.yml`) opened in editor. - Contextual menu in File explorer. It is visible to all `*.yaml` and `*.yml`. - Codelens at the top of a Camel file. +- Supports adding extra parameters provided by the `JBang camel run` command. (For both running and debugging the application) - Configuration snippets for Camel debugger launch configuration - Configuration snippets to launch Camel application ready to accept a Camel debugger connection using JBang, Maven with Camel maven plugin or Quarkus Devs diff --git a/package.json b/package.json index de19a9fe..74d30cb0 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,11 @@ "type": "boolean", "markdownDescription": "The `#repos` placeholder will be added by default to use also repositories defined in global Camel JBang configuration file.\n\n**Note**: The placeholder is available for versions `3.20.7/3.21` onwards.", "default": true + }, + "camel.debugAdapter.ExtraLaunchParameter": { + "type": "string", + "markdownDescription": "User defined parameter to be applied at every launch. To use more than one parameter each one has to be quoted according to your os/platform, e.g.: `'--max-messages=100' '--fresh'`\n\nDefault value is `--local-kamelet-dir=.`\n\n**Note**: Excluding `--dev`, `--logging-level`, `--dep`, `--camel-version` and `--repos` which are already being used\n\nFor possible values see:\n\n camel run --help\n\nor\n\njbang camel@apache/camel run --help", + "default": "--local-kamelet-dir=." } } }, diff --git a/src/task/CamelJBangTaskProvider.ts b/src/task/CamelJBangTaskProvider.ts index 46c95749..d1106169 100644 --- a/src/task/CamelJBangTaskProvider.ts +++ b/src/task/CamelJBangTaskProvider.ts @@ -62,7 +62,11 @@ export class CamelJBangTaskProvider implements TaskProvider { "quoting": 2 }, `${this.getCamelVersion()}`, - `${this.getRedHatMavenRepository()}` + `${this.getRedHatMavenRepository()}`, + { + "value": `${this.getExtraLaunchParameter()}`, + "quoting": 3 + }, ], shellExecOptions ), @@ -92,7 +96,11 @@ export class CamelJBangTaskProvider implements TaskProvider { '--dev', '--logging-level=info', `${this.getCamelVersion()}`, - `${this.getRedHatMavenRepository()}` + `${this.getRedHatMavenRepository()}`, + { + "value": `${this.getExtraLaunchParameter()}`, + "quoting": 3 + } ] ) ); @@ -138,4 +146,13 @@ export class CamelJBangTaskProvider implements TaskProvider { return ''; } } + + private getExtraLaunchParameter(): string{ + const extraLaunchParameter = workspace.getConfiguration().get('camel.debugAdapter.ExtraLaunchParameter') as string; + if(extraLaunchParameter){ + return extraLaunchParameter; + } else { + return ''; + } + } } diff --git a/src/test/suite/camel.extra.launch.parameter.settings.test.ts b/src/test/suite/camel.extra.launch.parameter.settings.test.ts new file mode 100644 index 00000000..1cbacfbe --- /dev/null +++ b/src/test/suite/camel.extra.launch.parameter.settings.test.ts @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License", destination); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +import { ShellQuotedString, workspace } from 'vscode'; +import { CamelJBangTaskProvider } from '../../task/CamelJBangTaskProvider'; +import { expect } from 'chai'; +import { getCamelTask, getTaskCommandArguments } from './util'; + +suite('Should run commands with the extra launch parameter specified in settings', () => { + + const EXTRA_LAUNCH_PARAMETER = '--fresh'; + const EXTRA_LAUNCH_PARAMETER_ID = 'camel.debugAdapter.ExtraLaunchParameter'; + + let defaultExtraLaunchParameter = ''; + + suiteSetup(function () { + defaultExtraLaunchParameter = workspace.getConfiguration().get(EXTRA_LAUNCH_PARAMETER_ID) as string; + }); + + teardown(async function () { + await workspace.getConfiguration().update(EXTRA_LAUNCH_PARAMETER_ID, defaultExtraLaunchParameter); + }); + + test('Default extra launch parameter is not empty', function () { + expect(workspace.getConfiguration().get(EXTRA_LAUNCH_PARAMETER_ID)).to.not.be.undefined; + }); + + test('Updated extra launch parameter is correct in generated \'Run with JBang\' task', async function () { + const config = workspace.getConfiguration(); + expect(config.get(EXTRA_LAUNCH_PARAMETER_ID)).to.not.be.equal(EXTRA_LAUNCH_PARAMETER); + + await config.update(EXTRA_LAUNCH_PARAMETER_ID, EXTRA_LAUNCH_PARAMETER); + + const camelRunTask = await getCamelTask(CamelJBangTaskProvider.labelProvidedRunTask); + const extraLaunchParameterPosition = 8; + expect((getTaskCommandArguments(camelRunTask)![extraLaunchParameterPosition] as ShellQuotedString).value).to.includes(EXTRA_LAUNCH_PARAMETER); + }); + + test('Updated extra launch parameter is correct in generated \'Run and Debug with JBang\' task', async function () { + const config = workspace.getConfiguration(); + expect(config.get(EXTRA_LAUNCH_PARAMETER_ID)).to.not.be.equal(EXTRA_LAUNCH_PARAMETER); + + await config.update(EXTRA_LAUNCH_PARAMETER_ID, EXTRA_LAUNCH_PARAMETER); + + const camelRunAndDebugTask = await getCamelTask(CamelJBangTaskProvider.labelProvidedTask); + const extraLaunchParameterPosition = 10; + expect((getTaskCommandArguments(camelRunAndDebugTask)![extraLaunchParameterPosition] as ShellQuotedString).value).to.includes(EXTRA_LAUNCH_PARAMETER); + }); + +}); diff --git a/src/ui-test/tests/camel.settings.test.ts b/src/ui-test/tests/camel.settings.test.ts index ec49ed52..c0616c7f 100644 --- a/src/ui-test/tests/camel.settings.test.ts +++ b/src/ui-test/tests/camel.settings.test.ts @@ -16,7 +16,7 @@ */ import { Workbench, VSBrowser, EditorView, WebDriver, before, ActivityBar, SideBarView, BottomBarPanel, beforeEach, afterEach } from 'vscode-uitests-tooling'; import * as path from 'path'; -import { CAMEL_ROUTE_YAML_WITH_SPACE, CAMEL_RUN_ACTION_QUICKPICKS_LABEL, CATALOG_VERSION_ID, JBANG_VERSION_ID, RH_MAVEN_REPOSITORY_GLOBAL, TEST_ARRAY_RUN, executeCommand, killTerminal, waitUntilTerminalHasText } from '../utils'; +import { CAMEL_ROUTE_YAML_WITH_SPACE, CAMEL_RUN_ACTION_QUICKPICKS_LABEL, CATALOG_VERSION_ID, EXTRA_LAUNCH_PARAMETER_ID, JBANG_VERSION_ID, RH_MAVEN_REPOSITORY_GLOBAL, TEST_ARRAY_RUN, executeCommand, killTerminal, waitUntilTerminalHasText } from '../utils'; import * as fs from 'node:fs'; import { storageFolder } from '../uitest_runner'; import { Context } from 'mocha'; @@ -27,6 +27,7 @@ describe('Camel User Settings', function () { let driver: WebDriver; let defaultJBangVersion: string; let defaultMavenRepository: string; + let defaultExtraLaunchParameter: string; const RESOURCES = path.resolve('src', 'ui-test', 'resources'); @@ -42,6 +43,7 @@ describe('Camel User Settings', function () { defaultJBangVersion = await getSettingsValue('JBang Version') as string; defaultMavenRepository = await getSettingsValue('Red Hat Maven Repository') as string; + defaultExtraLaunchParameter = await getSettingsValue('Extra Launch Parameter') as string; }); describe('Update Camel Version', function () { @@ -125,6 +127,34 @@ describe('Camel User Settings', function () { }); + describe('Update Extra Launch Parameter', function () { + + const customExtraLaunchParameter = '--fresh'; + + beforeEach(async function () { + await prepareEnvironment(); + }); + + afterEach(async function () { + await cleanEnvironment(); + resetUserSettings(EXTRA_LAUNCH_PARAMETER_ID); + }); + + it('Should use default extra launch parameter', async function () { + await executeCommand(CAMEL_RUN_ACTION_QUICKPICKS_LABEL); + + await waitUntilTerminalHasText(driver, [`${defaultExtraLaunchParameter}`], 6000, 120000); + }); + + it(`Should use user defined extra launch parameter'${customExtraLaunchParameter}'`, async function () { + await setExtraLaunchParameter(customExtraLaunchParameter); + await executeCommand(CAMEL_RUN_ACTION_QUICKPICKS_LABEL); + + await waitUntilTerminalHasText(driver, [`${customExtraLaunchParameter}`], 6000, 120000); + }); + + }); + async function prepareEnvironment(): Promise { await (await new ActivityBar().getViewControl('Explorer')).openView(); const section = await new SideBarView().getContent().getSection('resources'); @@ -149,6 +179,10 @@ describe('Camel User Settings', function () { await setSettingsValue(version, 'JBang Version'); } + async function setExtraLaunchParameter(parameter: string): Promise{ + await setSettingsValue(parameter, 'Extra Launch Parameter'); + } + async function setSettingsValue(value: string | boolean, title: string, path: string[] = ['Camel', 'Debug Adapter']): Promise { const textField = await (await new Workbench().openSettings()).findSetting(title, ...path); await textField.setValue(value); diff --git a/src/ui-test/utils.ts b/src/ui-test/utils.ts index 565defca..90f7a77c 100644 --- a/src/ui-test/utils.ts +++ b/src/ui-test/utils.ts @@ -80,6 +80,7 @@ export const JBANG_VERSION_ID = 'camel.debugAdapter.JBangVersion'; export const CATALOG_VERSION_ID = 'camel.debugAdapter.CamelVersion'; export const RH_MAVEN_REPOSITORY = "camel.debugAdapter.RedHatMavenRepository"; export const RH_MAVEN_REPOSITORY_GLOBAL = "camel.debugAdapter.redHatMavenRepository.global"; +export const EXTRA_LAUNCH_PARAMETER_ID = 'camel.debugAdapter.ExtraLaunchParameter'; /** * Executes a command in the command prompt of the workbench.