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 52758 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]
Proposed patch that implements the changes described in the bug report
Consolepatch.txt (text/plain), 13.67 KB, created by
R Keelan
on 2006-10-26 11:41:24 EDT
(
hide
)
Description:
Proposed patch that implements the changes described in the bug report
Filename:
MIME Type:
Creator:
R Keelan
Created:
2006-10-26 11:41:24 EDT
Size:
13.67 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 26 Oct 2006 15:42:55 -0000 >@@ -11,11 +11,24 @@ > > package org.eclipse.osgi.framework.internal.core; > >-import java.io.*; >-import java.net.*; >+import java.io.BufferedReader; >+import java.io.BufferedWriter; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.InputStreamReader; >+import java.io.OutputStream; >+import java.io.OutputStreamWriter; >+import java.io.PrintWriter; >+import java.io.Reader; >+import java.io.UnsupportedEncodingException; >+import java.net.ServerSocket; >+import java.net.Socket; >+import java.net.UnknownHostException; >+ > import org.eclipse.osgi.framework.console.CommandInterpreter; > import org.eclipse.osgi.framework.console.CommandProvider; > import org.eclipse.osgi.util.NLS; >+import org.osgi.framework.BundleContext; > import org.osgi.framework.ServiceReference; > import org.osgi.util.tracker.ServiceTracker; > >@@ -83,16 +96,35 @@ > > initialize(); > } >+ >+ 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||out==null) { >+ in = createBufferedReader(System.in); >+ out = createPrintWriter(System.out); >+ } > } > > /** >+ * Change the Input and Output streams for the console. >+ * The default is System.in and System.out >+ */ >+ public void setStreams(InputStream in, OutputStream out) { >+ this.in = createBufferedReader(in); >+ this.out = createPrintWriter(out); >+ } >+ >+ /** > * Open a socket and create input and output streams > * > * @param port number to listen on >@@ -182,16 +214,22 @@ > */ > 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); >+ } >+ > } > > /** >@@ -297,7 +335,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(); >@@ -418,5 +456,4 @@ > this.acceptConnections = acceptConnections; > } > } >- > } >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.28 >diff -u -r1.28 FrameworkCommandProvider.java >--- console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java 31 Aug 2006 20:38:29 -0000 1.28 >+++ console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java 26 Oct 2006 15:42:55 -0000 >@@ -11,23 +11,40 @@ > > package org.eclipse.osgi.framework.internal.core; > >-import java.io.*; >+import java.io.ByteArrayInputStream; >+import java.io.File; >+import java.io.IOException; >+import java.io.InputStream; > import java.lang.reflect.Method; > import java.net.URL; >+import java.security.PrivilegedAction; > import java.security.ProtectionDomain; >-import java.util.*; >+import java.util.ArrayList; >+import java.util.Dictionary; >+import java.util.Enumeration; >+import java.util.Hashtable; >+import java.util.Properties; >+import java.util.Vector; >+import java.security.AccessController; > import org.eclipse.osgi.framework.console.CommandInterpreter; > import org.eclipse.osgi.framework.console.CommandProvider; > import org.eclipse.osgi.framework.launcher.Launcher; > import org.eclipse.osgi.internal.profile.Profile; >-import org.eclipse.osgi.service.resolver.*; >+import org.eclipse.osgi.service.resolver.BundleDescription; >+import org.eclipse.osgi.service.resolver.ExportPackageDescription; >+import org.eclipse.osgi.service.resolver.PlatformAdmin; > import org.eclipse.osgi.util.NLS; >-import org.osgi.framework.*; >+import org.osgi.framework.Bundle; >+import org.osgi.framework.BundleContext; >+import org.osgi.framework.BundleException; >+import org.osgi.framework.ServiceReference; >+import org.osgi.framework.Version; > import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; > import org.osgi.service.condpermadmin.ConditionalPermissionInfo; > 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 >@@ -79,11 +96,11 @@ > public class FrameworkCommandProvider implements CommandProvider { > > /** An instance of the OSGi framework */ >- private OSGi osgi; >+ private OSGi osgi; //TODO Fix references to thsi variable, it might be null > /** 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,13 +118,37 @@ > public FrameworkCommandProvider(OSGi osgi) { > this.osgi = osgi; > context = osgi.getBundleContext(); >- slImpl = osgi.framework.startLevelManager; >+ slImpl = (StartLevel)context.getService(context.getServiceReference(StartLevel.class.getName()));; > condPermAdmin = osgi.framework.condPermAdmin; > permAdmin = osgi.framework.permissionAdmin; > Dictionary props = new Hashtable(); > props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); > context.registerService(CommandProvider.class.getName(), this, props); > } >+ >+ /** >+ * >+ * >+ * @param context >+ */ >+ 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 >+ ref = 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)); >+ context.registerService(CommandProvider.class.getName(), this, props); >+ } > > /** > Answer a string (may be as many lines as you like) with help >@@ -122,8 +163,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 +245,11 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _launch(CommandInterpreter intp) throws Exception { >- osgi.launch(); >+ if(osgi==null) { >+ return; >+ } else { >+ osgi.launch(); >+ } > } > > /** >@@ -211,7 +258,11 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _shutdown(CommandInterpreter intp) throws Exception { >- osgi.shutdown(); >+ if(osgi==null){ >+ return; >+ } else { >+ osgi.shutdown(); >+ } > } > > /** >@@ -408,10 +459,18 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _status(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >- intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ if(osgi==null) { >+ if(context.getBundle(0).getState()==Bundle.ACTIVE) { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ } else { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ } > } else { >- intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ if (osgi.isActive()) { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ } else { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ } > } > intp.println(); > >@@ -605,7 +664,12 @@ > 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; >+ if(osgi==null) { >+ dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$ >+ } else { >+ dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ >+ } > > String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); > >@@ -671,8 +735,12 @@ > 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; >+ if(osgi==null) { >+ dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$ >+ } else { >+ dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ >+ } > String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); > > intp.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root)); >@@ -1046,10 +1114,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(); >@@ -1092,7 +1168,9 @@ > */ > public void _close(CommandInterpreter intp) throws Exception { > intp.println(); >- osgi.close(); >+ if(osgi!=null) { >+ osgi.close(); >+ } > System.exit(0); > } > >@@ -1288,12 +1366,18 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _ss(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >- intp.println(); >- intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ if(osgi==null) { >+ if(context.getBundle(0).getState()==Bundle.ACTIVE) { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ } else { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ } > } else { >- intp.println(); >- intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ if (osgi.isActive()) { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); >+ } else { >+ intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >+ } > } > > AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); >@@ -1768,4 +1852,26 @@ > } > return t.nextToken(); > } >+ >+ /** >+ * >+ * Duplicate of method of same name from Framework.java >+ * >+ * * Creates a <code>File</code> object for a file in the persistent >+ * storage area provided for the bundle by the framework. If the adaptor >+ * does not have file system support, this method will return <code>null</code>. >+ * >+ * <p> >+ * A <code>File</code> object for the base directory of the persistent >+ * storage area provided for the context bundle by the framework can be >+ * obtained by calling this method with the empty string ("") as the >+ * parameter. >+ */ >+ protected File getDataFile(final AbstractBundle bundle, final String filename) { >+ return (File) AccessController.doPrivileged(new PrivilegedAction() { >+ public Object run() { >+ return bundle.getBundleData().getDataFile(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