Skip to content

Commit 5a4bf1b

Browse files
committed
debug 2
1 parent 5bb09c1 commit 5a4bf1b

3 files changed

Lines changed: 80 additions & 21 deletions

File tree

tests/src/main/java/io/openliberty/tools/eclipse/test/it/LibertyPluginSWTBotMultiModMavenTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,15 @@ public void testDebugSourceLookupContentSiblingModule() {
300300

301301
boolean jarEntryFound = false;
302302
boolean warEntryFound = false;
303-
303+
SWTBotTreeItem defaultSourceLookupTree = null;
304304
try {
305305
Object libertyConfigTree = getLibertyTreeItemNoBot(configShell);
306306

307307
context(libertyConfigTree, "New Configuration");
308308

309309
openSourceTab(configShell);
310310

311-
SWTBotTreeItem defaultSourceLookupTree = new SWTBotTreeItem((TreeItem) getDefaultSourceLookupTreeItemNoBot(configShell));
311+
defaultSourceLookupTree = new SWTBotTreeItem((TreeItem) getDefaultSourceLookupTreeItemNoBot(configShell));
312312

313313
try {
314314
defaultSourceLookupTree.getNode(MVN_JAR_NAME);
@@ -331,9 +331,11 @@ public void testDebugSourceLookupContentSiblingModule() {
331331

332332
// Validate dependency projects are in source lookup list
333333
Assertions.assertTrue(jarEntryFound,
334-
"The sibling module project, " + MVN_JAR_NAME + ", was not listed in the source lookup list for project " + MVN_APP_NAME);
334+
"The sibling module project, " + MVN_JAR_NAME + ", was not listed in the source lookup list for project " + MVN_APP_NAME + ". Nodes found: "
335+
+ defaultSourceLookupTree.getNodes());
335336
Assertions.assertTrue(warEntryFound,
336-
"The sibling module project, " + MVN_WAR_NAME + ", was not listed in the source lookup list for project " + MVN_APP_NAME);
337+
"The sibling module project, " + MVN_WAR_NAME + ", was not listed in the source lookup list for project " + MVN_APP_NAME + ". Nodes found: "
338+
+ defaultSourceLookupTree.getNodes());
337339

338340
}
339341

@@ -348,14 +350,15 @@ public void testDebugSourceLookupContentParentModule() {
348350
boolean jarEntryFound = false;
349351
boolean warEntryFound = false;
350352

353+
SWTBotTreeItem defaultSourceLookupTree = null;
351354
try {
352355
Object libertyConfigTree = getLibertyTreeItemNoBot(configShell);
353356

354357
context(libertyConfigTree, "New Configuration");
355358

356359
openSourceTab(configShell);
357360

358-
SWTBotTreeItem defaultSourceLookupTree = new SWTBotTreeItem((TreeItem) getDefaultSourceLookupTreeItemNoBot(configShell));
361+
defaultSourceLookupTree = new SWTBotTreeItem((TreeItem) getDefaultSourceLookupTreeItemNoBot(configShell));
359362

360363
// Lookup jar project
361364
try {
@@ -379,9 +382,11 @@ public void testDebugSourceLookupContentParentModule() {
379382

380383
// Validate dependency projects are in source lookup list
381384
Assertions.assertTrue(jarEntryFound,
382-
"The child module project, " + MVN_JAR_NAME + ", was not listed in the source lookup list for project " + MVN_PARENT_NAME);
385+
"The child module project, " + MVN_JAR_NAME + ". was not listed in the source lookup list for project " + MVN_PARENT_NAME + ". Nodes found: "
386+
+ defaultSourceLookupTree.getNodes());
383387
Assertions.assertTrue(warEntryFound,
384-
"The child module project, " + MVN_WAR_NAME + ", was not listed in the source lookup list for project " + MVN_PARENT_NAME);
388+
"The child module project, " + MVN_WAR_NAME + ". was not listed in the source lookup list for project " + MVN_PARENT_NAME + ". Nodes found: "
389+
+ defaultSourceLookupTree.getNodes());
385390

386391
}
387392
}

tests/src/main/java/io/openliberty/tools/eclipse/test/it/utils/MagicWidgetFinder.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,22 @@ public static void context(Object widget, Object... args) {
236236
}
237237

238238
if (!firstAttempt) {
239-
// On retry: dismiss any stale context menu that may still be open, then
240-
// re-select/focus the widget so Eclipse can repopulate dynamic contributions
241-
// (e.g. "Run As" / "Debug As") before we open the menu again.
239+
// On retry: dismiss any stale context menu that may still be open.
242240
dismissOpenContextMenu();
243-
if (widget instanceof TreeItem) {
244-
SWTBotTreeItem ti = (SWTBotTreeItem) obj;
245-
ti.select();
246-
ti.setFocus();
247-
}
248241
pause(2000);
249242
}
250243
firstAttempt = false;
251244

245+
// Always re-select and focus the widget before opening the context menu.
246+
// This ensures the view's selection provider is active so that Eclipse
247+
// populates dynamic contributions (e.g. "Run As" / "Debug As") correctly,
248+
// regardless of whether any other view stole focus since the item was found.
249+
if (widget instanceof TreeItem) {
250+
SWTBotTreeItem ti = (SWTBotTreeItem) obj;
251+
ti.select();
252+
ti.setFocus();
253+
}
254+
252255
try {
253256
for (int x = 0; x < args.length; x++) {
254257
if (x == 0) {

tests/src/main/java/io/openliberty/tools/eclipse/test/it/utils/SWTBotPluginOperations.java

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarPushButton;
5757
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
5858
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
59+
import org.eclipse.ui.IViewPart;
5960
import org.eclipse.ui.IWorkbench;
6061
import org.eclipse.ui.IWorkbenchWindow;
6162
import org.eclipse.ui.PlatformUI;
@@ -968,24 +969,54 @@ public static void checkRunCleanProjectCheckBox(Shell shell, String runDebugConf
968969

969970
public static Object getAppInPackageExplorerTree(String appName) {
970971
openJavaPerspectiveViaMenu();
971-
// Open Package Explorer view using Eclipse API instead of menu navigation
972-
// This is more reliable in headless CI environments
972+
// Open Package Explorer view using Eclipse API instead of menu navigation.
973+
// This is more reliable in headless CI environments.
973974
showPackageExplorerView();
974-
Object peView = MagicWidgetFinder.findGlobal("Package Explorer");
975+
976+
// Obtain the Package Explorer IViewPart directly from the Eclipse API rather
977+
// than using findGlobal(), which scans all visible shells and could match a
978+
// widget in an unrelated view. MagicWidgetFinder already knows how to traverse
979+
// a CommonNavigator (the PE's base class) to reach its TreeItems, so passing
980+
// the IViewPart as the neighbour is both correct and race-condition-free.
981+
IViewPart peView = getPackageExplorerView();
975982

976983
Object project = MagicWidgetFinder.find(appName, peView, Option.factory().useContains(true).widgetClass(TreeItem.class).build());
977-
go(project);
978984

979-
// Wait until the tree item is enabled before returning.
985+
// Select and focus the item so the Package Explorer's selection provider is
986+
// active before the caller opens a context menu. Calling go() here is omitted
987+
// intentionally: the intermediate click it triggers can fire selection-listener
988+
// events that steal focus away before the caller reaches context().
980989
SWTBotTreeItem botItem = new SWTBotTreeItem((TreeItem) project);
981990
SWTBotTestCondition.waitFor(botItem::isEnabled, SWTBotTestCondition.SHORT_WAIT_MS);
982991
botItem.select();
983992
botItem.setFocus();
984-
System.out.println("Explorer item selected: " + botItem.contextMenu().menuItems());
985993

994+
System.out.println("Project in context explorer context menu: " + botItem.contextMenu().menuItems());
986995
return project;
987996
}
988997

998+
/**
999+
* Returns the Package Explorer IViewPart obtained directly from the Eclipse API.
1000+
* Must be called after showPackageExplorerView() has confirmed the view is present.
1001+
*
1002+
* @return The Package Explorer IViewPart, or {@code null} if unavailable.
1003+
*/
1004+
private static IViewPart getPackageExplorerView() {
1005+
final IViewPart[] result = { null };
1006+
Display.getDefault().syncExec(() -> {
1007+
try {
1008+
IWorkbench wb = PlatformUI.getWorkbench();
1009+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
1010+
if (window != null && window.getActivePage() != null) {
1011+
result[0] = window.getActivePage().findView("org.eclipse.jdt.ui.PackageExplorer");
1012+
}
1013+
} catch (Exception e) {
1014+
System.err.println("Failed to retrieve Package Explorer view: " + e.getMessage());
1015+
}
1016+
});
1017+
return result[0];
1018+
}
1019+
9891020
/**
9901021
* Launches the start action using the debug as configuration shortcut.
9911022
*
@@ -1332,6 +1363,26 @@ public static void openSourceTab(Shell shell) {
13321363
SWTBot shellBot = botShell.bot();
13331364
SWTBotCTabItem tabItem = shellBot.cTabItem("Source");
13341365
tabItem.activate().setFocus();
1366+
1367+
// Wait until the Source tab's "Default" source-lookup tree item exists and has been
1368+
// populated with at least one child entry.
1369+
SWTBotTestCondition.waitFor(() -> {
1370+
try {
1371+
Object defaultItem = find("Default", shell);
1372+
if (defaultItem == null) {
1373+
return false;
1374+
}
1375+
SWTBotTreeItem item = new SWTBotTreeItem((TreeItem) defaultItem);
1376+
if (!item.isEnabled()) {
1377+
return false;
1378+
}
1379+
1380+
item.expand();
1381+
return item.getItems().length != 0;
1382+
} catch (Exception e) {
1383+
return false;
1384+
}
1385+
}, SWTBotTestCondition.SHORT_WAIT_MS);
13351386
}
13361387

13371388
/**

0 commit comments

Comments
 (0)