1 11 package org.eclipse.core.runtime.adaptor; 12 13 import org.eclipse.osgi.framework.console.CommandInterpreter; 14 import org.eclipse.osgi.framework.console.CommandProvider; 15 import org.eclipse.osgi.service.resolver.*; 16 import org.osgi.framework.*; 17 18 21 public class EclipseCommandProvider implements CommandProvider { 22 private BundleContext context; 23 24 public EclipseCommandProvider(BundleContext context) { 25 this.context = context; 26 } 27 28 public String getHelp() { 29 StringBuffer help = new StringBuffer (512); 30 help.append(EclipseAdaptorMsg.NEW_LINE); 31 help.append("---"); help.append(EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_COMMANDS_HEADER")); help.append("---"); help.append(EclipseAdaptorMsg.NEW_LINE); 35 help.append("\tdiag - " + EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_HELP_DIAG_COMMAND_DESCRIPTION")); help.append(EclipseAdaptorMsg.NEW_LINE); 37 help.append("\tactive - " + EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_HELP_ACTIVE_COMMAND_DESCRIPTION")); return help.toString(); 39 } 40 41 private BundleDescription getBundleDescriptionFromToken(State state, String token) { 42 try { 43 long id = Long.parseLong(token); 44 return state.getBundle(id); 45 } catch (NumberFormatException nfe) { 46 BundleDescription[] allBundles = state.getBundles(token); 47 if (allBundles.length > 0) 48 return allBundles[0]; 49 } 50 return null; 51 } 52 53 public void _diag(CommandInterpreter ci) throws Exception { 54 String nextArg = ci.nextArgument(); 55 if (nextArg == null) { 56 ci.println(EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_NO_BUNDLE_SPECIFIED_ERROR")); return; 58 } 59 ServiceReference platformAdminRef = context.getServiceReference(PlatformAdmin.class.getName()); 60 if (platformAdminRef == null) { 61 ci.print(" "); ci.println(EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE")); return; 64 } 65 try { 66 PlatformAdmin platformAdmin = (PlatformAdmin) context.getService(platformAdminRef); 67 if (platformAdmin == null) 68 return; 69 State systemState = platformAdmin.getState(false); 70 while (nextArg != null) { 71 BundleDescription bundle = getBundleDescriptionFromToken(systemState, nextArg); 72 if (bundle == null) { 73 ci.println(EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_CANNOT_FIND_BUNDLE_ERROR", nextArg)); nextArg = ci.nextArgument(); 75 continue; 76 } 77 ci.println(bundle.getLocation() + " [" + bundle.getBundleId() + "]"); VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(bundle); 79 if (unsatisfied.length == 0) { 80 String message = EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_NO_CONSTRAINTS"); if (!bundle.isResolved()) { 83 String symbolicName = bundle.getSymbolicName(); 85 BundleDescription resolved = symbolicName == null ? null : getResolvedBundle(systemState, symbolicName); 86 if (resolved != null) 87 message = EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_OTHER_VERSION", resolved.getLocation()); } 89 ci.print(" "); ci.println(message); } 92 for (int i = 0; i < unsatisfied.length; i++) { 93 ci.print(" "); ci.println(EclipseAdaptorMsg.getResolutionFailureMessage(unsatisfied[i])); 95 } 96 nextArg = ci.nextArgument(); 97 } 98 } finally { 99 context.ungetService(platformAdminRef); 100 } 101 } 102 103 private BundleDescription getResolvedBundle(State state, String symbolicName) { 104 BundleDescription[] homonyms = state.getBundles(symbolicName); 105 for (int i = 0; i < homonyms.length; i++) 106 if (homonyms[i].isResolved()) 107 return homonyms[i]; 108 return null; 109 } 110 111 public void _active(CommandInterpreter ci) throws Exception { 112 Bundle[] allBundles = context.getBundles(); 113 int activeCount = 0; 114 for (int i = 0; i < allBundles.length; i++) 115 if (allBundles[i].getState() == Bundle.ACTIVE) { 116 ci.println(allBundles[i]); 117 activeCount++; 118 } 119 ci.print(" "); ci.println(EclipseAdaptorMsg.formatter.getString("ECLIPSE_CONSOLE_BUNDLES_ACTIVE", activeCount)); } 122 } | Popular Tags |