Bug 250999 - ShowInConsoleAction failing to open console if DebugUI plugin not loaded
Summary: ShowInConsoleAction failing to open console if DebugUI plugin not loaded
Status: CLOSED FIXED
Alias: None
Product: WTP ServerTools
Classification: WebTools
Component: wst.server (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Tim deBoer CLA
QA Contact: Tim deBoer CLA
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-10-15 15:16 EDT by Rob Stryker CLA
Modified: 2017-10-11 16:28 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Stryker CLA 2008-10-15 15:16:21 EDT
If the debugUI plugin has not already been loaded into the workspace, the ShowInConsoleAction does NOTHING at all. 

While the DebugUI plugin *is* set to load when any one of its classes are referenced, the lazy classloading mechanism in eclipse means that the code referencing a DebugUI class is never reached.   

The code currently is as follows:

	protected void selectProcess(IProcess process) {
		IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
		IConsole[] consoles = consoleManager.getConsoles();
/* NOTE: If DebugUI is not loaded yet, this console array is EMPTY */ 
		int size = consoles.length;
		IConsole console = null;
		for (int i = 0; i < size; i++) {
 /* NOTE:  This is where a DebugUI class is first loaded */
			if (consoles[i] instanceof org.eclipse.debug.ui.console.IConsole) {
				org.eclipse.debug.ui.console.IConsole con = (org.eclipse.debug.ui.console.IConsole) consoles[i];
				if (process.equals(con.getProcess()))
					console = consoles[i];
			}
		}


As you can see, the first time the eclipse classloader would find a DebugUI class is inside a for-loop, which is never reached if DebugUI isn't already loaded.

The fix is to reference this DebugUI class immediately inside the method. As follows:

	protected void selectProcess(IProcess process) {
		Class forceLoad = org.eclipse.debug.ui.console.IConsole.class;
                // etc...

This will force DebugUI to load immediately before searching for the proper console.
Comment 1 Tim deBoer CLA 2008-10-15 17:47:09 EDT
Annoying that this actually happens with lazy loading, and thanks for providing the fix. I went with calling org.eclipse.debug.ui.console.IConsole.class.toString instead because not using the variable caused a compile warning in my workspace. ;-)

Released to WTP 3.1 builds.
Comment 2 Rob Stryker CLA 2009-04-24 00:43:23 EDT
A small change is required here that was overlooked.  Bug caught by Ravi Sankar.

From the email:
-------------

If the console view is already open, then the show in console action from the server view doesn't work. There is just a one liner fix for it. In the class "ShowInConsoleAction",  method selectProcess -> from line 89 onwards,

if (part != null) {
                    page.activate(part);
                    IConsoleView view = (IConsoleView) part.getAdapter(IConsoleView.class);
                    if (view != null) {
                        view.setFocus();
                        view.display(console);
                    }
                }
Adding the line in bold will fix it.

Thanks,
Ravi.

--- 
Note: The line in bold is  page.activate(part);
Comment 3 Tim deBoer CLA 2009-04-29 16:58:41 EDT
Fix released to 3.1 builds.
Comment 4 Tim deBoer CLA 2011-01-20 10:23:42 EST
Closing old bugs.
Comment 5 Eclipse Genie CLA 2017-10-11 16:25:44 EDT
New Gerrit change created: https://git.eclipse.org/r/108689
Comment 6 Eclipse Genie CLA 2017-10-11 16:28:34 EDT
New Gerrit change created: https://git.eclipse.org/r/108780