57
57
import java .util .Locale ;
58
58
import java .util .Map ;
59
59
import java .util .Random ;
60
- import java .util .Set ;
61
- import java .util .function .Predicate ;
62
60
import java .util .regex .Matcher ;
63
61
import java .util .regex .Pattern ;
64
62
import java .util .stream .Collectors ;
@@ -68,12 +66,6 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
68
66
private static final Logger LOGGER = Logging .getLogger (GlobalBuildInfoPlugin .class );
69
67
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java" ;
70
68
private static Integer _defaultParallel = null ;
71
- private static Set <File > JAVA_HOME_ENVS = System .getenv ()
72
- .entrySet ()
73
- .stream ()
74
- .filter (entry -> entry .getKey ().matches (".*JAVA.*_HOME" ))
75
- .map (entry -> new File (entry .getValue ()))
76
- .collect (Collectors .toSet ());
77
69
78
70
private final SharedJavaInstallationRegistry javaInstallationRegistry ;
79
71
private JvmMetadataDetector metadataDetector ;
@@ -195,7 +187,7 @@ private JavaVersion determineJavaVersion(String description, File javaHome, Java
195
187
196
188
private InstallationLocation getJavaInstallation (File javaHome ) {
197
189
System .out .println ("javaHome = " + javaHome );
198
- return filteredInstallationLocationStream ().map (i -> {
190
+ return javaInstallationRegistry . listInstallations (). stream ().map (i -> {
199
191
System .out .println ("installation = " + i .getDisplayName ());
200
192
return i ;
201
193
}).filter (installationLocation -> isSameFile (javaHome , installationLocation )).findFirst ().get ();
@@ -214,27 +206,14 @@ private boolean isSameFile(File javaHome, InstallationLocation installationLocat
214
206
* To make transition more reliable we only take env var provided installations into account for now
215
207
*/
216
208
private List <JavaHome > getAvailableJavaVersions () {
217
- return filteredInstallationLocationStream ().map (installationLocation -> {
209
+ return javaInstallationRegistry . listInstallations (). stream ().map (installationLocation -> {
218
210
File installationDir = installationLocation .getLocation ();
219
211
JvmInstallationMetadata metadata = metadataDetector .getMetadata (installationDir );
220
212
int actualVersion = Integer .parseInt (metadata .getLanguageVersion ().getMajorVersion ());
221
213
return JavaHome .of (actualVersion , providers .provider (() -> installationDir ));
222
214
}).collect (Collectors .toList ());
223
215
}
224
216
225
- private Stream <InstallationLocation > filteredInstallationLocationStream () {
226
- // We cannot filter by InstallationLocation#source = env as it is not reliable
227
- // as only the 1st found source type is listed. E.g. jdk detected by sdkman detection AND
228
- // ENV variable does only list one source in a non deterministic way.
229
- return javaInstallationRegistry .listInstallations ()
230
- .stream ()
231
- .filter (
232
- installation -> installation .getSource ().contains ("Current JVM" )
233
- || installation .getSource ().contains ("java_home" )
234
- || JAVA_HOME_ENVS .stream ().anyMatch (envHome -> isSameFile (envHome , installation ))
235
- );
236
- }
237
-
238
217
private static String getTestSeed () {
239
218
String testSeedProperty = System .getProperty ("tests.seed" );
240
219
final String testSeed ;
@@ -461,10 +440,6 @@ private static String readFirstLine(final Path path) throws IOException {
461
440
return firstLine ;
462
441
}
463
442
464
- private static Predicate <InstallationLocation > javaInstallationFilter = installation -> installation .getSource ().contains ("Current JVM" )
465
- || installation .getSource ().contains ("java_home" )
466
- || installation .getSource ().contains ("environment variable" );
467
-
468
443
public static class GitInfo {
469
444
private final String revision ;
470
445
private final String origin ;
0 commit comments