@@ -37,6 +37,20 @@ function isDotNetSdkInstalled(): boolean {
37
37
}
38
38
}
39
39
40
+ /**
41
+ * Checks if Java runtime is installed and available
42
+ * @returns true if Java is installed, false otherwise
43
+ */
44
+ function isJavaRuntimeInstalled ( ) : boolean {
45
+ try {
46
+ execSync ( 'java -version' , { encoding : 'utf-8' } ) ;
47
+ return true ;
48
+ } catch ( error ) {
49
+ console . error ( 'Error checking Java runtime:' , error ) ;
50
+ return false ;
51
+ }
52
+ }
53
+
40
54
/**
41
55
* Gets the installed Rapicgen .NET tool version
42
56
* @returns The installed version as a string, or null if not installed or version cannot be determined
@@ -294,30 +308,46 @@ function getTypeScriptOutputDirectory(specificationFile: string, generator: stri
294
308
* Available code generators with their command names and display names
295
309
*/
296
310
const generators = [
297
- { command : 'nswag' , displayName : 'NSwag' } ,
298
- { command : 'refitter' , displayName : 'Refitter' } ,
299
- { command : 'openapi' , displayName : 'OpenAPI Generator' } ,
300
- { command : 'kiota' , displayName : 'Microsoft Kiota' } ,
301
- { command : 'swagger' , displayName : 'Swagger Codegen CLI' } ,
302
- { command : 'autorest' , displayName : 'AutoREST' }
311
+ { command : 'nswag' , displayName : 'NSwag' , requiresJava : false } ,
312
+ { command : 'refitter' , displayName : 'Refitter' , requiresJava : false } ,
313
+ { command : 'openapi' , displayName : 'OpenAPI Generator' , requiresJava : true } ,
314
+ { command : 'kiota' , displayName : 'Microsoft Kiota' , requiresJava : false } ,
315
+ { command : 'swagger' , displayName : 'Swagger Codegen CLI' , requiresJava : true } ,
316
+ { command : 'autorest' , displayName : 'AutoREST' , requiresJava : false }
303
317
] ;
304
318
305
319
/**
306
320
* Available TypeScript generators with their command names and display names
307
321
*/
308
322
const typescriptGenerators = [
309
- { command : 'angular' , displayName : 'Angular' } ,
310
- { command : 'aurelia' , displayName : 'Aurelia' } ,
311
- { command : 'axios' , displayName : 'Axios' } ,
312
- { command : 'fetch' , displayName : 'Fetch' } ,
313
- { command : 'inversify' , displayName : 'Inversify' } ,
314
- { command : 'jquery' , displayName : 'JQuery' } ,
315
- { command : 'nestjs' , displayName : 'NestJS' } ,
316
- { command : 'node' , displayName : 'Node' } ,
317
- { command : 'reduxquery' , displayName : 'Redux Query' } ,
318
- { command : 'rxjs' , displayName : 'RxJS' }
323
+ { command : 'angular' , displayName : 'Angular' , requiresJava : true } ,
324
+ { command : 'aurelia' , displayName : 'Aurelia' , requiresJava : true } ,
325
+ { command : 'axios' , displayName : 'Axios' , requiresJava : true } ,
326
+ { command : 'fetch' , displayName : 'Fetch' , requiresJava : true } ,
327
+ { command : 'inversify' , displayName : 'Inversify' , requiresJava : true } ,
328
+ { command : 'jquery' , displayName : 'JQuery' , requiresJava : true } ,
329
+ { command : 'nestjs' , displayName : 'NestJS' , requiresJava : true } ,
330
+ { command : 'node' , displayName : 'Node' , requiresJava : true } ,
331
+ { command : 'reduxquery' , displayName : 'Redux Query' , requiresJava : true } ,
332
+ { command : 'rxjs' , displayName : 'RxJS' , requiresJava : true }
319
333
] ;
320
334
335
+ /**
336
+ * Checks if a generator requires Java runtime
337
+ * @param generator The generator command name
338
+ * @param isTypeScript Whether the generator is for TypeScript
339
+ * @returns true if the generator requires Java, false otherwise
340
+ */
341
+ function generatorRequiresJava ( generator : string , isTypeScript = false ) : boolean {
342
+ if ( isTypeScript ) {
343
+ const typescriptGenerator = typescriptGenerators . find ( g => g . command === generator ) ;
344
+ return typescriptGenerator ?. requiresJava ?? false ;
345
+ } else {
346
+ const csharpGenerator = generators . find ( g => g . command === generator ) ;
347
+ return csharpGenerator ?. requiresJava ?? false ;
348
+ }
349
+ }
350
+
321
351
/**
322
352
* Executes the Rapicgen tool with the given generator and parameters
323
353
* @param generator The generator to use (nswag, refitter, etc.)
@@ -338,6 +368,15 @@ async function executeRapicgen(generator: string, specificationFilePath: string,
338
368
return ;
339
369
}
340
370
371
+ // Check if Java is required and installed
372
+ if ( generatorRequiresJava ( generator ) && ! isJavaRuntimeInstalled ( ) ) {
373
+ vscode . window . showErrorMessage (
374
+ 'Java Runtime Environment (JRE) not found. The selected generator requires Java to be installed. ' +
375
+ 'Please install the latest version of Java from https://adoptium.net/ or https://www.oracle.com/java/technologies/downloads/'
376
+ ) ;
377
+ return ;
378
+ }
379
+
341
380
// Ensure the Rapicgen tool is installed and up-to-date
342
381
const rapicgenAvailable = await ensureRapicgenToolAvailable ( context ) ;
343
382
if ( ! rapicgenAvailable ) {
@@ -430,6 +469,15 @@ async function executeRapicgenTypeScript(generator: string, specificationFilePat
430
469
return ;
431
470
}
432
471
472
+ // Check if Java is required and installed
473
+ if ( generatorRequiresJava ( generator , true ) && ! isJavaRuntimeInstalled ( ) ) {
474
+ vscode . window . showErrorMessage (
475
+ 'Java Runtime Environment (JRE) not found. The selected generator requires Java to be installed. ' +
476
+ 'Please install the latest version of Java from https://adoptium.net/ or https://www.oracle.com/java/technologies/downloads/'
477
+ ) ;
478
+ return ;
479
+ }
480
+
433
481
// Ensure the Rapicgen tool is installed and up-to-date
434
482
const rapicgenAvailable = await ensureRapicgenToolAvailable ( context ) ;
435
483
if ( ! rapicgenAvailable ) {
0 commit comments