@@ -23,6 +23,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
23
23
private monoVerRegExp = / v e r s i o n ( \d + [ . ] \d + [ . ] \d + ) / gm;
24
24
25
25
private javaCompilerVerCache : string ;
26
+ private javaPathCache : string ;
26
27
private javaVerCache : string ;
27
28
private javaVerJavaHomeCache : string ;
28
29
private javaVerPathCache : string ;
@@ -75,6 +76,13 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
75
76
} ) ;
76
77
}
77
78
79
+ public getJavaPath ( ) : Promise < string > {
80
+ return this . getValueForProperty ( ( ) => this . javaPathCache , async ( ) : Promise < string > => {
81
+ const javaPath = ( await this . getJavaExecutablePathFromJavaHome ( Constants . JAVA_EXECUTABLE_NAME ) ) || ( await this . getJavaExecutablePathFromPath ( Constants . JAVA_EXECUTABLE_NAME ) ) ;
82
+ return javaPath ;
83
+ } ) ;
84
+ }
85
+
78
86
public getJavaVersionFromPath ( ) : Promise < string > {
79
87
return this . getValueForProperty ( ( ) => this . javaVerPathCache , ( ) : Promise < string > => {
80
88
return this . getVersionOfJavaExecutableFromPath ( Constants . JAVA_EXECUTABLE_NAME , SysInfo . JAVA_VERSION_REGEXP ) ;
@@ -509,6 +517,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
509
517
result . dotNetVer = await this . hostInfo . dotNetVersion ( ) ;
510
518
result . javacVersion = await this . getJavaCompilerVersion ( ) ;
511
519
result . javaVersion = await this . getJavaVersion ( ) ;
520
+ result . javaPath = await this . getJavaPath ( ) ;
512
521
result . adbVer = await this . getAdbVersion ( config && config . androidToolsInfo && config . androidToolsInfo . pathToAdb ) ;
513
522
result . androidInstalled = await this . isAndroidInstalled ( ) ;
514
523
result . monoVer = await this . getMonoVersion ( ) ;
@@ -521,6 +530,16 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
521
530
522
531
private async getVersionOfJavaExecutableFromJavaHome ( javaExecutableName : string , regExp : RegExp ) : Promise < string > {
523
532
let javaExecutableVersion : string = null ;
533
+ const javaExecutablePath = this . getJavaExecutablePathFromJavaHome ( javaExecutableName ) ;
534
+ if ( javaExecutablePath ) {
535
+ javaExecutableVersion = await this . getVersionOfJavaExecutable ( javaExecutablePath , regExp ) ;
536
+ }
537
+
538
+ return javaExecutableVersion ;
539
+ }
540
+
541
+ private getJavaExecutablePathFromJavaHome ( javaExecutableName : string ) : string {
542
+ let javaExecutablePath : string = null ;
524
543
525
544
try {
526
545
const javaHome = process . env [ "JAVA_HOME" ] ;
@@ -529,25 +548,36 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
529
548
if ( javaHome ) {
530
549
const pathToJavaExecutable = path . join ( javaHome , "bin" , javaExecutableFile ) ;
531
550
if ( this . fileSystem . exists ( pathToJavaExecutable ) ) {
532
- javaExecutableVersion = await this . getVersionOfJavaExecutable ( pathToJavaExecutable , regExp ) ;
551
+ javaExecutablePath = pathToJavaExecutable ;
533
552
}
534
553
}
535
554
} catch ( err ) { /* intentionally left blank */ }
536
555
537
- return javaExecutableVersion ;
556
+ return javaExecutablePath ;
538
557
}
539
558
540
559
private async getVersionOfJavaExecutableFromPath ( javaExecutableName : string , regExp : RegExp ) : Promise < string > {
541
560
let javaExecutableVersion : string = null ;
542
561
562
+ const javaExecutablePath = await this . getJavaExecutablePathFromPath ( javaExecutableName ) ;
563
+ if ( javaExecutablePath ) {
564
+ javaExecutableVersion = await this . getVersionOfJavaExecutable ( javaExecutablePath , regExp ) ;
565
+ }
566
+
567
+ return javaExecutableVersion ;
568
+ }
569
+
570
+ private async getJavaExecutablePathFromPath ( javaExecutableName : string ) : Promise < string > {
571
+ let javaExecutablePath : string = null ;
572
+
543
573
try {
544
574
const detectionCommand = this . hostInfo . isWindows ? "where" : "which" ;
545
575
// if this command succeeds, we have javac in the PATH. In case it is not there, it will throw an error.
546
576
await this . childProcess . exec ( `${ detectionCommand } ${ javaExecutableName } ` ) ;
547
- javaExecutableVersion = await this . getVersionOfJavaExecutable ( javaExecutableName , regExp ) ;
577
+ javaExecutablePath = javaExecutableName ;
548
578
} catch ( err ) { /* intentionally left blank */ }
549
579
550
- return javaExecutableVersion ;
580
+ return javaExecutablePath ;
551
581
}
552
582
553
583
private async getVersionOfJavaExecutable ( executable : string , regExp : RegExp ) : Promise < string > {
0 commit comments