@@ -131,7 +131,8 @@ IEnumerable<JdkInfo> ToJdkInfos (IEnumerable<string> paths, string locator)
131
131
}
132
132
133
133
return ToJdkInfos ( GetPreferredJdkPaths ( ) , "Preferred Registry" )
134
- . Concat ( ToJdkInfos ( GetOpenJdkPaths ( ) , "OpenJDK" ) )
134
+ . Concat ( ToJdkInfos ( GetMicrosoftOpenJdkPaths ( ) , "Microsoft OpenJDK" ) )
135
+ . Concat ( ToJdkInfos ( GetVSAndroidJdkPaths ( ) , @"HKLM\SOFTWARE\Microsoft\VisualStudio\Android@JavaHome" ) )
135
136
. Concat ( ToJdkInfos ( GetKnownOpenJdkPaths ( ) , "Well-known OpenJDK paths" ) )
136
137
. Concat ( ToJdkInfos ( GetOracleJdkPaths ( ) , "Oracle JDK" ) )
137
138
;
@@ -150,7 +151,7 @@ private static IEnumerable<string> GetPreferredJdkPaths ()
150
151
}
151
152
}
152
153
153
- private static IEnumerable < string > GetOpenJdkPaths ( )
154
+ private static IEnumerable < string > GetVSAndroidJdkPaths ( )
154
155
{
155
156
var root = RegistryEx . LocalMachine ;
156
157
var wows = new [ ] { RegistryEx . Wow64 . Key32 , RegistryEx . Wow64 . Key64 } ;
@@ -162,6 +163,54 @@ private static IEnumerable<string> GetOpenJdkPaths ()
162
163
yield return RegistryEx . GetValueString ( root , subKey , valueName , wow ) ?? "" ;
163
164
}
164
165
}
166
+ private static IEnumerable < string > GetMicrosoftOpenJdkPaths ( )
167
+ {
168
+ const string JdkFolderNamePrefix = "jdk-" ;
169
+
170
+ var paths = new List < Tuple < string , Version > > ( ) ;
171
+ var rootPaths = new List < string > {
172
+ Path . Combine ( Environment . ExpandEnvironmentVariables ( "%ProgramW6432%" ) , "Microsoft" ) ,
173
+ Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFilesX86 ) , "Android" , "jdk" ) ,
174
+ } ;
175
+
176
+ foreach ( var rootPath in rootPaths ) {
177
+ if ( ! Directory . Exists ( rootPath ) )
178
+ continue ;
179
+ foreach ( var directoryName in Directory . EnumerateDirectories ( rootPath , $ "{ JdkFolderNamePrefix } *") . ToList ( ) ) {
180
+ var version = ExtractVersion ( directoryName , JdkFolderNamePrefix ) ;
181
+ if ( version == null )
182
+ continue ;
183
+ paths . Add ( Tuple . Create ( directoryName , version ) ) ;
184
+ }
185
+ }
186
+
187
+ return paths . OrderByDescending ( v => v . Item2 )
188
+ . Where ( openJdk => ProcessUtils . FindExecutablesInDirectory ( Path . Combine ( openJdk . Item1 , "bin" ) , _JarSigner ) . Any ( ) )
189
+ . Select ( openJdk => openJdk . Item1 ) ;
190
+ }
191
+
192
+ static Version ? ExtractVersion ( string path , string prefix )
193
+ {
194
+ var name = Path . GetFileName ( path ) ;
195
+ if ( name . Length <= prefix . Length )
196
+ return null ;
197
+ if ( ! name . StartsWith ( prefix , StringComparison . OrdinalIgnoreCase ) )
198
+ return null ;
199
+
200
+ name = name . Substring ( prefix . Length ) ;
201
+ int end = 0 ;
202
+ while ( end < name . Length &&
203
+ ( char . IsDigit ( name [ end ] ) || name [ end ] == '.' ) )
204
+ end ++ ;
205
+
206
+ do {
207
+ if ( Version . TryParse ( name . Substring ( 0 , end ) , out var v ) )
208
+ return v ;
209
+ end = name . LastIndexOf ( '.' , end ) ;
210
+ } while ( end > 0 ) ;
211
+
212
+ return null ;
213
+ }
165
214
166
215
/// <summary>
167
216
/// Locate OpenJDK installations by well known path.
0 commit comments