Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 162415

Summary: Changes to FrameworkCommnadProvider and Framework Console to allow an OSGi console to be launched for a currently running framework
Product: [Eclipse Project] Equinox Reporter: R Keelan <RKeelan>
Component: FrameworkAssignee: equinox.framework-inbox <equinox.framework-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: fcuadrado, pascal, RKeelan, simon_kaegi, tjwatson
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 162420    
Attachments:
Description Flags
Proposed patch that implements the changes described in the bug report
none
New version of propsed patch
none
Console service patch (proposal)
none
Console service patch (proposal)
none
Updated patch
none
patch none

Description R Keelan CLA 2006-10-26 11:37:47 EDT
FrameworkConsole

* Added a new constructor that takes a BundleContext object instead of an OSGi object, because you can only get a handle on the OSGi object when it's first created
* Added a public method to changes input and output streams from System.in and System.out, so they can be sent to the UI
* changed getDefaultStream() so that it only creates in and out if they either is null
* Made disconnect() public, so that the Console can be closed when the corresponding UI object is closed

FrameworkCommandProvider

* Added a new constructor taking a BundleContext object instead of an OSGi, because the corresponding FrameworkConsole may not have an OSGi object
* Chagned StartLevelManager object slImpl to a StartLevel object, so it can be retrieved with a service lookup.
* condPermAdmin and permAdmin might be null if the BundleContext constructor is used, so there's added code to check if these two variables are null before they are used
* _launch and _shutdown do nothing if the OSGi object is null (Because the BundleContext constructor was used), and also aren't listed in Help when osgi is null 
* Calls to osgi.isActive are only used if osgi isn't null, otherwise it checks if the system bundle (bundle 0) is active.
* If osgi is null, osgi.close() isn't called in _close
* Copied the getDataFile() method from Framework, and added it to FrameworkCommandProvider, so that I could use it without access to the osgi object, and without changing the visibility of that method in Framework
Comment 1 R Keelan CLA 2006-10-26 11:41:24 EDT
Created attachment 52758 [details]
Proposed patch that implements the changes described in the bug report
Comment 2 R Keelan CLA 2006-10-27 12:03:03 EDT
Created attachment 52854 [details]
New version of propsed patch

