Skip to content

Commit 434e89e

Browse files
authored
Include additional options in install command (#44)
To be able to bypass the SSL exception during bsp server installation we need to be able to pass on additional flags to coursier launch command. Here we are adding option to add additional flags for install command. Additionally cleaned up the code and removed ununsed declarations and imports **Test** - Unit Test - Tested regular installation on local no issues
1 parent a1367ac commit 434e89e

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/server/install.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,22 @@ export class BazelBSPInstaller {
186186
['--bazel-binary', bazelPath],
187187
['--targets', '//your/targets/here/...'],
188188
])
189+
189190
const flagsString = Array.from(installFlags.entries())
190191
.map(([key, value]) => `${key} "${value}"`)
191192
.join(' ')
193+
const additionalInstallFlags = getExtensionSetting(
194+
SettingName.ADDITIONAL_INSTALL_FLAGS
195+
)
196+
const additionalInstallFlagsString = additionalInstallFlags
197+
? additionalInstallFlags.join(' ')
198+
: ''
192199

193200
const javaVersion =
194201
os.platform() === 'darwin' ? TEMURIN_JAVA_17 : OPEN_JDK_JAVA_17
195202
this.outputChannel.appendLine(`Using Java version: ${javaVersion}`)
196-
const installCommand = `"${coursierPath}" launch --jvm ${javaVersion} ${MAVEN_PACKAGE}:${config.serverVersion} -M ${INSTALL_METHOD} -- ${flagsString}`
203+
const installCommand = `"${coursierPath}" launch --jvm ${javaVersion} ${MAVEN_PACKAGE}:${config.serverVersion} -M ${INSTALL_METHOD} ${additionalInstallFlagsString} -- ${flagsString}`
204+
this.outputChannel.appendLine(`Running command: ${installCommand}`)
197205

198206
// Report progress in output channel.
199207
const installProcess = cp.spawn(installCommand, {cwd: root, shell: true})

src/test/suite/install.test.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,23 @@ import * as vscode from 'vscode'
33
import {Test} from '@nestjs/testing'
44
import {beforeEach, afterEach} from 'mocha'
55
import * as sinon from 'sinon'
6-
import {MessageConnection} from 'vscode-jsonrpc'
7-
import * as bsp from '../../bsp/bsp'
86
import * as axios from 'axios'
97
import fs from 'fs/promises'
108
import cp from 'child_process'
119
import * as zlib from 'zlib'
1210
const proxyquire = require('proxyquire')
1311

14-
import {BazelBSPBuildClient} from '../../test-explorer/client'
1512
import {
1613
contextProviderFactory,
1714
outputChannelProvider,
1815
} from '../../custom-providers'
19-
import {BuildServerManager} from '../../server/server-manager'
2016
import {Utils} from '../../utils/utils'
21-
import {createSampleMessageConnection} from './test-utils'
2217
import {BazelBSPInstaller} from '../../server/install'
2318
import * as settings from '../../utils/settings'
24-
import {TestItemFactory} from '../../test-info/test-item-factory'
25-
import {TestCaseStore} from '../../test-explorer/store'
2619

2720
suite('BSP Installer', () => {
2821
let ctx: vscode.ExtensionContext
2922
let bazelBSPInstaller: BazelBSPInstaller
30-
let buildServerStub: sinon.SinonStubbedInstance<BuildServerManager>
31-
let sampleConn: MessageConnection
32-
let clientOutputChannel: vscode.LogOutputChannel
3323
let spawnStub: sinon.SinonStub
3424
let osMock: any
3525

@@ -40,6 +30,7 @@ suite('BSP Installer', () => {
4030
arch: string
4131
isGzipped: boolean
4232
javaVersion: string
33+
additionalInstallFlags?: string[]
4334
}
4435

4536
const setupInstallTest = (config: InstallTestConfig) => {
@@ -61,6 +52,8 @@ suite('BSP Installer', () => {
6152
.returns('2.0.0')
6253
.withArgs(settings.SettingName.SERVER_INSTALL_MODE)
6354
.returns('Prompt')
55+
.withArgs(settings.SettingName.ADDITIONAL_INSTALL_FLAGS)
56+
.returns(config.additionalInstallFlags || [])
6457

6558
sandbox.stub(fs, 'readFile').resolves(
6659
`#if( $pythonEnabled == "true" && $bazel8OrAbove == "true" )
@@ -250,4 +243,24 @@ load("//aspects:utils/utils.bzl", "create_struct", "file_location", "to_file_loc
250243
const actualInstallResult = await bazelBSPInstaller.install()
251244
assert.ok(!actualInstallResult)
252245
})
246+
247+
test('additional install flags', async () => {
248+
const config = {
249+
...testConfigs.macArm64,
250+
additionalInstallFlags: [
251+
'-J-Djavax.net.ssl.trustStore=/path/to/ca/cacerts',
252+
'-J-Djavax.net.ssl.trustStorePassword=xxxx',
253+
],
254+
}
255+
setupInstallTest(config)
256+
257+
await bazelBSPInstaller.install()
258+
259+
assert.equal(spawnStub.callCount, 1)
260+
const spawnCall = spawnStub.getCalls()[0]
261+
const commandString = spawnCall.args[0]
262+
config.additionalInstallFlags.forEach(flag => {
263+
assert.ok(commandString.includes(flag))
264+
})
265+
})
253266
})

src/utils/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum SettingName {
1313
DEBUG_BAZEL_FLAGS = 'debug.bazelFlags',
1414
LAUNCH_CONFIG_NAME = 'debug.launchConfigName',
1515
DEBUG_READY_PATTERN = 'debug.readyPattern',
16+
ADDITIONAL_INSTALL_FLAGS = 'additionalInstallFlags',
1617
}
1718

1819
export interface SettingTypes {
@@ -26,6 +27,7 @@ export interface SettingTypes {
2627
[SettingName.DEBUG_BAZEL_FLAGS]: string[]
2728
[SettingName.LAUNCH_CONFIG_NAME]: string
2829
[SettingName.DEBUG_READY_PATTERN]: string
30+
[SettingName.ADDITIONAL_INSTALL_FLAGS]: string[]
2931
}
3032

3133
export function getExtensionSetting<T extends keyof SettingTypes>(

0 commit comments

Comments
 (0)