@@ -389,56 +389,61 @@ public static SWTBotMenu getAppDebugAsMenu(SWTWorkbenchBot bot, String item) {
389389 * @param buildTool the build tool to be used (Maven or Gradle)
390390 */
391391 public static void setBuildCmdPathInPreferences (SWTWorkbenchBot bot , String buildTool ) {
392-
393- /* Preferences are accessed from a different menu on macOS than on Windows and Linux */
394- /* Currently not possible to access the Preferences dialog panel on macOS so we */
395- /* will return and just use an app configured with a wrapper */
396- if (Platform .getOS ().equals (Platform .OS_MACOSX )) {
397- return ;
392+ // Use Eclipse preference store API directly instead of UI navigation
393+ // This avoids issues with menu accessibility in headless CI environments
394+
395+ String finalMvnExecutableLoc = AbstractLibertyPluginSWTBotTest .getMvnCmdPath ();
396+ String finalGradleExecutableLoc = AbstractLibertyPluginSWTBotTest .getGradleCmdPath ();
397+
398+ // Get the preference store for the Liberty Tools plugin
399+ org .eclipse .jface .preference .IPreferenceStore prefStore =
400+ new org .eclipse .ui .preferences .ScopedPreferenceStore (
401+ org .eclipse .core .runtime .preferences .InstanceScope .INSTANCE ,
402+ "io.openliberty.tools.eclipse.ui" );
403+
404+ if ("Maven" .equals (buildTool )) {
405+ prefStore .setValue ("MVNPATH" , finalMvnExecutableLoc );
406+ } else if ("Gradle" .equals (buildTool )) {
407+ prefStore .setValue ("GRADLEPATH" , finalGradleExecutableLoc );
398408 }
399-
400- String finalMvnExecutableLoc = null ;
401- String finalGradleExecutableLoc = null ;
402- Object locationLabel = null ;
403- Object locationText = null ;
404-
405- finalMvnExecutableLoc = AbstractLibertyPluginSWTBotTest .getMvnCmdPath ();
406- finalGradleExecutableLoc = AbstractLibertyPluginSWTBotTest .getGradleCmdPath ();
407-
408- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
409- goMenuItem (windowMenu , "Preferences" );
410-
411- TreeItem liberty = (TreeItem ) findGlobal ("Liberty" , Option .factory ().widgetClass (TreeItem .class ).build ());
412- go (liberty );
413- if (buildTool == "Maven" ) {
414- locationLabel = findGlobal ("Maven Install Location:" , Option .factory ().widgetClass (Label .class ).build ());
415- locationText = ControlFinder .findControlInRange (locationLabel , Text .class , Direction .EAST );
416- set (locationText , finalMvnExecutableLoc );
417- } else if (buildTool == "Gradle" ) {
418- locationLabel = findGlobal ("Gradle Install Location:" , Option .factory ().widgetClass (Label .class ).build ());
419- locationText = ControlFinder .findControlInRange (locationLabel , Text .class , Direction .EAST );
420- set (locationText , finalGradleExecutableLoc );
409+
410+ // Save the preference store
411+ if (prefStore instanceof org .eclipse .ui .preferences .ScopedPreferenceStore ) {
412+ try {
413+ ((org .eclipse .ui .preferences .ScopedPreferenceStore ) prefStore ).save ();
414+ } catch (java .io .IOException e ) {
415+ System .err .println ("Failed to save preferences: " + e .getMessage ());
416+ e .printStackTrace ();
417+ }
421418 }
422-
423- goGlobal ("Apply and Close" );
424419 }
425420
426421 public static void unsetBuildCmdPathInPreferences (SWTWorkbenchBot bot , String buildTool ) {
427-
428- /* Preferences are accessed from a different menu on macOS than on Windows and Linux */
429- /* Currently not possible to access the Preferences dialog panel on macOS so we */
430- /* will return and just use an app configured with a wrapper */
431- if (Platform .getOS ().equals (Platform .OS_MACOSX )) {
432- return ;
422+ // Use Eclipse preference store API directly instead of UI navigation
423+ // This avoids issues with menu accessibility in headless CI environments
424+
425+ // Get the preference store for the Liberty Tools plugin
426+ org .eclipse .jface .preference .IPreferenceStore prefStore =
427+ new org .eclipse .ui .preferences .ScopedPreferenceStore (
428+ org .eclipse .core .runtime .preferences .InstanceScope .INSTANCE ,
429+ "io.openliberty.tools.eclipse.ui" );
430+
431+ // Reset to default values (empty strings)
432+ if ("Maven" .equals (buildTool )) {
433+ prefStore .setToDefault ("MVNPATH" );
434+ } else if ("Gradle" .equals (buildTool )) {
435+ prefStore .setToDefault ("GRADLEPATH" );
436+ }
437+
438+ // Save the preference store
439+ if (prefStore instanceof org .eclipse .ui .preferences .ScopedPreferenceStore ) {
440+ try {
441+ ((org .eclipse .ui .preferences .ScopedPreferenceStore ) prefStore ).save ();
442+ } catch (java .io .IOException e ) {
443+ System .err .println ("Failed to save preferences: " + e .getMessage ());
444+ e .printStackTrace ();
445+ }
433446 }
434-
435- Object windowMenu = findGlobal ("Window" , Option .factory ().widgetClass (MenuItem .class ).build ());
436- goMenuItem (windowMenu , "Preferences" );
437-
438- findGlobal ("Liberty" , Option .factory ().widgetClass (TreeItem .class ).build ());
439-
440- goGlobal ("Restore Defaults" );
441- goGlobal ("Apply and Close" );
442447 }
443448
444449 /**
0 commit comments