@@ -23,6 +23,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
2323 private monoVerRegExp = / v e r s i o n ( \d + [ . ] \d + [ . ] \d + ) / gm;
2424
2525 private javaCompilerVerCache : string ;
26+ private javaPathCache : string ;
2627 private javaVerCache : string ;
2728 private javaVerJavaHomeCache : string ;
2829 private javaVerPathCache : string ;
@@ -75,6 +76,13 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
7576 } ) ;
7677 }
7778
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+
7886 public getJavaVersionFromPath ( ) : Promise < string > {
7987 return this . getValueForProperty ( ( ) => this . javaVerPathCache , ( ) : Promise < string > => {
8088 return this . getVersionOfJavaExecutableFromPath ( Constants . JAVA_EXECUTABLE_NAME , SysInfo . JAVA_VERSION_REGEXP ) ;
@@ -509,6 +517,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
509517 result . dotNetVer = await this . hostInfo . dotNetVersion ( ) ;
510518 result . javacVersion = await this . getJavaCompilerVersion ( ) ;
511519 result . javaVersion = await this . getJavaVersion ( ) ;
520+ result . javaPath = await this . getJavaPath ( ) ;
512521 result . adbVer = await this . getAdbVersion ( config && config . androidToolsInfo && config . androidToolsInfo . pathToAdb ) ;
513522 result . androidInstalled = await this . isAndroidInstalled ( ) ;
514523 result . monoVer = await this . getMonoVersion ( ) ;
@@ -521,6 +530,16 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
521530
522531 private async getVersionOfJavaExecutableFromJavaHome ( javaExecutableName : string , regExp : RegExp ) : Promise < string > {
523532 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 ;
524543
525544 try {
526545 const javaHome = process . env [ "JAVA_HOME" ] ;
@@ -529,25 +548,36 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
529548 if ( javaHome ) {
530549 const pathToJavaExecutable = path . join ( javaHome , "bin" , javaExecutableFile ) ;
531550 if ( this . fileSystem . exists ( pathToJavaExecutable ) ) {
532- javaExecutableVersion = await this . getVersionOfJavaExecutable ( pathToJavaExecutable , regExp ) ;
551+ javaExecutablePath = pathToJavaExecutable ;
533552 }
534553 }
535554 } catch ( err ) { /* intentionally left blank */ }
536555
537- return javaExecutableVersion ;
556+ return javaExecutablePath ;
538557 }
539558
540559 private async getVersionOfJavaExecutableFromPath ( javaExecutableName : string , regExp : RegExp ) : Promise < string > {
541560 let javaExecutableVersion : string = null ;
542561
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+
543573 try {
544574 const detectionCommand = this . hostInfo . isWindows ? "where" : "which" ;
545575 // if this command succeeds, we have javac in the PATH. In case it is not there, it will throw an error.
546576 await this . childProcess . exec ( `${ detectionCommand } ${ javaExecutableName } ` ) ;
547- javaExecutableVersion = await this . getVersionOfJavaExecutable ( javaExecutableName , regExp ) ;
577+ javaExecutablePath = javaExecutableName ;
548578 } catch ( err ) { /* intentionally left blank */ }
549579
550- return javaExecutableVersion ;
580+ return javaExecutablePath ;
551581 }
552582
553583 private async getVersionOfJavaExecutable ( executable : string , regExp : RegExp ) : Promise < string > {
0 commit comments