@@ -91,6 +91,10 @@ public static JdkInstallation getJdk(Predicate<JdkInstallation> filter, Supplier
91
91
.orElseThrow (() -> new NoSuchElementException (String .format ("%s%nAvailable JDK: %s" , message .get (), jdks )));
92
92
}
93
93
94
+ public static List <JdkInstallation > getJdks () {
95
+ return JDKS .get ();
96
+ }
97
+
94
98
/**
95
99
* JDK detection strategy.
96
100
*/
@@ -125,7 +129,10 @@ public static Selector builder() {
125
129
}
126
130
127
131
public static Selector from (JavaVersion javaVersion ) {
128
- return builder ().and (it -> javaVersion .getVersionDetector ().test (it .getVersion ()))
132
+
133
+ return builder ()
134
+ .and (it -> javaVersion .getVersionDetector ().test (it .getVersion ())
135
+ && javaVersion .getImplementor ().test (it .getImplementor ()))
129
136
.message ("Cannot find Java " + javaVersion .getName ());
130
137
}
131
138
@@ -184,10 +191,29 @@ public List<JdkInstallation> detect() {
184
191
version = Version .parse (candidateVersion );
185
192
}
186
193
187
- return new JdkInstallation (version , it .getName (), it );
194
+ String implementor = normalizeImplementor (parseImplementor (it ));
195
+
196
+ return new JdkInstallation (version , toDisplayName (implementor , candidateVersion ), implementor , it );
188
197
189
198
}).collect (Collectors .toList ());
190
199
}
200
+
201
+ @ SneakyThrows
202
+ private String parseImplementor (File candidateHome ) {
203
+
204
+ List <String > release = FileUtils .readLines (new File (candidateHome , "release" ));
205
+
206
+ for (String line : release ) {
207
+
208
+ if (line .startsWith ("IMPLEMENTOR=" )) {
209
+ String substring = line .substring (line .indexOf ("=\" " ));
210
+ substring = substring .substring (2 , substring .length () - 1 );
211
+ return substring ;
212
+ }
213
+ }
214
+
215
+ return "?" ;
216
+ }
191
217
}
192
218
193
219
/**
@@ -208,7 +234,8 @@ public boolean isAvailable() {
208
234
public List <JdkInstallation > detect () {
209
235
210
236
return Collections
211
- .singletonList (new JdkInstallation (JavaVersion .parse (javaVersion ), javaVendor + " " + javaVersion , javaHome ));
237
+ .singletonList (new JdkInstallation (JavaVersion .parse (javaVersion ), toDisplayName (javaVendor , javaVersion ),
238
+ normalizeImplementor (javaVendor ), javaHome ));
212
239
}
213
240
}
214
241
@@ -252,14 +279,17 @@ public List<JdkInstallation> detect() {
252
279
String jvmHomePath = dict .get ("JVMHomePath" ).toJavaObject (String .class );
253
280
String name = dict .get ("JVMName" ).toJavaObject (String .class );
254
281
String version = dict .get ("JVMVersion" ).toJavaObject (String .class );
282
+ String vendor = dict .get ("JVMVendor" ).toJavaObject (String .class );
255
283
256
284
Matcher matcher = VERSION .matcher (version );
257
285
if (!matcher .find ()) {
258
286
throw new IllegalArgumentException ("Cannot determine JVM version number from JVMVersion " + version
259
287
+ ". This should not happen in an ideal world, check the VERSION regex." );
260
288
}
261
289
262
- return new JdkInstallation (JavaVersion .parse (matcher .group (1 )), name , new File (jvmHomePath ));
290
+ String implementor = normalizeImplementor (vendor );
291
+ return new JdkInstallation (JavaVersion .parse (matcher .group (1 )), toDisplayName (implementor , version ),
292
+ implementor , new File (jvmHomePath ));
263
293
264
294
}).collect (Collectors .toList ());
265
295
}
@@ -270,11 +300,34 @@ public static class JdkInstallation implements Comparable<JdkInstallation> {
270
300
271
301
Version version ;
272
302
String name ;
303
+ String implementor ;
273
304
File home ;
274
305
275
306
@ Override
276
307
public int compareTo (JdkInstallation o ) {
277
308
return this .version .compareTo (o .version );
278
309
}
279
310
}
311
+
312
+ static String normalizeImplementor (String implementor ) {
313
+
314
+ if (implementor .equals ("Eclipse Adoptium" )) {
315
+ return "Eclipse Temurin" ;
316
+ }
317
+
318
+ if (implementor .equals ("Eclipse Foundation" )) {
319
+ return "Eclipse Temurin" ;
320
+ }
321
+
322
+ return implementor ;
323
+ }
324
+
325
+ static String toDisplayName (String implementor , String version ) {
326
+
327
+ if (implementor .startsWith ("Oracle" )) {
328
+ implementor = "Oracle Java" ;
329
+ }
330
+
331
+ return implementor + " " + version ;
332
+ }
280
333
}
0 commit comments