Should not be released yet, I will look into using a service factory.
Comment 3 Thomas Watson CLA 2006-10-27 12:24:25 EDT
(In reply to comment #2)
> Created an attachment (id=52854) [edit]
> New version of propsed patch
> Should not be released yet, I will look into using a service factory.

I have not had time to look at the patch yet.  I'm not sure what you mean by service factory in this context.  I chatted with Pascal about this a little bit.  I think there is a better way to do this.  Instead of exposing internals of the FrameworkCommandProvider and FrameworkConsole and having the ui part construct the FrameworkConsole themselves, it may be better to have a new Console Service interface (org.eclipse.osgi.framework.console.Console).  To start with this Console interface would one simple method.

public String runCommand(String command)

The underlying FrameworkConsole implementation would implement this interface and it would be registered as a service.  The ui part would then just use this service to run commands on the console and get output from the console.  Now here is where a service factory would be good.  The framework would register a Console service factory and would not construct the FrameworkConsole instance until a client got the Console Service from the service registry.

Thoughts?
Comment 4 R Keelan CLA 2006-10-27 17:28:56 EDT
Sounds good to me. runCommand could delegate to doCommand, I think. The only trouble is that doCommand uses a CommandInterpreter to execute the command, which then prints the results directly to the FrameworkConsole's printWriter. Off the top of my head, I can't think of a way to get the results back from the PrintWriter so it can be returned in the String.
Comment 5 Jeff McAffer CLA 2006-10-27 18:45:32 EDT
we should also consider these APIs and usecases as candidates for standardization.  The OSGi CPEG is currently looking at adding a console service to the spec.
Comment 6 Pascal Rapicault CLA 2006-10-30 21:53:26 EST
Tom, Richard and I talked after we talked and he is set to do what you describe in the comment #3. The only difference is the API which will need to take a writer and a reader of some sort to allow the output to be directed appropriately (see what Richard says in comment #4).

Jeff, what is the scope of the console spec work? Is it a way to interact with a console, or is it the definition of some wellknown commands, or both, or none of the above.
Comment 7 Jeff McAffer CLA 2006-10-30 21:59:42 EST
roughly what is a command, how does on supply a command, how does it run etc.  The intent is to allow people to write commands once and use them in any console.
Comment 8 Thomas Watson CLA 2006-10-31 09:11:58 EST
Created attachment 52985 [details]
Console service patch (proposal)

Either way I think the FrameworkCommandInterpreter implementation is going to need to be restructured a bit.  If we are going to do this I think it is possible to have a simple Console service interface that does not need a PrintWriter PrintReader set to it.

This patch splits the common parts of FrameworkCommandInterpreter out into a BaseCommandInterpreter.  This implementation can be used by a ConsoleImpl class to implement the Console.runCommand method.

Note that this patch is a quick hack to give you an idea of what I was thinking.  It needs polishing.
Comment 9 Thomas Watson CLA 2006-10-31 09:14:26 EST
Created attachment 52987 [details]
Console service patch (proposal)

Disregard the last patch, it included some other things from my workspace not related to the console.
Comment 10 R Keelan CLA 2006-11-01 16:34:19 EST
Created attachment 53111 [details]
Updated patch

New patch that incorporates Tom's changes, and provides the console as a service.
Comment 11 Thomas Watson CLA 2006-11-03 08:56:59 EST
Created attachment 53195 [details]
patch

Updated patch from attachment 53111 [details].

- Moved console service registration from EclipseStarter to an AdaptorHook
- Moved -console (osgi.console) property processing from EclispeStarter to an AdaptorHook.  This is what actually starts the "real" osgi> console prompt.
Comment 12 Félix Cuadrado CLA 2006-11-10 12:55:08 EST
Standarization of a Console API for OSGi would be something really useful, and I think the extensibility of Equinox Console is a very valuable feature. However, it can only be used in Equinox, as it is embedded in it. I am developing an extension for adding support to Felix in the new PDE OSGi frameworks extension point, and currently each framework implementation has to supply its own set of bundles for a basic console functionality. 
Would it be possible to extract the console from the system bundle so that it can be used in any framework? That would also probably increase the popularity of defining and offering FrameworkCommands, as they would be OSGi generic instead of Equinox specific.

Comment 13 Jeff McAffer CLA 2006-11-10 21:10:20 EST
What a fine idea.  Felix, are you able to sketch that out in a patch?  Perhaps if we had a new bundle, something like org.eclipse.equinox.console then people could contribute command handlers.  Presumable then the framework could contribute its command handlers simply by registering services.

there is an interesting chicken and egg problem in as much as some command implementations must be in the framework (at least I suspect so).  Those impls need to reference the command interface which, at least in theory, would be supplied by this other bundle.  The console could come as a framework fragment I suppose.  

Felix, if you are going to do some work in this area perhaps a separate bug report would be best.
Comment 14 Félix Cuadrado CLA 2006-11-14 06:10:03 EST
(In reply to comment #13)
> What a fine idea.  Felix, are you able to sketch that out in a patch?  Perhaps
> if we had a new bundle, something like org.eclipse.equinox.console then people
> could contribute command handlers.  Presumable then the framework could
> contribute its command handlers simply by registering services.
> 
> there is an interesting chicken and egg problem in as much as some command
> implementations must be in the framework (at least I suspect so).  Those impls
> need to reference the command interface which, at least in theory, would be
> supplied by this other bundle.  The console could come as a framework fragment
> I suppose.  
> 
> Felix, if you are going to do some work in this area perhaps a separate bug
> report would be best.

I don't think I am the best suited person for working on this refactoring, as I only have experience with Equinox and the console by using them as "black box" bundles, and this type of refactoring requires a thorough knowledge of them. 

About possible solutions, I think it should be feasible to separate completely the console as a bundle. In Apache Felix they have followed this approach with the org.apache.felix.shell service, which is delivered as two bundles (generic service and text ui impl) and works with Felix, Knopfler and Equinox.
Comment 15 Thomas Watson CLA 2009-11-13 10:09:34 EST
Marking as dup of bug 279562 where we did some work to allow ConsoleSession to be registered as a service in order to start a new console session.

*** This bug has been marked as a duplicate of bug 279562 ***