1 11 package org.eclipse.core.runtime.internal.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.eclipse.osgi.util.NLS; 17 import org.osgi.framework.BundleContext; 18 import org.osgi.framework.ServiceReference; 19 20 23 public class EclipseCommandProvider implements CommandProvider { 24 private BundleContext context; 25 26 public EclipseCommandProvider(BundleContext context) { 27 this.context = context; 28 } 29 30 public String getHelp() { 31 StringBuffer help = new StringBuffer (512); 32 help.append(EclipseAdaptorMsg.NEW_LINE); 33 help.append("---"); help.append(EclipseAdaptorMsg.ECLIPSE_CONSOLE_COMMANDS_HEADER); 35 help.append("---"); help.append(EclipseAdaptorMsg.NEW_LINE); 37 help.append("\tdiag - " + EclipseAdaptorMsg.ECLIPSE_CONSOLE_HELP_DIAG_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.ECLIPSE_CONSOLE_NO_BUNDLE_SPECIFIED_ERROR); 57 return; 58 } 59 ServiceReference platformAdminRef = context.getServiceReference(PlatformAdmin.class.getName()); 60 if (platformAdminRef == null) { 61 ci.print(" "); ci.println(EclipseAdaptorMsg.ECLIPSE_CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE); 63 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(NLS.bind(EclipseAdaptorMsg.ECLIPSE_CONSOLE_CANNOT_FIND_BUNDLE_ERROR, nextArg)); 74 nextArg = ci.nextArgument(); 75 continue; 76 } 77 ci.println(bundle.getLocation() + " [" + bundle.getBundleId() + "]"); VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(bundle); 79 ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(bundle); 80 for (int i = 0; i < resolverErrors.length; i++) { 81 if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0) 82 continue; 83 ci.print(" "); ci.println(resolverErrors[i].toString()); 85 } 86 87 for (int i = 0; i < unsatisfied.length; i++) { 88 ci.print(" "); ci.println(MessageHelper.getResolutionFailureMessage(unsatisfied[i])); 90 } 91 if (unsatisfied.length == 0 && resolverErrors.length == 0) { 92 ci.print(" "); ci.println(EclipseAdaptorMsg.ECLIPSE_CONSOLE_NO_CONSTRAINTS); 94 } 95 nextArg = ci.nextArgument(); 96 } 97 } finally { 98 context.ungetService(platformAdminRef); 99 } 100 } 101 } 102 | Popular Tags |