Skip to content

Commit

Permalink
FUSETOOLS2-2314: Provide extra parameter when running and debugging w…
Browse files Browse the repository at this point in the history
…ith JBang

Signed-off-by: Marcelo Henrique Diniz de Araujo <[email protected]>
  • Loading branch information
hdamarcelo committed Apr 9, 2024
1 parent 7c264af commit 5fc5969
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ This is the <a href="https://code.visualstudio.com/">Visual Studio Code</a> 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

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=."
}
}
},
Expand Down
21 changes: 19 additions & 2 deletions src/task/CamelJBangTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export class CamelJBangTaskProvider implements TaskProvider {
"quoting": 2
},
`${this.getCamelVersion()}`,
`${this.getRedHatMavenRepository()}`
`${this.getRedHatMavenRepository()}`,
{
"value": `${this.getExtraLaunchParameter()}`,
"quoting": 3
},
],
shellExecOptions
),
Expand Down Expand Up @@ -92,7 +96,11 @@ export class CamelJBangTaskProvider implements TaskProvider {
'--dev',
'--logging-level=info',
`${this.getCamelVersion()}`,
`${this.getRedHatMavenRepository()}`
`${this.getRedHatMavenRepository()}`,
{
"value": `${this.getExtraLaunchParameter()}`,
"quoting": 3
}
]
)
);
Expand Down Expand Up @@ -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 '';
}
}
}
65 changes: 65 additions & 0 deletions src/test/suite/camel.extra.launch.parameter.settings.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});

});
36 changes: 35 additions & 1 deletion src/ui-test/tests/camel.settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');

Expand All @@ -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 () {
Expand Down Expand Up @@ -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<void> {
await (await new ActivityBar().getViewControl('Explorer')).openView();
const section = await new SideBarView().getContent().getSection('resources');
Expand All @@ -149,6 +179,10 @@ describe('Camel User Settings', function () {
await setSettingsValue(version, 'JBang Version');
}

async function setExtraLaunchParameter(parameter: string): Promise<void>{
await setSettingsValue(parameter, 'Extra Launch Parameter');
}

async function setSettingsValue(value: string | boolean, title: string, path: string[] = ['Camel', 'Debug Adapter']): Promise<void> {
const textField = await (await new Workbench().openSettings()).findSetting(title, ...path);
await textField.setValue(value);
Expand Down
1 change: 1 addition & 0 deletions src/ui-test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5fc5969

Please sign in to comment.