@@ -1435,30 +1435,57 @@ private void tweakJvmOptions(Path configFileRoot) {
1435
1435
Path jvmOptions = configFileRoot .resolve ("jvm.options" );
1436
1436
try {
1437
1437
String content = new String (Files .readAllBytes (jvmOptions ));
1438
- Map <String , String > expansions = jvmOptionExpansions ();
1439
- for (String origin : expansions .keySet ()) {
1440
- if (content .contains (origin ) == false ) {
1441
- throw new IOException ("template property " + origin + " not found in template." );
1438
+ Map <ReplacementKey , String > expansions = jvmOptionExpansions ();
1439
+ for (var entry : expansions .entrySet ()) {
1440
+ ReplacementKey replacement = entry .getKey ();
1441
+ String key = replacement .key ();
1442
+ if (content .contains (key ) == false ) {
1443
+ key = replacement .fallback ();
1444
+ if (content .contains (key ) == false ) {
1445
+ throw new IOException ("Template property '" + replacement + "' not found in template:\n " + content );
1446
+ }
1442
1447
}
1443
- content = content .replace (origin , expansions . get ( origin ));
1448
+ content = content .replace (key , entry . getValue ( ));
1444
1449
}
1445
1450
Files .write (jvmOptions , content .getBytes ());
1446
1451
} catch (IOException ioException ) {
1447
1452
throw new UncheckedIOException (ioException );
1448
1453
}
1449
1454
}
1450
1455
1451
- private Map <String , String > jvmOptionExpansions () {
1452
- Map <String , String > expansions = new HashMap <>();
1456
+ private record ReplacementKey (String key , String fallback ) {}
1457
+
1458
+ private Map <ReplacementKey , String > jvmOptionExpansions () {
1459
+ Map <ReplacementKey , String > expansions = new HashMap <>();
1453
1460
Version version = getVersion ();
1454
- String heapDumpOrigin = getVersion ().onOrAfter ("6.3.0" ) ? "-XX:HeapDumpPath=data" : "-XX:HeapDumpPath=/heap/dump/path" ;
1455
- expansions .put (heapDumpOrigin , "-XX:HeapDumpPath=" + confPathLogs );
1456
- if (version .onOrAfter ("6.2.0" )) {
1457
- expansions .put ("logs/gc.log" , confPathLogs .resolve ("gc.log" ).toString ());
1461
+
1462
+ ReplacementKey heapDumpPathSub ;
1463
+ if (version .before ("8.19.0" ) && version .onOrAfter ("6.3.0" )) {
1464
+ heapDumpPathSub = new ReplacementKey ("-XX:HeapDumpPath=data" , null );
1465
+ } else {
1466
+ // temporarily fall back to the old substitution so both old and new work during backport
1467
+ heapDumpPathSub = new ReplacementKey ("# -XX:HeapDumpPath=/heap/dump/path" , "-XX:HeapDumpPath=data" );
1458
1468
}
1459
- if (getVersion ().getMajor () >= 7 ) {
1460
- expansions .put ("-XX:ErrorFile=logs/hs_err_pid%p.log" , "-XX:ErrorFile=" + confPathLogs .resolve ("hs_err_pid%p.log" ));
1469
+ expansions .put (heapDumpPathSub , "-XX:HeapDumpPath=" + confPathLogs );
1470
+
1471
+ ReplacementKey gcLogSub ;
1472
+ if (version .before ("8.19.0" ) && version .onOrAfter ("6.2.0" )) {
1473
+ gcLogSub = new ReplacementKey ("logs/gc.log" , null );
1474
+ } else {
1475
+ // temporarily check the old substitution first so both old and new work during backport
1476
+ gcLogSub = new ReplacementKey ("logs/gc.log" , "gc.log" );
1461
1477
}
1478
+ expansions .put (gcLogSub , confPathLogs .resolve ("gc.log" ).toString ());
1479
+
1480
+ ReplacementKey errorFileSub ;
1481
+ if (version .before ("8.19.0" ) && version .getMajor () >= 7 ) {
1482
+ errorFileSub = new ReplacementKey ("-XX:ErrorFile=logs/hs_err_pid%p.log" , null );
1483
+ } else {
1484
+ // temporarily check the old substitution first so both old and new work during backport
1485
+ errorFileSub = new ReplacementKey ("-XX:ErrorFile=logs/hs_err_pid%p.log" , "-XX:ErrorFile=hs_err_pid%p.log" );
1486
+ }
1487
+ expansions .put (errorFileSub , "-XX:ErrorFile=" + confPathLogs .resolve ("hs_err_pid%p.log" ));
1488
+
1462
1489
return expansions ;
1463
1490
}
1464
1491
0 commit comments