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 52985 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]
Console service patch (proposal)
162415_org.eclipse.osgi.patch (text/plain), 40.53 KB, created by
Thomas Watson
on 2006-10-31 09:11:58 EST
(
hide
)
Description:
Console service patch (proposal)
Filename:
MIME Type:
Creator:
Thomas Watson
Created:
2006-10-31 09:11:58 EST
Size:
40.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.osgi >Index: core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java,v >retrieving revision 1.80 >diff -u -r1.80 BundleLoader.java >--- core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java 21 Aug 2006 18:59:00 -0000 1.80 >+++ core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java 31 Oct 2006 14:12:38 -0000 >@@ -351,6 +351,7 @@ > if (Debug.DEBUG && Debug.DEBUG_LOADER) > Debug.println("BundleLoader[" + this + "].loadBundleClass(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > String pkgName = getPackageName(name); >+ boolean bootDelegation = false; > // follow the OSGi delegation model > if (checkParent && parent != null) { > if (name.startsWith(JAVA_PACKAGE)) >@@ -363,6 +364,7 @@ > return parent.loadClass(name); > } catch (ClassNotFoundException cnfe) { > // we want to continue >+ bootDelegation = true; > } > } > >@@ -389,14 +391,30 @@ > // 6) attempt to find a dynamic import source; only do this if a required source was not found > if (source == null) { > source = findDynamicSource(pkgName); >- if (source != null) >+ if (source != null) { > result = source.loadClass(name); >+ if (result != null) >+ return result; >+ // must throw CNFE if dynamic import source does not have the class >+ throw new ClassNotFoundException(name); >+ } > } >+ >+ // hack to support backwards compatibiility for bootdelegation >+ if (checkParent && !bootDelegation && bundle.framework.compatibiltyBootDelegation) { >+ bootDelegation = true; >+ try { >+ return parent.loadClass(name); >+ } catch (ClassNotFoundException cnfe) { >+ // we want to continue >+ } >+ } >+ > // do buddy policy loading > if (result == null && policy != null) > result = policy.doBuddyClassLoading(name); > // last resort; do class context trick to work around VM bugs >- if (result == null && findParentResource(name)) >+ if (result == null && !bootDelegation && findParentResource(name)) > result = parent.loadClass(name); > if (result == null) > throw new ClassNotFoundException(name); >@@ -451,6 +469,7 @@ > name = name.substring(1); /* remove leading slash before search */ > String pkgName = getResourcePackageName(name); > // follow the OSGi delegation model >+ boolean bootDelegation = false; > // First check the parent classloader for system resources, if it is a java resource. > if (checkParent && parent != null) { > if (pkgName.startsWith(JAVA_PACKAGE)) >@@ -462,6 +481,7 @@ > URL result = parent.getResource(name); > if (result != null) > return result; >+ bootDelegation = true; > } > } > >@@ -485,13 +505,21 @@ > if (source == null) { > source = findDynamicSource(pkgName); > if (source != null) >- result = source.getResource(name); >+ // must return the result of the dynamic import and do not continue >+ return source.getResource(name); >+ } >+ >+ // hack to support backwards compatibiility for bootdelegation >+ if (checkParent && !bootDelegation && bundle.framework.compatibiltyBootDelegation) { >+ bootDelegation = true; >+ result = parent.getResource(name); > } >+ > // do buddy policy loading > if (result == null && policy != null) > return policy.doBuddyResourceLoading(name); > // last resort; do class context trick to work around VM bugs >- if (result == null && findParentResource(name)) >+ if (result == null && !bootDelegation && findParentResource(name)) > result = parent.getResource(name); > return result; > } >@@ -949,7 +977,7 @@ > }); > } > >- private static final class ClassContext extends SecurityManager { >+ static final class ClassContext extends SecurityManager { > // need to make this method public > public Class[] getClassContext() { > return super.getClassContext(); >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 31 Oct 2006 14:12:39 -0000 >@@ -99,6 +99,7 @@ > String[] bootDelegationStems; > boolean bootDelegateAll = false; > boolean contextBootDelegation = "true".equals(FrameworkProperties.getProperty("osgi.context.bootdelegation", "true")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ boolean compatibiltyBootDelegation = "true".equals(FrameworkProperties.getProperty("osgi.compatibility.bootdelegation", "true")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ > > /** > * The AliasMapper used to alias OS Names. >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 31 Oct 2006 14:12:38 -0000 >@@ -36,8 +36,6 @@ > protected OSGi osgi; > /** The command line arguments passed at launch time*/ > protected String[] args; >- /** The OSGi Command Provider */ >- protected CommandProvider osgicp; > /** A tracker containing the service object of all registered command providers */ > protected ServiceTracker cptracker; > >@@ -190,7 +188,7 @@ > cptracker.open(); > > // register the OSGi command provider >- osgicp = new FrameworkCommandProvider(osgi); >+ FrameworkCommandProvider.getInstance(osgi.framework); > > } > >Index: console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java,v >retrieving revision 1.14 >diff -u -r1.14 FrameworkCommandInterpreter.java >--- console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java 10 May 2006 16:17:28 -0000 1.14 >+++ console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandInterpreter.java 31 Oct 2006 14:12:38 -0000 >@@ -11,14 +11,8 @@ > > package org.eclipse.osgi.framework.internal.core; > >-import java.io.*; >-import java.lang.reflect.*; >-import java.net.URL; >-import java.util.*; > import org.eclipse.osgi.framework.console.CommandInterpreter; >-import org.eclipse.osgi.framework.console.CommandProvider; >-import org.eclipse.osgi.util.NLS; >-import org.osgi.framework.Bundle; >+ > > /** > * This class knows how to parse and execute the command line arguments to the FrameworkConsole. >@@ -30,21 +24,11 @@ > * > * FrameworkCommandInterpreter provides several print methods which handle the "More" command. > */ >-public class FrameworkCommandInterpreter implements CommandInterpreter { >+public class FrameworkCommandInterpreter extends BaseCommandInterpreter { >+ /** Strings used to format other strings */ >+ private static final String tab = "\t"; //$NON-NLS-1$ > >- /** The command line in StringTokenizer form */ >- private StringTokenizer tok; >- /** The active CommandProviders */ >- private Object[] commandProviders; >- /** The FrameworkConsole */ > private FrameworkConsole con; >- /** The stream to send output to */ >- private PrintWriter out; >- >- /** Strings used to format other strings */ >- private String tab = "\t"; //$NON-NLS-1$ >- private String newline = "\r\n"; //$NON-NLS-1$ >- private boolean firstCommand = true; > > /** > * The maximum number of lines to print without user prompt. >@@ -60,44 +44,10 @@ > * the input parms. > */ > public FrameworkCommandInterpreter(String cmdline, Object[] commandProviders, FrameworkConsole con) { >- tok = new StringTokenizer(cmdline); >- this.commandProviders = commandProviders; >+ super(cmdline, commandProviders, con.out); > this.con = con; >- this.out = con.getWriter(); > } > >- /** >- Get the next argument in the input. >- >- E.g. if the commandline is hello world, the _hello method >- will get "world" as the first argument. >- >- @return A string containing the next argument on the command line >- */ >- public String nextArgument() { >- if (tok == null || !tok.hasMoreElements()) { >- return null; >- } >- String token = tok.nextToken(); >- //check for quotes >- int index = token.indexOf('"'); >- if (index != -1) { >- //if we only have one quote, find the second quote >- if (index == token.lastIndexOf('"')) { >- token += tok.nextToken("\""); //$NON-NLS-1$ >- } >- StringBuffer buf = new StringBuffer(token); >- >- //strip quotes >- while (index != -1) { >- buf.deleteCharAt(index); >- token = buf.toString(); >- index = token.indexOf('"'); >- } >- return buf.toString(); >- } >- return (token); >- } > > /** > Execute a command line as if it came from the end user. >@@ -111,9 +61,6 @@ > @return The object returned by the method executed. > */ > public Object execute(String cmd) { >- if (!firstCommand) >- return innerExecute(cmd); >- firstCommand = false; > resetLineCount(); > Object retval = null; > // handle "more" command here >@@ -134,52 +81,7 @@ > } > return retval; > } >- Class[] parameterTypes = new Class[] {CommandInterpreter.class}; >- Object[] parameters = new Object[] {this}; >- boolean executed = false; >- int size = commandProviders.length; >- for (int i = 0; !executed && (i < size); i++) { >- try { >- Object target = commandProviders[i]; >- Method method = target.getClass().getMethod("_" + cmd, parameterTypes); //$NON-NLS-1$ >- retval = method.invoke(target, parameters); >- executed = true; // stop after the command has been found >- } catch (NoSuchMethodException ite) { >- // keep going - maybe another command provider will be able to execute this command >- } catch (InvocationTargetException ite) { >- executed = true; // don't want to keep trying - we found the method but got an error >- printStackTrace(ite.getTargetException()); >- } catch (Exception ee) { >- executed = true; // don't want to keep trying - we got an error we don't understand >- printStackTrace(ee); >- } >- } >- // if no command was found to execute, display help for all registered command providers >- if (!executed) { >- for (int i = 0; i < size; i++) { >- try { >- CommandProvider commandProvider = (CommandProvider) commandProviders[i]; >- out.print(commandProvider.getHelp()); >- out.flush(); >- } catch (Exception ee) { >- printStackTrace(ee); >- } >- } >- // call help for the more command provided by this class >- out.print(getHelp()); >- out.flush(); >- } >- return retval; >- } >- >- private Object innerExecute(String cmd) { >- if (cmd != null && cmd.length() > 0) { >- CommandInterpreter intcp = new FrameworkCommandInterpreter(cmd, commandProviders, con); >- String command = intcp.nextArgument(); >- if (command != null) >- return intcp.execute(command); >- } >- return null; >+ return super.execute(cmd); > } > > /** >@@ -208,7 +110,6 @@ > if (lines < 0) { > throw new IllegalArgumentException(ConsoleMsg.CONSOLE_LINES_TO_SCROLL_NEGATIVE_ERROR); > } >- > maxLineCount = lines; > } > >@@ -220,157 +121,11 @@ > } > > /** >- * Prints a string to the output medium (appended with newline character). >- * <p> >- * This method does not increment the line counter for the 'more' prompt. >- * >- * @param o the string to be printed >- */ >- private void printline(Object o) { >- print(o + newline); >- } >- >- /** >- * Prints an object to the outputstream >- * >- * @param o the object to be printed >- */ >- public void print(Object o) { >- synchronized (out) { >- check4More(); >- out.print(o); >- out.flush(); >- } >- } >- >- /** >- * Prints a empty line to the outputstream >- */ >- public void println() { >- println(""); //$NON-NLS-1$ >- } >- >- /** >- * Print a stack trace including nested exceptions. >- * @param t The offending exception >- */ >- public void printStackTrace(Throwable t) { >- t.printStackTrace(out); >- >- Method[] methods = t.getClass().getMethods(); >- >- int size = methods.length; >- Class throwable = Throwable.class; >- >- for (int i = 0; i < size; i++) { >- Method method = methods[i]; >- >- if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("get") && throwable.isAssignableFrom(method.getReturnType()) && (method.getParameterTypes().length == 0)) { //$NON-NLS-1$ >- try { >- Throwable nested = (Throwable) method.invoke(t, null); >- >- if ((nested != null) && (nested != t)) { >- out.println(ConsoleMsg.CONSOLE_NESTED_EXCEPTION); >- printStackTrace(nested); >- } >- } catch (IllegalAccessException e) { >- } catch (InvocationTargetException e) { >- } >- } >- } >- } >- >- /** >- * Prints an object to the output medium (appended with newline character). >- * <p> >- * If running on the target environment, the user is prompted with '--more' >- * if more than the configured number of lines have been printed without user prompt. >- * This enables the user of the program to have control over scrolling. >- * <p> >- * For this to work properly you should not embed "\n" etc. into the string. >- * >- * @param o the object to be printed >- */ >- public void println(Object o) { >- if (o == null) { >- return; >- } >- synchronized (out) { >- check4More(); >- printline(o); >- currentLineCount++; >- currentLineCount += o.toString().length() / 80; >- } >- } >- >- /** >- * Prints the given dictionary sorted by keys. >- * >- * @param dic the dictionary to print >- * @param title the header to print above the key/value pairs >- */ >- public void printDictionary(Dictionary dic, String title) { >- if (dic == null) >- return; >- >- int count = dic.size(); >- String[] keys = new String[count]; >- Enumeration keysEnum = dic.keys(); >- int i = 0; >- while (keysEnum.hasMoreElements()) { >- keys[i++] = (String) keysEnum.nextElement(); >- } >- Util.sort(keys); >- >- if (title != null) { >- println(title); >- } >- for (i = 0; i < count; i++) { >- println(" " + keys[i] + " = " + dic.get(keys[i])); //$NON-NLS-1$//$NON-NLS-2$ >- } >- println(); >- } >- >- /** >- * Prints the given bundle resource if it exists >- * >- * @param bundle the bundle containing the resource >- * @param resource the resource to print >- */ >- public void printBundleResource(Bundle bundle, String resource) { >- URL entry = null; >- entry = bundle.getEntry(resource); >- if (entry != null) { >- try { >- println(resource); >- InputStream in = entry.openStream(); >- byte[] buffer = new byte[1024]; >- int read = 0; >- try { >- while ((read = in.read(buffer)) != -1) >- print(new String(buffer, 0, read)); >- } finally { >- if (in != null) { >- try { >- in.close(); >- } catch (IOException e) { >- } >- } >- } >- } catch (Exception e) { >- System.err.println(NLS.bind(ConsoleMsg.CONSOLE_ERROR_READING_RESOURCE, resource)); >- } >- } else { >- println(NLS.bind(ConsoleMsg.CONSOLE_RESOURCE_NOT_IN_BUNDLE, resource, bundle.toString())); >- } >- } >- >- /** > * Displays the more... prompt if the max line count has been reached > * and waits for the operator to hit enter. > * > */ >- private void check4More() { >+ protected void check4More() { > int max = getMaximumLinesToScroll(); > if (max > 0) { > if (currentLineCount >= max) { >@@ -407,7 +162,7 @@ > * Toggles the use of the more prompt for displayed output. > * > */ >- public void _more() throws Exception { >+ private void _more() throws Exception { > if (confirm(ConsoleMsg.CONSOLE_CONFIRM_MORE, true)) { > int lines = prompt(newline + ConsoleMsg.CONSOLE_MORE_ENTER_LINES, 24); > setMaximumLinesToScroll(lines); >@@ -430,7 +185,7 @@ > * > * @return <code>true</code> if the user confirms; <code>false</code> otherwise. > */ >- protected boolean confirm(String string, boolean defaultAnswer) { >+ private boolean confirm(String string, boolean defaultAnswer) { > synchronized (out) { > if (string.length() > 0) { > print(string); >@@ -452,7 +207,7 @@ > return input.toLowerCase().charAt(0) == ConsoleMsg.CONSOLE_Y.charAt(0); > } > >- /** >+ /* > * Prompts the user for input from the input medium providing a default value. > * > * @param string the message to present to the user >@@ -461,7 +216,7 @@ > * @return The user provided string or the defaultAnswer, > * if user provided string was empty. > */ >- protected String prompt(String string, String defaultAnswer) { >+ private String prompt(String string, String defaultAnswer) { > if (string.length() > 0) { > if (defaultAnswer.length() > 0) { > StringBuffer buf = new StringBuffer(256); >@@ -484,7 +239,7 @@ > return defaultAnswer; > } > >- /** >+ /* > * Prompts the user for input of a positive integer. > * > * @param string the message to present to the user >@@ -493,7 +248,7 @@ > * @return The user provided integer or the defaultAnswer, > * if user provided an empty input. > */ >- protected int prompt(String string, int defaultAnswer) { >+ private int prompt(String string, int defaultAnswer) { > Integer i = new Integer(defaultAnswer); > int answer; > for (int j = 0; j < 3; j++) { >@@ -510,4 +265,12 @@ > println(ConsoleMsg.CONSOLE_TOO_MUCH_INVALID_INPUT); > return defaultAnswer; > } >+ >+ protected CommandInterpreter getInnerCommandInterpreter(String cmd) { >+ return new FrameworkCommandInterpreter(cmd, commandProviders, con); >+ } >+ >+ protected void incrementLineCount(int i) { >+ currentLineCount += i; >+ } > } >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 31 Oct 2006 14:12:38 -0000 >@@ -77,36 +77,38 @@ > * invoked by a CommandInterpreter's execute method. > */ > public class FrameworkCommandProvider implements CommandProvider { >- >- /** An instance of the OSGi framework */ >- private OSGi osgi; >+ private static FrameworkCommandProvider instance; >+ /** An instance of the framework */ >+ private Framework framework; > /** The system bundle context */ > private org.osgi.framework.BundleContext context; >- /** The start level implementation */ >- private StartLevelManager slImpl; >- private ConditionalPermissionAdmin condPermAdmin; >- private PermissionAdmin permAdmin; > > /** Strings used to format other strings */ > private String tab = "\t"; //$NON-NLS-1$ > private String newline = "\r\n"; //$NON-NLS-1$ > > /** >- * Constructor. >+ * Get the instance of the FrameworkCommandProvider > * > * It registers itself as a CommandProvider with the highest ranking possible. > * >- * @param osgi The current instance of OSGi >+ * @param framework The current instance of the Framework > */ >- public FrameworkCommandProvider(OSGi osgi) { >- this.osgi = osgi; >- context = osgi.getBundleContext(); >- slImpl = osgi.framework.startLevelManager; >- condPermAdmin = osgi.framework.condPermAdmin; >- permAdmin = osgi.framework.permissionAdmin; >+ public static synchronized FrameworkCommandProvider getInstance(Framework framework) { >+ if (instance != null) >+ return instance; >+ instance = new FrameworkCommandProvider(framework); >+ BundleContext bc = framework.systemBundle.getBundleContext(); > Dictionary props = new Hashtable(); > props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); >- context.registerService(CommandProvider.class.getName(), this, props); >+ bc.registerService(CommandProvider.class.getName(), instance, props); >+ return instance; >+ } >+ >+ >+ private FrameworkCommandProvider(Framework framework) { >+ this.framework = framework; >+ context = framework.systemBundle.getBundleContext(); > } > > /** >@@ -202,7 +204,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _launch(CommandInterpreter intp) throws Exception { >- osgi.launch(); >+ framework.launch(); > } > > /** >@@ -211,7 +213,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _shutdown(CommandInterpreter intp) throws Exception { >- osgi.shutdown(); >+ framework.shutdown(); > } > > /** >@@ -408,7 +410,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _status(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >+ if (framework.isActive()) { > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); > } else { > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); >@@ -605,7 +607,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 +673,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,7 +1046,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _init(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >+ if (framework.isActive()) { > intp.print(newline); > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); > return; >@@ -1069,6 +1071,7 @@ > } else { > intp.println(ConsoleMsg.CONSOLE_NO_INSTALLED_BUNDLES_ERROR); > } >+ PermissionAdmin permAdmin = framework.permissionAdmin; > if (permAdmin != null) { > // clear the permissions from permission admin > permAdmin.setDefaultPermissions(null); >@@ -1078,6 +1081,7 @@ > permAdmin.setPermissions(permLocations[i], null); > } > // clear the permissions from conditional permission admin >+ ConditionalPermissionAdmin condPermAdmin = framework.condPermAdmin; > if (condPermAdmin != null) > for (Enumeration infos = condPermAdmin.getConditionalPermissionInfos(); infos.hasMoreElements();) > ((ConditionalPermissionInfo) infos.nextElement()).delete(); >@@ -1090,7 +1094,7 @@ > */ > public void _close(CommandInterpreter intp) throws Exception { > intp.println(); >- osgi.close(); >+ framework.close(); > System.exit(0); > } > >@@ -1286,7 +1290,7 @@ > * @param intp A CommandInterpreter object containing the command and it's arguments. > */ > public void _ss(CommandInterpreter intp) throws Exception { >- if (osgi.isActive()) { >+ if (framework.isActive()) { > intp.println(); > intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); > } else { >@@ -1400,10 +1404,10 @@ > } > } > if (bundle == null) { // must want framework startlevel >- value = slImpl.getStartLevel(); >+ value = framework.startLevelManager.getStartLevel(); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_FRAMEWORK_ACTIVE_STARTLEVEL, String.valueOf(value))); > } else { // must want bundle startlevel >- value = slImpl.getBundleStartLevel(bundle); >+ value = framework.startLevelManager.getBundleStartLevel(bundle); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_BUNDLE_STARTLEVEL, new Long(bundle.getBundleId()), new Integer(value))); > } > } >@@ -1420,13 +1424,13 @@ > String token = intp.nextArgument(); > if (token == null) { > intp.println(ConsoleMsg.STARTLEVEL_NO_STARTLEVEL_GIVEN); >- value = slImpl.getStartLevel(); >+ value = framework.startLevelManager.getStartLevel(); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_FRAMEWORK_ACTIVE_STARTLEVEL, String.valueOf(value))); > } else { > value = this.getStartLevelFromToken(intp, token); > if (value > 0) { > try { >- slImpl.setStartLevel(value); >+ framework.startLevelManager.setStartLevel(value); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_FRAMEWORK_ACTIVE_STARTLEVEL, String.valueOf(value))); > } catch (IllegalArgumentException e) { > intp.println(e.getMessage()); >@@ -1462,7 +1466,7 @@ > bundle = getBundleFromToken(intp, token, true); > if (bundle != null) { > try { >- slImpl.setBundleStartLevel(bundle, newSL); >+ framework.startLevelManager.setBundleStartLevel(bundle, newSL); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_BUNDLE_STARTLEVEL, new Long(bundle.getBundleId()), new Integer(newSL))); > } catch (IllegalArgumentException e) { > intp.println(e.getMessage()); >@@ -1484,13 +1488,13 @@ > String token = intp.nextArgument(); > if (token == null) { > intp.println(ConsoleMsg.STARTLEVEL_NO_STARTLEVEL_GIVEN); >- value = slImpl.getInitialBundleStartLevel(); >+ value = framework.startLevelManager.getInitialBundleStartLevel(); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_INITIAL_BUNDLE_STARTLEVEL, String.valueOf(value))); > } else { > value = this.getStartLevelFromToken(intp, token); > if (value > 0) { > try { >- slImpl.setInitialBundleStartLevel(value); >+ framework.startLevelManager.setInitialBundleStartLevel(value); > intp.println(NLS.bind(ConsoleMsg.STARTLEVEL_INITIAL_BUNDLE_STARTLEVEL, String.valueOf(value))); > } catch (IllegalArgumentException e) { > intp.println(e.getMessage()); >Index: console/src/org/eclipse/osgi/framework/internal/core/BaseCommandInterpreter.java >=================================================================== >RCS file: console/src/org/eclipse/osgi/framework/internal/core/BaseCommandInterpreter.java >diff -N console/src/org/eclipse/osgi/framework/internal/core/BaseCommandInterpreter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ console/src/org/eclipse/osgi/framework/internal/core/BaseCommandInterpreter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,323 @@ >+/******************************************************************************* >+ * Copyright (c) 2003, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.osgi.framework.internal.core; >+ >+import java.io.*; >+import java.lang.reflect.*; >+import java.net.URL; >+import java.util.*; >+import org.eclipse.osgi.framework.console.CommandInterpreter; >+import org.eclipse.osgi.framework.console.CommandProvider; >+import org.eclipse.osgi.util.NLS; >+import org.osgi.framework.Bundle; >+ >+/** >+ * This class knows how to parse and execute the command line arguments to the FrameworkConsole. >+ * It attempts to pass the command to each registered CommandProvider until it finds one >+ * that knows what to do with it. >+ * >+ * FrameworkCommandInterpreter provides support for the "More" command which allows the operator to configure >+ * the number of lines to display before being prompted to continue. >+ * >+ * FrameworkCommandInterpreter provides several print methods which handle the "More" command. >+ */ >+public class BaseCommandInterpreter implements CommandInterpreter { >+ /** Strings used to format other strings */ >+ protected static final String newline = "\r\n"; //$NON-NLS-1$ >+ /** The command line in StringTokenizer form */ >+ protected StringTokenizer tok; >+ /** The active CommandProviders */ >+ protected Object[] commandProviders; >+ /** The stream to send output to */ >+ protected PrintWriter out; >+ >+ protected boolean firstCommand = true; >+ >+ /** >+ * The constructor. It turns the cmdline string into a StringTokenizer and remembers >+ * the input parms. >+ */ >+ public BaseCommandInterpreter(String cmdline, Object[] commandProviders, PrintWriter out) { >+ tok = new StringTokenizer(cmdline); >+ this.commandProviders = commandProviders; >+ this.out = out; >+ } >+ >+ /** >+ Get the next argument in the input. >+ >+ E.g. if the commandline is hello world, the _hello method >+ will get "world" as the first argument. >+ >+ @return A string containing the next argument on the command line >+ */ >+ public String nextArgument() { >+ if (tok == null || !tok.hasMoreElements()) { >+ return null; >+ } >+ String token = tok.nextToken(); >+ //check for quotes >+ int index = token.indexOf('"'); >+ if (index != -1) { >+ //if we only have one quote, find the second quote >+ if (index == token.lastIndexOf('"')) { >+ token += tok.nextToken("\""); //$NON-NLS-1$ >+ } >+ StringBuffer buf = new StringBuffer(token); >+ >+ //strip quotes >+ while (index != -1) { >+ buf.deleteCharAt(index); >+ token = buf.toString(); >+ index = token.indexOf('"'); >+ } >+ return buf.toString(); >+ } >+ return (token); >+ } >+ >+ /** >+ Execute a command line as if it came from the end user. >+ >+ Searches the list of command providers using introspection until >+ it finds one that contains a matching method. It searches for a method >+ with the name "_cmd" where cmd is the command to execute. For example, >+ for a command of "launch" execute searches for a method called "_launch". >+ >+ @param cmd The name of the command to execute. >+ @return The object returned by the method executed. >+ */ >+ public Object execute(String cmd) { >+ if (!firstCommand) >+ return innerExecute(cmd); >+ firstCommand = false; >+ >+ Class[] parameterTypes = new Class[] {CommandInterpreter.class}; >+ Object[] parameters = new Object[] {this}; >+ boolean executed = false; >+ int size = commandProviders.length; >+ Object retval = null; >+ for (int i = 0; !executed && (i < size); i++) { >+ try { >+ Object target = commandProviders[i]; >+ Method method = target.getClass().getMethod("_" + cmd, parameterTypes); //$NON-NLS-1$ >+ retval = method.invoke(target, parameters); >+ executed = true; // stop after the command has been found >+ } catch (NoSuchMethodException ite) { >+ // keep going - maybe another command provider will be able to execute this command >+ } catch (InvocationTargetException ite) { >+ executed = true; // don't want to keep trying - we found the method but got an error >+ printStackTrace(ite.getTargetException()); >+ } catch (Exception ee) { >+ executed = true; // don't want to keep trying - we got an error we don't understand >+ printStackTrace(ee); >+ } >+ } >+ // if no command was found to execute, display help for all registered command providers >+ if (!executed) { >+ for (int i = 0; i < size; i++) { >+ try { >+ CommandProvider commandProvider = (CommandProvider) commandProviders[i]; >+ out.print(commandProvider.getHelp()); >+ out.flush(); >+ } catch (Exception ee) { >+ printStackTrace(ee); >+ } >+ } >+ // call help for the more command provided by this class >+ out.print(getHelp()); >+ out.flush(); >+ } >+ return retval; >+ } >+ >+ private Object innerExecute(String cmd) { >+ if (cmd != null && cmd.length() > 0) { >+ CommandInterpreter intcp = getInnerCommandInterpreter(cmd); >+ String command = intcp.nextArgument(); >+ if (command != null) >+ return intcp.execute(command); >+ } >+ return null; >+ } >+ >+ protected CommandInterpreter getInnerCommandInterpreter(String cmd) { >+ return new BaseCommandInterpreter(cmd, commandProviders, out); >+ } >+ >+ /** >+ * Prints a string to the output medium (appended with newline character). >+ * <p> >+ * This method does not increment the line counter for the 'more' prompt. >+ * >+ * @param o the string to be printed >+ */ >+ private void printline(Object o) { >+ print(o + newline); >+ } >+ >+ /** >+ * Prints an object to the outputstream >+ * >+ * @param o the object to be printed >+ */ >+ public void print(Object o) { >+ synchronized (out) { >+ check4More(); >+ out.print(o); >+ out.flush(); >+ } >+ } >+ >+ /** >+ * Prints a empty line to the outputstream >+ */ >+ public void println() { >+ println(""); //$NON-NLS-1$ >+ } >+ >+ /** >+ * Print a stack trace including nested exceptions. >+ * @param t The offending exception >+ */ >+ public void printStackTrace(Throwable t) { >+ t.printStackTrace(out); >+ >+ Method[] methods = t.getClass().getMethods(); >+ >+ int size = methods.length; >+ Class throwable = Throwable.class; >+ >+ for (int i = 0; i < size; i++) { >+ Method method = methods[i]; >+ >+ if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("get") && throwable.isAssignableFrom(method.getReturnType()) && (method.getParameterTypes().length == 0)) { //$NON-NLS-1$ >+ try { >+ Throwable nested = (Throwable) method.invoke(t, null); >+ >+ if ((nested != null) && (nested != t)) { >+ out.println(ConsoleMsg.CONSOLE_NESTED_EXCEPTION); >+ printStackTrace(nested); >+ } >+ } catch (IllegalAccessException e) { >+ } catch (InvocationTargetException e) { >+ } >+ } >+ } >+ } >+ >+ /** >+ * Prints an object to the output medium (appended with newline character). >+ * <p> >+ * If running on the target environment, the user is prompted with '--more' >+ * if more than the configured number of lines have been printed without user prompt. >+ * This enables the user of the program to have control over scrolling. >+ * <p> >+ * For this to work properly you should not embed "\n" etc. into the string. >+ * >+ * @param o the object to be printed >+ */ >+ public void println(Object o) { >+ if (o == null) { >+ return; >+ } >+ synchronized (out) { >+ check4More(); >+ printline(o); >+ incrementLineCount(1 + (o.toString().length() / 80)); >+ } >+ } >+ >+ /** >+ * Prints the given dictionary sorted by keys. >+ * >+ * @param dic the dictionary to print >+ * @param title the header to print above the key/value pairs >+ */ >+ public void printDictionary(Dictionary dic, String title) { >+ if (dic == null) >+ return; >+ >+ int count = dic.size(); >+ String[] keys = new String[count]; >+ Enumeration keysEnum = dic.keys(); >+ int i = 0; >+ while (keysEnum.hasMoreElements()) { >+ keys[i++] = (String) keysEnum.nextElement(); >+ } >+ Util.sort(keys); >+ >+ if (title != null) { >+ println(title); >+ } >+ for (i = 0; i < count; i++) { >+ println(" " + keys[i] + " = " + dic.get(keys[i])); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ println(); >+ } >+ >+ /** >+ * Prints the given bundle resource if it exists >+ * >+ * @param bundle the bundle containing the resource >+ * @param resource the resource to print >+ */ >+ public void printBundleResource(Bundle bundle, String resource) { >+ URL entry = null; >+ entry = bundle.getEntry(resource); >+ if (entry != null) { >+ try { >+ println(resource); >+ InputStream in = entry.openStream(); >+ byte[] buffer = new byte[1024]; >+ int read = 0; >+ try { >+ while ((read = in.read(buffer)) != -1) >+ print(new String(buffer, 0, read)); >+ } finally { >+ if (in != null) { >+ try { >+ in.close(); >+ } catch (IOException e) { >+ } >+ } >+ } >+ } catch (Exception e) { >+ System.err.println(NLS.bind(ConsoleMsg.CONSOLE_ERROR_READING_RESOURCE, resource)); >+ } >+ } else { >+ println(NLS.bind(ConsoleMsg.CONSOLE_RESOURCE_NOT_IN_BUNDLE, resource, bundle.toString())); >+ } >+ } >+ >+ /** >+ * Displays the more... prompt if the max line count has been reached >+ * and waits for the operator to hit enter. >+ * >+ */ >+ protected void check4More() { >+ // do nothing by default >+ } >+ >+ protected void incrementLineCount(int i) { >+ // do nothing by default >+ } >+ >+ /** >+ Answer a string (may be as many lines as you like) with help >+ texts that explain the command. >+ */ >+ public String getHelp() { >+ return newline; >+ } >+ >+} >Index: console/src/org/eclipse/osgi/framework/internal/core/ConsoleImpl.java >=================================================================== >RCS file: console/src/org/eclipse/osgi/framework/internal/core/ConsoleImpl.java >diff -N console/src/org/eclipse/osgi/framework/internal/core/ConsoleImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ console/src/org/eclipse/osgi/framework/internal/core/ConsoleImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.osgi.framework.internal.core; >+ >+import java.io.*; >+import org.eclipse.osgi.framework.console.CommandProvider; >+import org.eclipse.osgi.framework.console.Console; >+import org.osgi.framework.ServiceReference; >+import org.osgi.util.tracker.ServiceTracker; >+ >+public class ConsoleImpl implements Console { >+ private Framework framework; >+ /** A tracker containing the service object of all registered command providers */ >+ private ServiceTracker providers; >+ >+ public ConsoleImpl(Framework framework) { >+ this.framework = framework; >+ // register the OSGi command provider >+ FrameworkCommandProvider.getInstance(framework); >+ } >+ >+ public String runCommand(String commandLine) { >+ if (commandLine == null || commandLine.length() == 0) >+ return null; >+ ByteArrayOutputStream out = new ByteArrayOutputStream(); >+ PrintWriter writer = new PrintWriter(out); >+ BaseCommandInterpreter interpreter = new BaseCommandInterpreter(commandLine, getProviders(), writer); >+ String command = interpreter.nextArgument(); >+ if (command != null) >+ interpreter.execute(command); >+ writer.flush(); >+ return out.toString(); >+ } >+ >+ public synchronized CommandProvider[] getProviders() { >+ if (providers == null) >+ providers = new ServiceTracker(framework.systemBundle.getBundleContext(), CommandProvider.class.getName(), null); >+ ServiceReference[] serviceRefs = providers.getServiceReferences(); >+ Util.dsort(serviceRefs, 0, serviceRefs.length); >+ >+ CommandProvider[] serviceObjects = new CommandProvider[serviceRefs.length]; >+ for (int i = 0; i < serviceRefs.length; i++) >+ serviceObjects[i] = (CommandProvider) framework.systemBundle.getBundleContext().getService(serviceRefs[i]); >+ return serviceObjects; >+ } >+} >Index: core/framework/org/eclipse/osgi/framework/console/Console.java >=================================================================== >RCS file: core/framework/org/eclipse/osgi/framework/console/Console.java >diff -N core/framework/org/eclipse/osgi/framework/console/Console.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ core/framework/org/eclipse/osgi/framework/console/Console.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,16 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.osgi.framework.console; >+ >+public interface Console { >+ public String runCommand(String command); >+}
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