Skip to content

Commit 01001df

Browse files
authored
Merge pull request #92 from jGauravGupta/FISH-12969
FISH-12969 Eclipse IDE - Server startup fails because of CRaCCheckpointTo
2 parents 849a3eb + ba3efa2 commit 01001df

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/sdk/server/JDK.java

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
/******************************************************************************
18-
* Copyright (c) 2018-2022 Payara Foundation
18+
* Copyright (c) 2018-2026 Payara Foundation
1919
* All rights reserved. This program and the accompanying materials
2020
* are made available under the terms of the Eclipse Public License v2.0
2121
* which accompanies this distribution, and is available at
@@ -25,6 +25,8 @@
2525

2626
package fish.payara.eclipse.tools.server.sdk.server;
2727

28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
2830
import java.util.Optional;
2931

3032
/**
@@ -239,11 +241,39 @@ public static Version getVersion() {
239241
return new Version(major, minor, subminor, update, vendor);
240242
}
241243

242-
public static boolean isCorrectJDK(Optional<Version> minVersion, Optional<Version> maxVersion) {
243-
return isCorrectJDK(JDK_VERSION, Optional.empty(), minVersion, maxVersion);
244+
public static boolean isCorrectJDK(Optional<Version> minVersion,
245+
Optional<Version> maxVersion) {
246+
return isCorrectJDK(
247+
JDK_VERSION,
248+
Optional.empty(),
249+
minVersion,
250+
maxVersion,
251+
null,
252+
null
253+
);
244254
}
245255

246-
public static boolean isCorrectJDK(Version version, Optional<String> vendor, Optional<Version> minVersion, Optional<Version> maxVersion) {
256+
/**
257+
* Checks whether a JVM option is applicable for the given JDK.
258+
* Applies vendor, min/max version checks and additionally validates
259+
* CRaC-related options against the selected JDK.
260+
*
261+
* @param version JDK version used to start the server
262+
* @param vendor optional vendor restriction
263+
* @param minVersion optional minimum supported JDK version
264+
* @param maxVersion optional maximum supported JDK version
265+
* @param jvmOption JVM option string from domain.xml
266+
* @param javaHome Java home of the selected server JDK
267+
* @return true if the option is valid for the given JDK
268+
*/
269+
public static boolean isCorrectJDK(
270+
Version version,
271+
Optional<String> vendor,
272+
Optional<Version> minVersion,
273+
Optional<Version> maxVersion,
274+
String jvmOption,
275+
String javaHome) {
276+
247277
boolean correctJDK = true;
248278

249279
if (vendor.isPresent()) {
@@ -253,16 +283,39 @@ public static boolean isCorrectJDK(Version version, Optional<String> vendor, Opt
253283
correctJDK = false;
254284
}
255285
}
286+
256287
if (correctJDK && minVersion.isPresent()) {
257288
correctJDK = version.newerOrEquals(minVersion.get());
258289
}
290+
259291
if (correctJDK && maxVersion.isPresent()) {
260292
correctJDK = version.olderOrEquals(maxVersion.get());
261293
}
262294

295+
if (correctJDK
296+
&& jvmOption != null
297+
&& jvmOption.matches("^-XX:[+-]?CRaC.*")) {
298+
299+
correctJDK = isCRaCJDK(javaHome);
300+
}
301+
263302
return correctJDK;
264303
}
265304

305+
/**
306+
* Checks whether the given JDK installation supports CRaC by verifying the
307+
* presence of the lib/criu directory.
308+
*
309+
* @param javaHome Java home directory to check
310+
* @return true if the JDK appears to be CRaC-enabled
311+
*/
312+
public static boolean isCRaCJDK(String javaHome) {
313+
return Optional.ofNullable(javaHome)
314+
.map(home -> Path.of(home, "lib", "criu"))
315+
.map(Files::exists)
316+
.orElse(false);
317+
}
318+
266319
/**
267320
* No instances are allowed so it is pointless to override toString
268321
*

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/sdk/server/ServerTasks.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
******************************************************************************/
99

1010
/******************************************************************************
11-
* Copyright (c) 2018-2022 Payara Foundation
11+
* Copyright (c) 2018-2026 Payara Foundation
1212
* All rights reserved. This program and the accompanying materials
1313
* are made available under the terms of the Eclipse Public License v2.0
1414
* which accompanies this distribution, and is available at
@@ -152,12 +152,20 @@ public static ResultProcess startServer(PayaraServer server, StartupArgs args, S
152152

153153
JDK.Version jdkVersion = getJavaVersion(args);
154154
JDK.Version targetJDKVersion = jdkVersion != null ? jdkVersion : JDK_VERSION;
155-
155+
String selectedJavaHome = jdkVersion != null
156+
? args.getJavaHome()
157+
: System.getProperty("java.home");
156158
// Filter out all options that are not applicable
157159
List<String> optList
158160
= jvmConfigReader.getJvmOptions()
159161
.stream()
160-
.filter(fullOption -> isCorrectJDK(targetJDKVersion, fullOption.vendor, fullOption.minVersion, fullOption.maxVersion))
162+
.filter(fullOption -> isCorrectJDK(
163+
targetJDKVersion,
164+
fullOption.vendor,
165+
fullOption.minVersion,
166+
fullOption.maxVersion,
167+
fullOption.option,
168+
selectedJavaHome))
161169
.map(fullOption -> fullOption.option)
162170
.collect(toList());
163171

0 commit comments

Comments
 (0)