Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 52854 Details for
Bug 162415
Changes to FrameworkCommnadProvider and Framework Console to allow an OSGi console to be launched for a currently running framework
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
New version of propsed patch
Consolepatch.txt (text/plain), 17.14 KB, created by
R Keelan
on 2006-10-27 12:03:03 EDT
(
hide
)
Description:
New version of propsed patch
Filename:
MIME Type:
Creator:
R Keelan
Created:
2006-10-27 12:03:03 EDT
Size:
17.14 KB
patch
obsolete
>Index: console/src/org/eclipse/osgi/framework/internal/core/FrameworkConsole.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkConsole.java,v >retrieving revision 1.16 >diff -u -r1.16 FrameworkConsole.java >--- console/src/org/eclipse/osgi/framework/internal/core/FrameworkConsole.java 16 Jun 2006 13:38:50 -0000 1.16 >+++ console/src/org/eclipse/osgi/framework/internal/core/FrameworkConsole.java 27 Oct 2006 16:04:13 -0000 >@@ -15,7 +15,10 @@ > import java.net.*; > import org.eclipse.osgi.framework.console.CommandInterpreter; > import org.eclipse.osgi.framework.console.CommandProvider; >+import org.eclipse.osgi.framework.log.FrameworkLog; >+import org.eclipse.osgi.framework.log.FrameworkLogEntry; > import org.eclipse.osgi.util.NLS; >+import org.osgi.framework.BundleContext; > import org.osgi.framework.ServiceReference; > import org.osgi.util.tracker.ServiceTracker; > >@@ -53,6 +56,7 @@ > protected ServerSocket ss = null; > protected ConsoleSocketGetter scsg = null; > protected Socket s; >+ protected FrameworkLog log; > > /** > Constructor for FrameworkConsole. >@@ -71,7 +75,7 @@ > /** > Constructor for FrameworkConsole. > It creates a service tracker to track CommandProvider registrations. >- The console InputStream is set to System.in and the console PrintStream is set to System.out. >+ The console InputStream is set to System.in and the console PrintStream is set to System.out, by deafult > @param osgi - an instance of an osgi framework > @param args - any arguments passed on the command line when Launcher is started. > */ >@@ -85,11 +89,48 @@ > } > > /** >+ Constructor for FrameworkConsole. >+ It creates a service tracker to track CommandProvider registrations. >+ The console InputStream is set to System.in and the console PrintStream is set to System.out, by default >+ @param context - BundleContext of the bundle creating this framework console >+ @param args - any arguments passed on the command line when Launcher is started. >+ */ >+ public FrameworkConsole(BundleContext context, String[] args) { >+ this.args = args; >+ this.osgi = null; >+ this.context = context; >+ >+ initialize(); >+ } >+ >+ /** > * Open streams for system.in and system.out > */ > private void getDefaultStreams() { >- in = createBufferedReader(System.in); >- out = createPrintWriter(System.out); >+ if (in == null) >+ in = createBufferedReader(System.in); >+ if (out == null) >+ out = createPrintWriter(System.out); >+ } >+ >+ /** >+ * Change the Input stream for the console. If >+ * The default is System.in >+ * @arg InputStream in - if null, the method does nothing >+ */ >+ public void setIn(InputStream in) { >+ if (in != null) >+ this.in = createBufferedReader(in); >+ } >+ >+ /** >+ * Change the output stream for the console. If >+ * The default is System.out >+ * @arg OutputStream out - if null, the method does nothing >+ */ >+ public void setOut(OutputStream out) { >+ if (out != null) >+ this.out = createPrintWriter(out); > } > > /** >@@ -110,9 +151,9 @@ > in = createBufferedReader(s.getInputStream()); > out = createPrintWriter(s.getOutputStream()); > } catch (UnknownHostException uhe) { >- uhe.printStackTrace(); >+ log(ConsoleMsg.SOCKET_STREAM_UNKOWNHOST, uhe); > } catch (Exception e) { >- e.printStackTrace(); >+ log(ConsoleMsg.SOCKET_STREAM_EXCEPTION, e); > } > } > >@@ -183,14 +224,20 @@ > private void initialize() { > getDefaultStreams(); > >- context = osgi.getBundleContext(); >+ if (osgi != null) { >+ context = osgi.getBundleContext(); >+ } > > // set up a service tracker to track CommandProvider registrations > cptracker = new ServiceTracker(context, CommandProvider.class.getName(), null); > cptracker.open(); > > // register the OSGi command provider >- osgicp = new FrameworkCommandProvider(osgi); >+ if (osgi != null) { >+ osgicp = new FrameworkCommandProvider(osgi); >+ } else { >+ osgicp = new FrameworkCommandProvider(context); >+ } > > } > >@@ -210,7 +257,7 @@ > console(); > } > } catch (IOException e) { >- e.printStackTrace(out); >+ log(ConsoleMsg.CONSOLE_RUN, e); > } > } > >@@ -297,7 +344,7 @@ > * will cause the console to close from a telnet session. > */ > >- void disconnect() throws IOException { >+ public void disconnect() throws IOException { > disconnect = true; > out.close(); > in.close(); >@@ -342,6 +389,49 @@ > } > > /** >+ * Lazily initializes a FrameworkLog for private use >+ */ >+ protected FrameworkLog getLog() { >+ if (log == null) >+ log = (FrameworkLog) context.getService(context.getServiceReference(FrameworkLog.class.getName())); >+ return log; >+ } >+ >+ /** >+ * Adds to log with given entry and message >+ */ >+ protected void log(String entry, String message) { >+ log(entry, message, null); >+ } >+ >+ /** >+ * Adds to log with given entry and message, and throwable >+ */ >+ protected void log(String entry, String message, Throwable exception) { >+ FrameworkLog localLog = getLog(); >+ if (localLog == null) { >+ System.err.println(ConsoleMsg.LOG_ENTRY + entry); >+ System.err.println(ConsoleMsg.LOG_MESSAGE + message); >+ if (exception != null) >+ exception.printStackTrace(); >+ } else { >+ localLog.log(new FrameworkLogEntry(entry, message, 0, exception, null)); >+ } >+ } >+ >+ /** >+ * Adds to log with given entry, and throwable >+ * Entry is a string describing the context of the throwable. >+ * If the throwable has no message, message is the Throwable's class name >+ */ >+ protected void log(String entry, Throwable exception) { >+ String message = exception.getMessage(); >+ if (message == null) >+ message = exception.getClass().getName(); >+ log(entry, message, exception); >+ } >+ >+ /** > * ConsoleSocketGetter - provides a Thread that listens on the port > * for FrameworkConsole. If acceptConnections is set to true then > * the thread will notify the getSocket method to return the socket. >@@ -389,7 +479,7 @@ > } > } > } catch (Exception e) { >- e.printStackTrace(); >+ log(ConsoleMsg.SOCKET_RUN, e); > } > > } >@@ -418,5 +508,4 @@ > this.acceptConnections = acceptConnections; > } > } >- > } >Index: console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties,v >retrieving revision 1.9 >diff -u -r1.9 ConsoleMessages.properties >--- console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties 25 Feb 2005 21:34:27 -0000 1.9 >+++ console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties 27 Oct 2006 16:04:12 -0000 >@@ -13,6 +13,7 @@ > CONSOLE_PROMPT=osgi> > CONSOLE_ID=id > CONSOLE_MORE=-- More...Press Enter to Continue... >+CONSOLE_RUN=Exception Startring the console thread. > CONSOLE_HELP_CONTROLLING_CONSOLE_HEADING=---Controlling the Console--- > CONSOLE_HELP_MORE=More prompt for console output > CONSOLE_HELP_DISCONNECT=Disconnects from telnet session >@@ -152,3 +153,8 @@ > CONSOLE_REQUIRES_MESSAGE=[requires] > CONSOLE_HELP_PROFILE_HEADING=---Controlling the Profiling--- > CONSOLE_HELP_PROFILELOG_DESCRIPTION=Display & flush the profile log messages >+SOCKET_RUN=Exception listening for connections. >+SOCKET_STREAM_UNKOWNHOST=UnknownHostException attempting to open a socket. >+SOCKET_STREAM_EXCEPTION=Exception attempting to open a socket. >+LOG_ENTRY=\!ENTRY >+LOG_MESSAGE=\!MESSAGE >Index: console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java,v >retrieving revision 1.29 >diff -u -r1.29 FrameworkCommandProvider.java >--- console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java 24 Oct 2006 20:28:21 -0000 1.29 >+++ console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java 27 Oct 2006 16:04:13 -0000 >@@ -28,6 +28,7 @@ > import org.osgi.service.packageadmin.PackageAdmin; > import org.osgi.service.packageadmin.RequiredBundle; > import org.osgi.service.permissionadmin.PermissionAdmin; >+import org.osgi.service.startlevel.StartLevel; > > /** > * This class provides methods to execute commands from the command line. It registers >@@ -83,7 +84,7 @@ > /** The system bundle context */ > private org.osgi.framework.BundleContext context; > /** The start level implementation */ >- private StartLevelManager slImpl; >+ private StartLevel slImpl; > private ConditionalPermissionAdmin condPermAdmin; > private PermissionAdmin permAdmin; > >@@ -101,7 +102,10 @@ > public FrameworkCommandProvider(OSGi osgi) { > this.osgi = osgi; > context = osgi.getBundleContext(); >- slImpl = osgi.framework.startLevelManager; >+ if (context == null) { >+ System.err.println("Could not find OSGi's bundle context"); >+ } >+ slImpl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName())); > condPermAdmin = osgi.framework.condPermAdmin; > permAdmin = osgi.framework.permissionAdmin; > Dictionary props = new Hashtable(); >@@ -110,6 +114,33 @@ > } > > /** >+ * Constructor. >+ * >+ * It registers itself as a CommandProvider with the highest ranking possible. Takes BundleContext object >+ * instead of OSGi object. This means that some commands will be disabled, specifically, _launch and _shutdown >+ * >+ * @param context The BundleContext of the plugin attempting to create this FrameworkCommandProvider, or that of the plugin that created the FrameworkConsole that is creating this. >+ */ >+ public FrameworkCommandProvider(BundleContext context) { >+ this.osgi = null; >+ this.context = context; >+ slImpl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName())); >+ ServiceReference ref = context.getServiceReference(ConditionalPermissionAdmin.class.getName()); >+ if (ref != null) >+ condPermAdmin = (ConditionalPermissionAdmin) context.getService(ref); >+ else >+ condPermAdmin = null; >+ ref = context.getServiceReference(PermissionAdmin.class.getName()); >+ if (ref != null) >+ permAdmin = (PermissionAdmin) context.getService(ref); >+ else >+ permAdmin = null; >+ Dictionary props = new Hashtable(); >+ props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); >+ this.context.registerService(CommandProvider.class.getName(), this, props); >+ } >+ >+ /** > Answer a string (may be as many lines as you like) with help > texts that explain the command. This getHelp() method uses the > ConsoleMsg class to obtain the correct NLS data to display to the user. >@@ -122,8 +153,10 @@ > help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER); > help.append(newline); > addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help); >- addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ >- addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ >+ if (osgi != null) { >+ addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ >+ addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ >+ } > addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ > addCommand("exit", ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ > addCommand("gc", ConsoleMsg.CONSOLE_HELP_GC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ >@@ -202,7 +235,9 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _launch(CommandInterpreter intp) throws Exception { >- osgi.launch(); >+ if (osgi != null) >+ osgi.launch(); >+ > } > > /** >@@ -211,7 +246,9 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _shutdown(CommandInterpreter intp) throws Exception { >- osgi.shutdown(); >+ if (osgi != null) >+ osgi.shutdown(); >+ > } > > /** >@@ -408,7 +445,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _status(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >+ if (osgi != null && osgi.isActive() || osgi == null && context.getBundle(0).getState() == Bundle.ACTIVE) { > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); > } else { > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >@@ -605,7 +642,7 @@ > intp.print(", "); //$NON-NLS-1$ > intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); > if (id != 0) { >- File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ >+ File dataRoot = Framework.getDataFile(bundle, ""); //$NON-NLS-1$ > > String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); > >@@ -671,7 +708,7 @@ > intp.print(", "); //$NON-NLS-1$ > intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); > if (id != 0) { >- File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ >+ File dataRoot = Framework.getDataFile(bundle, ""); //$NON-NLS-1$ > > String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); > >@@ -1044,10 +1081,18 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _init(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >- intp.print(newline); >- intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); >- return; >+ if (osgi == null) { >+ if (context.getBundle(0).getState() == Bundle.ACTIVE) { >+ intp.print(newline); >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); >+ return; >+ } >+ } else { >+ if (osgi.isActive()) { >+ intp.print(newline); >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); >+ return; >+ } > } > > AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); >@@ -1090,7 +1135,9 @@ > */ > public void _close(CommandInterpreter intp) throws Exception { > intp.println(); >- osgi.close(); >+ if (osgi != null) { >+ osgi.close(); >+ } > System.exit(0); > } > >@@ -1286,7 +1333,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _ss(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >+ if (osgi != null && osgi.isActive() || osgi == null && context.getBundle(0).getState() == Bundle.ACTIVE) { > intp.println(); > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); > } else { >Index: console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java,v >retrieving revision 1.7 >diff -u -r1.7 ConsoleMsg.java >--- console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java 25 Feb 2005 21:34:26 -0000 1.7 >+++ console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java 27 Oct 2006 16:04:12 -0000 >@@ -27,6 +27,8 @@ > public static String CONSOLE_CONFIRM_DISCONNECT; > public static String CONSOLE_CONFIRM; > public static String CONSOLE_CONFIRM_VALUES; >+ >+ public static String CONSOLE_RUN; > public static String CONSOLE_Y; > public static String CONSOLE_N; > public static String CONSOLE_PROMPT_DEFAULT; >@@ -80,6 +82,12 @@ > public static String CONSOLE_HELP_COMMAND_ARGUMENT_DESCRIPTION; > public static String CONSOLE_HELP_EXEC_COMMAND_DESCRIPTION; > public static String CONSOLE_HELP_FORK_COMMAND_DESCRIPTION; >+ >+ public static String LOG_ENTRY; >+ public static String LOG_MESSAGE; >+ public static String SOCKET_RUN; >+ public static String SOCKET_STREAM_EXCEPTION; >+ public static String SOCKET_STREAM_UNKOWNHOST; > public static String STARTLEVEL_HELP_HEADING; > public static String CONSOLE_HELP_OPTIONAL_IDLOCATION_ARGUMENT_DESCRIPTION; > public static String STARTLEVEL_HELP_SL; >Index: core/framework/org/eclipse/osgi/framework/internal/core/Framework.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/Framework.java,v >retrieving revision 1.105 >diff -u -r1.105 Framework.java >--- core/framework/org/eclipse/osgi/framework/internal/core/Framework.java 26 Oct 2006 14:55:30 -0000 1.105 >+++ core/framework/org/eclipse/osgi/framework/internal/core/Framework.java 27 Oct 2006 16:04:13 -0000 >@@ -1327,7 +1327,7 @@ > * obtained by calling this method with the empty string ("") as the > * parameter. > */ >- protected File getDataFile(final AbstractBundle bundle, final String filename) { >+ public static File getDataFile(final AbstractBundle bundle, final String filename) { > return (File) AccessController.doPrivileged(new GetDataFileAction(bundle, filename)); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 162415
:
52758
|
52854
|
52985
|
52987
|
53111
|
53195