1
1
import axios from 'axios' ;
2
2
import * as child_process from 'child_process' ;
3
- import { XMLParser } from 'fast-xml-parser' ;
3
+ import { XMLParser } from 'fast-xml-parser' ;
4
4
import * as extract from 'extract-zip' ;
5
5
import * as fs from 'fs' ;
6
6
import * as path from 'path' ;
@@ -98,7 +98,7 @@ export async function installMissingSpl2Requirements(globalStoragePath: string,
98
98
reject ( `Error creating local artifact storage for SPL2, err: ${ err } ` ) ;
99
99
return Promise . resolve ( ) ;
100
100
}
101
-
101
+
102
102
let installedLatestLsp = false ;
103
103
if ( ! lspVersion ) {
104
104
// If we haven't set up a Language Server version prompt use to accept terms
@@ -115,7 +115,7 @@ export async function installMissingSpl2Requirements(globalStoragePath: string,
115
115
const localLspDir = getLocalLspDir ( globalStoragePath ) ;
116
116
fs . rmSync ( localLspDir , { recursive : true , force : true } ) ;
117
117
makeLocalStorage ( globalStoragePath ) ; // recreate directory
118
-
118
+
119
119
await getLatestSpl2Release ( globalStoragePath , progressBar ) ;
120
120
installedLatestLsp = true ;
121
121
} catch ( err ) {
@@ -162,7 +162,7 @@ export async function installMissingSpl2Requirements(globalStoragePath: string,
162
162
function isJavaVersionCompatible ( javaLoc : string ) : boolean {
163
163
let output ;
164
164
try {
165
- const javaVerCmd = child_process . spawnSync ( javaLoc , [ '-version' ] , { encoding : 'utf8' } ) ;
165
+ const javaVerCmd = child_process . spawnSync ( javaLoc , [ '-version' ] , { encoding : 'utf8' } ) ;
166
166
if ( ! javaVerCmd || javaVerCmd . stdout ) {
167
167
return false ;
168
168
}
@@ -223,16 +223,16 @@ async function promptToDownloadJava(): Promise<boolean> {
223
223
) ;
224
224
const downloadAndInstallChoice = 'Download and Install' ;
225
225
const turnOffSPL2Choice = 'Turn off SPL2 support' ;
226
-
226
+
227
227
const popup = window . showInformationMessage (
228
228
promptMessage ,
229
229
{ modal : true } ,
230
230
downloadAndInstallChoice ,
231
231
turnOffSPL2Choice ,
232
232
) ;
233
-
233
+
234
234
const userSelection = ( await popup ) || null ;
235
- switch ( userSelection ) {
235
+ switch ( userSelection ) {
236
236
case downloadAndInstallChoice :
237
237
return Promise . resolve ( true ) ;
238
238
case turnOffSPL2Choice :
@@ -255,7 +255,7 @@ async function installJDK(installDir: string, progressBar: StatusBarItem): Promi
255
255
let os = '' ;
256
256
let ext = 'tar.gz' ;
257
257
// Determine architecture
258
- switch ( process . arch ) {
258
+ switch ( process . arch ) {
259
259
case 'x64' :
260
260
arch = process . arch ;
261
261
break ;
@@ -270,7 +270,7 @@ async function installJDK(installDir: string, progressBar: StatusBarItem): Promi
270
270
) ;
271
271
}
272
272
// Determine OS/extension
273
- switch ( process . platform ) {
273
+ switch ( process . platform ) {
274
274
case 'darwin' :
275
275
os = 'macos' ;
276
276
break ;
@@ -281,10 +281,10 @@ async function installJDK(installDir: string, progressBar: StatusBarItem): Promi
281
281
default :
282
282
os = 'linux' ;
283
283
}
284
-
284
+
285
285
const filename = `amazon-corretto-${ minimumMajorJavaVersion } -${ arch } -${ os } -jdk.${ ext } ` ;
286
286
const url = `https://corretto.aws/downloads/latest/${ filename } ` ;
287
-
287
+
288
288
// Download to installDir
289
289
const downloadedArchive = path . join ( installDir , filename ) ;
290
290
let compressedSize = 0 ;
@@ -351,9 +351,7 @@ async function downloadWithProgress(
351
351
const fileWriter = fs . createWriteStream ( destinationPath ) ;
352
352
353
353
return new Promise ( async ( resolve , reject ) => {
354
- const { data, headers } = await axios ( {
355
- url,
356
- method : 'GET' ,
354
+ const { data, headers } = await axios . get ( url , {
357
355
responseType : 'stream' ,
358
356
transformRequest : ( data , headers ) => {
359
357
// Override defaults set elsewhere for splunkd communication
@@ -364,7 +362,7 @@ async function downloadWithProgress(
364
362
delete headers ?. get [ 'Authorization' ] ;
365
363
delete headers ?. get [ 'Accept' ] ;
366
364
return data ;
367
- } ,
365
+ } ,
368
366
} ) ;
369
367
const totalSize = parseInt ( headers [ 'content-length' ] ) ;
370
368
let totalDownloaded = 0 ;
@@ -395,7 +393,7 @@ async function downloadWithProgress(
395
393
}
396
394
397
395
async function extractZipWithProgress (
398
- zipfilePath :string ,
396
+ zipfilePath : string ,
399
397
extractPath : string ,
400
398
compressedSize : number ,
401
399
progressBar : StatusBarItem ,
@@ -407,17 +405,19 @@ async function extractZipWithProgress(
407
405
// infer this from the read/unzip stream
408
406
let binJavaPath = '' ;
409
407
progressBar . text = `${ progressBarText } ...` ;
410
- await extract ( zipfilePath , { dir : extractPath , onEntry : ( entry , zipfile ) => {
411
- if ( entry . fileName . endsWith ( 'bin/java.exe' ) || entry . fileName . endsWith ( 'bin\\java.exe' ) ) {
412
- binJavaPath = path . join ( extractPath , entry . fileName ) ;
413
- }
414
- readCompressedSize += entry . compressedSize ;
415
- let pct = Math . floor ( readCompressedSize * 100 / compressedSize ) ;
416
- if ( pct >= nextUpdate ) {
417
- progressBar . text = `${ progressBarText } ${ pct } %` ;
418
- nextUpdate = pct + 1 ;
408
+ await extract ( zipfilePath , {
409
+ dir : extractPath , onEntry : ( entry , zipfile ) => {
410
+ if ( entry . fileName . endsWith ( 'bin/java.exe' ) || entry . fileName . endsWith ( 'bin\\java.exe' ) ) {
411
+ binJavaPath = path . join ( extractPath , entry . fileName ) ;
412
+ }
413
+ readCompressedSize += entry . compressedSize ;
414
+ let pct = Math . floor ( readCompressedSize * 100 / compressedSize ) ;
415
+ if ( pct >= nextUpdate ) {
416
+ progressBar . text = `${ progressBarText } ${ pct } %` ;
417
+ nextUpdate = pct + 1 ;
418
+ }
419
419
}
420
- } } ) ;
420
+ } ) ;
421
421
if ( ! binJavaPath ) {
422
422
const jdkDir = fs . readdirSync ( extractPath ) . filter ( fn => fn . startsWith ( 'jdk' ) ) ; // e.g. jdk17.0.7_7
423
423
if ( jdkDir . length === 1 ) {
@@ -431,19 +431,19 @@ async function extractZipWithProgress(
431
431
}
432
432
433
433
async function extractTgzWithProgress (
434
- tgzPath :string ,
435
- extractPath : string ,
436
- compressedSize : number ,
437
- progressBar : StatusBarItem ,
438
- progressBarText : string ,
439
- ) : Promise < string > {
434
+ tgzPath : string ,
435
+ extractPath : string ,
436
+ compressedSize : number ,
437
+ progressBar : StatusBarItem ,
438
+ progressBarText : string ,
439
+ ) : Promise < string > {
440
440
// Create read and unzip streams and listen for individual entry to find bin\java.exe
441
441
let binJavaPath ;
442
442
let readCompressedSize = 0 ;
443
443
let nextUpdate = 1 ;
444
444
445
445
const pipe = util . promisify ( pipeline ) ;
446
-
446
+
447
447
await pipe (
448
448
fs . createReadStream ( tgzPath ) . on ( 'data' , ( chunk ) => {
449
449
readCompressedSize += chunk . length ;
@@ -493,9 +493,9 @@ async function promptToDownloadLsp(alsoInstallJava: boolean): Promise<boolean> {
493
493
viewTermsChoice ,
494
494
turnOffSPL2Choice ,
495
495
) ;
496
-
496
+
497
497
const userSelection = ( await popup ) || null ;
498
- switch ( userSelection ) {
498
+ switch ( userSelection ) {
499
499
case agreeAndContinueChoice :
500
500
// Record preference so user is not asked again
501
501
await workspace . getConfiguration ( ) . update ( configKeyAcceptedTerms , TermsAcceptanceStatus . Accepted , true ) ;
0 commit comments