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
2525
2626package fish .payara .eclipse .tools .server .sdk .server ;
2727
28+ import java .nio .file .Files ;
29+ import java .nio .file .Path ;
2830import 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 *
0 commit comments