|
Lines 28-33
Link Here
|
| 28 |
import org.osgi.service.packageadmin.PackageAdmin; |
28 |
import org.osgi.service.packageadmin.PackageAdmin; |
| 29 |
import org.osgi.service.packageadmin.RequiredBundle; |
29 |
import org.osgi.service.packageadmin.RequiredBundle; |
| 30 |
import org.osgi.service.permissionadmin.PermissionAdmin; |
30 |
import org.osgi.service.permissionadmin.PermissionAdmin; |
|
|
31 |
import org.osgi.service.startlevel.StartLevel; |
| 31 |
|
32 |
|
| 32 |
/** |
33 |
/** |
| 33 |
* This class provides methods to execute commands from the command line. It registers |
34 |
* This class provides methods to execute commands from the command line. It registers |
|
Lines 83-89
Link Here
|
| 83 |
/** The system bundle context */ |
84 |
/** The system bundle context */ |
| 84 |
private org.osgi.framework.BundleContext context; |
85 |
private org.osgi.framework.BundleContext context; |
| 85 |
/** The start level implementation */ |
86 |
/** The start level implementation */ |
| 86 |
private StartLevelManager slImpl; |
87 |
private StartLevel slImpl; |
| 87 |
private ConditionalPermissionAdmin condPermAdmin; |
88 |
private ConditionalPermissionAdmin condPermAdmin; |
| 88 |
private PermissionAdmin permAdmin; |
89 |
private PermissionAdmin permAdmin; |
| 89 |
|
90 |
|
|
Lines 101-107
Link Here
|
| 101 |
public FrameworkCommandProvider(OSGi osgi) { |
102 |
public FrameworkCommandProvider(OSGi osgi) { |
| 102 |
this.osgi = osgi; |
103 |
this.osgi = osgi; |
| 103 |
context = osgi.getBundleContext(); |
104 |
context = osgi.getBundleContext(); |
| 104 |
slImpl = osgi.framework.startLevelManager; |
105 |
if (context == null) { |
|
|
106 |
System.err.println("Could not find OSGi's bundle context"); |
| 107 |
} |
| 108 |
slImpl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName())); |
| 105 |
condPermAdmin = osgi.framework.condPermAdmin; |
109 |
condPermAdmin = osgi.framework.condPermAdmin; |
| 106 |
permAdmin = osgi.framework.permissionAdmin; |
110 |
permAdmin = osgi.framework.permissionAdmin; |
| 107 |
Dictionary props = new Hashtable(); |
111 |
Dictionary props = new Hashtable(); |
|
Lines 110-115
Link Here
|
| 110 |
} |
114 |
} |
| 111 |
|
115 |
|
| 112 |
/** |
116 |
/** |
|
|
117 |
* Constructor. |
| 118 |
* |
| 119 |
* It registers itself as a CommandProvider with the highest ranking possible. Takes BundleContext object |
| 120 |
* instead of OSGi object. This means that some commands will be disabled, specifically, _launch and _shutdown |
| 121 |
* |
| 122 |
* @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. |
| 123 |
*/ |
| 124 |
public FrameworkCommandProvider(BundleContext context) { |
| 125 |
this.osgi = null; |
| 126 |
this.context = context; |
| 127 |
slImpl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName())); |
| 128 |
ServiceReference ref = context.getServiceReference(ConditionalPermissionAdmin.class.getName()); |
| 129 |
if (ref != null) |
| 130 |
condPermAdmin = (ConditionalPermissionAdmin) context.getService(ref); |
| 131 |
else |
| 132 |
condPermAdmin = null; |
| 133 |
ref = context.getServiceReference(PermissionAdmin.class.getName()); |
| 134 |
if (ref != null) |
| 135 |
permAdmin = (PermissionAdmin) context.getService(ref); |
| 136 |
else |
| 137 |
permAdmin = null; |
| 138 |
Dictionary props = new Hashtable(); |
| 139 |
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE)); |
| 140 |
this.context.registerService(CommandProvider.class.getName(), this, props); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 113 |
Answer a string (may be as many lines as you like) with help |
144 |
Answer a string (may be as many lines as you like) with help |
| 114 |
texts that explain the command. This getHelp() method uses the |
145 |
texts that explain the command. This getHelp() method uses the |
| 115 |
ConsoleMsg class to obtain the correct NLS data to display to the user. |
146 |
ConsoleMsg class to obtain the correct NLS data to display to the user. |
|
Lines 122-129
Link Here
|
| 122 |
help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER); |
153 |
help.append(ConsoleMsg.CONSOLE_HELP_VALID_COMMANDS_HEADER); |
| 123 |
help.append(newline); |
154 |
help.append(newline); |
| 124 |
addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help); |
155 |
addHeader(ConsoleMsg.CONSOLE_HELP_CONTROLLING_FRAMEWORK_HEADER, help); |
| 125 |
addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
156 |
if (osgi != null) { |
| 126 |
addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
157 |
addCommand("launch", ConsoleMsg.CONSOLE_HELP_LAUNCH_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
|
|
158 |
addCommand("shutdown", ConsoleMsg.CONSOLE_HELP_SHUTDOWN_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
| 159 |
} |
| 127 |
addCommand("close", ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ |
160 |
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$ |
161 |
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$ |
162 |
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. |
235 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 203 |
*/ |
236 |
*/ |
| 204 |
public void _launch(CommandInterpreter intp) throws Exception { |
237 |
public void _launch(CommandInterpreter intp) throws Exception { |
| 205 |
osgi.launch(); |
238 |
if (osgi != null) |
|
|
239 |
osgi.launch(); |
| 240 |
|
| 206 |
} |
241 |
} |
| 207 |
|
242 |
|
| 208 |
/** |
243 |
/** |
|
Lines 211-217
Link Here
|
| 211 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
246 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 212 |
*/ |
247 |
*/ |
| 213 |
public void _shutdown(CommandInterpreter intp) throws Exception { |
248 |
public void _shutdown(CommandInterpreter intp) throws Exception { |
| 214 |
osgi.shutdown(); |
249 |
if (osgi != null) |
|
|
250 |
osgi.shutdown(); |
| 251 |
|
| 215 |
} |
252 |
} |
| 216 |
|
253 |
|
| 217 |
/** |
254 |
/** |
|
Lines 408-414
Link Here
|
| 408 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
445 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 409 |
*/ |
446 |
*/ |
| 410 |
public void _status(CommandInterpreter intp) throws Exception { |
447 |
public void _status(CommandInterpreter intp) throws Exception { |
| 411 |
if (osgi.isActive()) { |
448 |
if (osgi != null && osgi.isActive() || osgi == null && context.getBundle(0).getState() == Bundle.ACTIVE) { |
| 412 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
449 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
| 413 |
} else { |
450 |
} else { |
| 414 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
451 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE); |
|
Lines 605-611
Link Here
|
| 605 |
intp.print(", "); //$NON-NLS-1$ |
642 |
intp.print(", "); //$NON-NLS-1$ |
| 606 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
643 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
| 607 |
if (id != 0) { |
644 |
if (id != 0) { |
| 608 |
File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
645 |
File dataRoot = Framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
| 609 |
|
646 |
|
| 610 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
647 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
| 611 |
|
648 |
|
|
Lines 671-677
Link Here
|
| 671 |
intp.print(", "); //$NON-NLS-1$ |
708 |
intp.print(", "); //$NON-NLS-1$ |
| 672 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
709 |
intp.print(NLS.bind(ConsoleMsg.CONSOLE_STATUS_MESSAGE, getStateName(bundle.getState()))); |
| 673 |
if (id != 0) { |
710 |
if (id != 0) { |
| 674 |
File dataRoot = osgi.framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
711 |
File dataRoot = Framework.getDataFile(bundle, ""); //$NON-NLS-1$ |
| 675 |
|
712 |
|
| 676 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
713 |
String root = (dataRoot == null) ? null : dataRoot.getAbsolutePath(); |
| 677 |
|
714 |
|
|
Lines 1044-1053
Link Here
|
| 1044 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
1081 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 1045 |
*/ |
1082 |
*/ |
| 1046 |
public void _init(CommandInterpreter intp) throws Exception { |
1083 |
public void _init(CommandInterpreter intp) throws Exception { |
| 1047 |
if (osgi.isActive()) { |
1084 |
if (osgi == null) { |
| 1048 |
intp.print(newline); |
1085 |
if (context.getBundle(0).getState() == Bundle.ACTIVE) { |
| 1049 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
1086 |
intp.print(newline); |
| 1050 |
return; |
1087 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
|
|
1088 |
return; |
| 1089 |
} |
| 1090 |
} else { |
| 1091 |
if (osgi.isActive()) { |
| 1092 |
intp.print(newline); |
| 1093 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_LAUNCHED_PLEASE_SHUTDOWN_MESSAGE); |
| 1094 |
return; |
| 1095 |
} |
| 1051 |
} |
1096 |
} |
| 1052 |
|
1097 |
|
| 1053 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
1098 |
AbstractBundle[] bundles = (AbstractBundle[]) context.getBundles(); |
|
Lines 1090-1096
Link Here
|
| 1090 |
*/ |
1135 |
*/ |
| 1091 |
public void _close(CommandInterpreter intp) throws Exception { |
1136 |
public void _close(CommandInterpreter intp) throws Exception { |
| 1092 |
intp.println(); |
1137 |
intp.println(); |
| 1093 |
osgi.close(); |
1138 |
if (osgi != null) { |
|
|
1139 |
osgi.close(); |
| 1140 |
} |
| 1094 |
System.exit(0); |
1141 |
System.exit(0); |
| 1095 |
} |
1142 |
} |
| 1096 |
|
1143 |
|
|
Lines 1286-1292
Link Here
|
| 1286 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
1333 |
* @param intp A CommandInterpreter object containing the command and it's arguments. |
| 1287 |
*/ |
1334 |
*/ |
| 1288 |
public void _ss(CommandInterpreter intp) throws Exception { |
1335 |
public void _ss(CommandInterpreter intp) throws Exception { |
| 1289 |
if (osgi.isActive()) { |
1336 |
if (osgi != null && osgi.isActive() || osgi == null && context.getBundle(0).getState() == Bundle.ACTIVE) { |
| 1290 |
intp.println(); |
1337 |
intp.println(); |
| 1291 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
1338 |
intp.println(ConsoleMsg.CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE); |
| 1292 |
} else { |
1339 |
} else { |