|
Lines 11-33
Link Here
|
| 11 |
|
11 |
|
| 12 |
package org.eclipse.osgi.framework.internal.core; |
12 |
package org.eclipse.osgi.framework.internal.core; |
| 13 |
|
13 |
|
| 14 |
import java.io.*; |
14 |
import java.io.ByteArrayInputStream; |
|
|
15 |
import java.io.File; |
| 16 |
import java.io.IOException; |
| 17 |
import java.io.InputStream; |
| 15 |
import java.lang.reflect.Method; |
18 |
import java.lang.reflect.Method; |
| 16 |
import java.net.URL; |
19 |
import java.net.URL; |
|
|
20 |
import java.security.PrivilegedAction; |
| 17 |
import java.security.ProtectionDomain; |
21 |
import java.security.ProtectionDomain; |
| 18 |
import java.util.*; |
22 |
import java.util.ArrayList; |
|
|
23 |
import java.util.Dictionary; |
| 24 |
import java.util.Enumeration; |
| 25 |
import java.util.Hashtable; |
| 26 |
import java.util.Properties; |
| 27 |
import java.util.Vector; |
| 28 |
import java.security.AccessController; |
| 19 |
import org.eclipse.osgi.framework.console.CommandInterpreter; |
29 |
import org.eclipse.osgi.framework.console.CommandInterpreter; |
| 20 |
import org.eclipse.osgi.framework.console.CommandProvider; |
30 |
import org.eclipse.osgi.framework.console.CommandProvider; |
| 21 |
import org.eclipse.osgi.framework.launcher.Launcher; |
31 |
import org.eclipse.osgi.framework.launcher.Launcher; |
| 22 |
import org.eclipse.osgi.internal.profile.Profile; |
32 |
import org.eclipse.osgi.internal.profile.Profile; |
| 23 |
import org.eclipse.osgi.service.resolver.*; |
33 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
|
|
34 |
import org.eclipse.osgi.service.resolver.ExportPackageDescription; |
| 35 |
import org.eclipse.osgi.service.resolver.PlatformAdmin; |
| 24 |
import org.eclipse.osgi.util.NLS; |
36 |
import org.eclipse.osgi.util.NLS; |
| 25 |
import org.osgi.framework.*; |
37 |
import org.osgi.framework.Bundle; |
|
|
38 |
import org.osgi.framework.BundleContext; |
| 39 |
import org.osgi.framework.BundleException; |
| 40 |
import org.osgi.framework.ServiceReference; |
| 41 |
import org.osgi.framework.Version; |
| 26 |
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; |
42 |
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; |
| 27 |
import org.osgi.service.condpermadmin.ConditionalPermissionInfo; |
43 |
import org.osgi.service.condpermadmin.ConditionalPermissionInfo; |
| 28 |
import org.osgi.service.packageadmin.PackageAdmin; |
44 |
import org.osgi.service.packageadmin.PackageAdmin; |
| 29 |
import org.osgi.service.packageadmin.RequiredBundle; |
45 |
import org.osgi.service.packageadmin.RequiredBundle; |
| 30 |
import org.osgi.service.permissionadmin.PermissionAdmin; |
46 |
import org.osgi.service.permissionadmin.PermissionAdmin; |
|
|
47 |
import org.osgi.service.startlevel.StartLevel; |
| 31 |
|
48 |
|
| 32 |
/** |
49 |
/** |
| 33 |
* This class provides methods to execute commands from the command line. It registers |
50 |
* This class provides methods to execute commands from the command line. It registers |
|
Lines 79-89
Link Here
|
| 79 |
public class FrameworkCommandProvider implements CommandProvider { |
96 |
public class FrameworkCommandProvider implements CommandProvider { |
| 80 |
|
97 |
|
| 81 |
/** An instance of the OSGi framework */ |
98 |
/** An instance of the OSGi framework */ |
| 82 |
private OSGi osgi; |
99 |
private OSGi osgi; //TODO Fix references to thsi variable, it might be null |
| 83 |
/** The system bundle context */ |
100 |
/** The system bundle context */ |
| 84 |
private org.osgi.framework.BundleContext context; |
101 |
private org.osgi.framework.BundleContext context; |
| 85 |
/** The start level implementation */ |
102 |
/** The start level implementation */ |
| 86 |
private StartLevelManager slImpl; |
103 |
private StartLevel slImpl; |
| 87 |
private ConditionalPermissionAdmin condPermAdmin; |
104 |
private ConditionalPermissionAdmin condPermAdmin; |
| 88 |
private PermissionAdmin permAdmin; |
105 |
private PermissionAdmin permAdmin; |
| 89 |
|
106 |
|
|
Lines 101-113
Link Here
|
| 101 |
public FrameworkCommandProvider(OSGi osgi) { |
118 |
public FrameworkCommandProvider(OSGi osgi) { |
| 102 |
this.osgi = osgi; |
119 |
this.osgi = osgi; |
| 103 |
context = osgi.getBundleContext(); |
120 |
context = osgi.getBundleContext(); |
| 104 |
slImpl = osgi.framework.startLevelManager; |
121 |
slImpl = (StartLevel)context.getService(context.getServiceReference(StartLevel.class.getName()));; |
| 105 |
condPermAdmin = osgi.framework.condPermAdmin; |
122 |
condPermAdmin = osgi.framework.condPermAdmin; |
| 106 |
permAdmin = osgi.framework.permissionAdmin; |
123 |
permAdmin = osgi.framework.permissionAdmin; |
| 107 |
Dictionary props = new Hashtable(); |
124 |
Dictionary props = new Hashtable(); |
| 108 |
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); |
125 |
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); |
| 109 |
context.registerService(CommandProvider.class.getName(), this, props); |
126 |
context.registerService(CommandProvider.class.getName(), this, props); |
| 110 |
} |
127 |
} |
|
|
128 |
|
| 129 |
/** |
| 130 |
* |
| 131 |
* |
| 132 |
* @param context |
| 133 |
*/ |
| 134 |
public FrameworkCommandProvider(BundleContext context) { |
| 135 |
this.osgi = null; |
| 136 |
this.context = context; |
| 137 |
slImpl = (StartLevel)context.getService(context.getServiceReference(StartLevel.class.getName())); |
| 138 |
ServiceReference ref = context.getServiceReference(ConditionalPermissionAdmin.class.getName()); |
| 139 |
if(ref!= null) |
| 140 |
condPermAdmin = (ConditionalPermissionAdmin)context.getService(ref); |
| 141 |
else |
| 142 |
ref = null; |
| 143 |
ref = context.getServiceReference(PermissionAdmin.class.getName()); |
| 144 |
if(ref!=null) |
| 145 |
permAdmin = (PermissionAdmin)context.getService(ref); |
| 146 |
else |
| 147 |
permAdmin = null; |
| 148 |
Dictionary props = new Hashtable(); |
| 149 |
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); |
| 150 |
context.registerService(CommandProvider.class.getName(), this, props); |
| 151 |
} |
| 111 |
|
152 |
|
| 112 |
/** |
153 |
/** |
| 113 |
Answer a string (may be as many lines as you like) with help |
154 |
Answer a string (may be as many lines as you like) with help |
|
Lines 122-129
Link Here
|
| 122 |
help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER); |
163 |
help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER); |
| 123 |
help.append(newline); |
164 |
help.append(newline); |
| 124 |
addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help); |
165 |
addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help); |
| 125 |
addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
166 |
if(osgi!=null){ |
| 126 |
addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
167 |
addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
|
|
168 |
addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
| 169 |
} |
| 127 |
addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
170 |
addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
| 128 |
addCommand("exit", ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
171 |
addCommand("exit", ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
| 129 |
addCommand("gc", ConsoleMsg.CONSOLE_HELP_GC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
172 |
addCommand("gc", ConsoleMsg.CONSOLE_HELP_GC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
|
Lines 202-208
Link Here
|
| 202 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
245 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 203 |
*/ |
246 |
*/ |
| 204 |
public void _launch(CommandInterpreter intp) throws Exception { |
247 |
public void _launch(CommandInterpreter intp) throws Exception { |
| 205 |
osgi.launch(); |
248 |
if(osgi==null) { |
|
|
249 |
return; |
| 250 |
} else { |
| 251 |
osgi.launch(); |
| 252 |
} |
| 206 |
} |
253 |
} |
| 207 |
|
254 |
|
| 208 |
/** |
255 |
/** |
|
Lines 211-217
Link Here
|
| 211 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
258 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 212 |
*/ |
259 |
*/ |
| 213 |
public void _shutdown(CommandInterpreter intp) throws Exception { |
260 |
public void _shutdown(CommandInterpreter intp) throws Exception { |
| 214 |
osgi.shutdown(); |
261 |
if(osgi==null){ |
|
|
262 |
return; |
| 263 |
} else { |
| 264 |
osgi.shutdown(); |
| 265 |
} |
| 215 |
} |
266 |
} |
| 216 |
|
267 |
|
| 217 |
/** |
268 |
/** |
|
Lines 408-417
Link Here
|
| 408 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
459 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 409 |
*/ |
460 |
*/ |
| 410 |
public void _status(CommandInterpreter intp) throws Exception { |
461 |
public void _status(CommandInterpreter intp) throws Exception { |
| 411 |
if (osgi.isActive()) { |
462 |
if(osgi==null) { |
| 412 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
463 |
if(context.getBundle(0).getState()==Bundle.ACTIVE) { |
|
|
464 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
| 465 |
} else { |
| 466 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
| 467 |
} |
| 413 |
} else { |
468 |
} else { |
| 414 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
469 |
if (osgi.isActive()) { |
|
|
470 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
| 471 |
} else { |
| 472 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
| 473 |
} |
| 415 |
} |
474 |
} |
| 416 |
intp.println(); |
475 |
intp.println(); |
| 417 |
|
476 |
|
|
Lines 605-611
Link Here
|
| 605 |
intp.print(", "); //$NON-NLS-1$ |
664 |
intp.print(", "); //$NON-NLS-1$ |
| 606 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
665 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
| 607 |
if (id != 0) { |
666 |
if (id != 0) { |
| 608 |
File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
667 |
File dataRoot; |
|
|
668 |
if(osgi==null) { |
| 669 |
dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$ |
| 670 |
} else { |
| 671 |
dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
| 672 |
} |
| 609 |
|
673 |
|
| 610 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
674 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
| 611 |
|
675 |
|
|
Lines 671-678
Link Here
|
| 671 |
intp.print(", "); //$NON-NLS-1$ |
735 |
intp.print(", "); //$NON-NLS-1$ |
| 672 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
736 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
| 673 |
if (id != 0) { |
737 |
if (id != 0) { |
| 674 |
File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
738 |
File dataRoot; |
| 675 |
|
739 |
if(osgi==null) { |
|
|
740 |
dataRoot = getDataFile(bundle, ""); //$NON-NLS-1$ |
| 741 |
} else { |
| 742 |
dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
| 743 |
} |
| 676 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
744 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
| 677 |
|
745 |
|
| 678 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root)); |
746 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_DATA_ROOT_MESSAGE, root)); |
|
Lines 1046-1055
Link Here
|
| 1046 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
1114 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 1047 |
*/ |
1115 |
*/ |
| 1048 |
public void _init(CommandInterpreter intp) throws Exception { |
1116 |
public void _init(CommandInterpreter intp) throws Exception { |
| 1049 |
if (osgi.isActive()) { |
1117 |
if(osgi==null) { |
| 1050 |
intp.print(newline); |
1118 |
if(context.getBundle(0).getState()==Bundle.ACTIVE) { |
| 1051 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
1119 |
intp.print(newline); |
| 1052 |
return; |
1120 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
|
|
1121 |
return; |
| 1122 |
} |
| 1123 |
} else { |
| 1124 |
if (osgi.isActive()) { |
| 1125 |
intp.print(newline); |
| 1126 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
| 1127 |
return; |
| 1128 |
} |
| 1053 |
} |
1129 |
} |
| 1054 |
|
1130 |
|
| 1055 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
1131 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
|
Lines 1092-1098
Link Here
|
| 1092 |
*/ |
1168 |
*/ |
| 1093 |
public void _close(CommandInterpreter intp) throws Exception { |
1169 |
public void _close(CommandInterpreter intp) throws Exception { |
| 1094 |
intp.println(); |
1170 |
intp.println(); |
| 1095 |
osgi.close(); |
1171 |
if(osgi!=null) { |
|
|
1172 |
osgi.close(); |
| 1173 |
} |
| 1096 |
System.exit(0); |
1174 |
System.exit(0); |
| 1097 |
} |
1175 |
} |
| 1098 |
|
1176 |
|
|
Lines 1288-1299
Link Here
|
| 1288 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
1366 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 1289 |
*/ |
1367 |
*/ |
| 1290 |
public void _ss(CommandInterpreter intp) throws Exception { |
1368 |
public void _ss(CommandInterpreter intp) throws Exception { |
| 1291 |
if (osgi.isActive()) { |
1369 |
if(osgi==null) { |
| 1292 |
intp.println(); |
1370 |
if(context.getBundle(0).getState()==Bundle.ACTIVE) { |
| 1293 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
1371 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
|
|
1372 |
} else { |
| 1373 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
| 1374 |
} |
| 1294 |
} else { |
1375 |
} else { |
| 1295 |
intp.println(); |
1376 |
if (osgi.isActive()) { |
| 1296 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
1377 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
|
|
1378 |
} else { |
| 1379 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
| 1380 |
} |
| 1297 |
} |
1381 |
} |
| 1298 |
|
1382 |
|
| 1299 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
1383 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
|
Lines 1768-1771
Link Here
|
| 1768 |
} |
1852 |
} |
| 1769 |
return t.nextToken(); |
1853 |
return t.nextToken(); |
| 1770 |
} |
1854 |
} |
|
|
1855 |
|
| 1856 |
/** |
| 1857 |
* |
| 1858 |
* Duplicate of method of same name from Framework.java |
| 1859 |
* |
| 1860 |
* * Creates a <code>File</code> object for a file in the persistent |
| 1861 |
* storage area provided for the bundle by the framework. If the adaptor |
| 1862 |
* does not have file system support, this method will return <code>null</code>. |
| 1863 |
* |
| 1864 |
* <p> |
| 1865 |
* A <code>File</code> object for the base directory of the persistent |
| 1866 |
* storage area provided for the context bundle by the framework can be |
| 1867 |
* obtained by calling this method with the empty string ("") as the |
| 1868 |
* parameter. |
| 1869 |
*/ |
| 1870 |
protected File getDataFile(final AbstractBundle bundle, final String filename) { |
| 1871 |
return (File) AccessController.doPrivileged(new PrivilegedAction() { |
| 1872 |
public Object run() { |
| 1873 |
return bundle.getBundleData().getDataFile(filename); |
| 1874 |
} |
| 1875 |
}); |
| 1876 |
} |
| 1771 |
} |
1877 |
} |