diff options
| author | Lazar Kirchev | 2011-10-15 17:40:28 +0000 |
|---|---|---|
| committer | Lazar Kirchev | 2011-10-15 17:40:28 +0000 |
| commit | 8c8c2d910fa5313f94f2b7f7d1c04598eb2b61a5 (patch) | |
| tree | 646ee937b80f84e1e05fa8c11f3e7cef4d1bc082 | |
| parent | b76a1e93e813b4c95466d65218aca9bb28fb698e (diff) | |
| download | rt.equinox.bundles-8c8c2d910fa5313f94f2b7f7d1c04598eb2b61a5.tar.gz rt.equinox.bundles-8c8c2d910fa5313f94f2b7f7d1c04598eb2b61a5.tar.xz rt.equinox.bundles-8c8c2d910fa5313f94f2b7f7d1c04598eb2b61a5.zip | |
Migrate EclipseCommandProvider commands to the new Equinox console bundle
3 files changed, 254 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties index 99c7f4298..64bc484da 100755 --- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties +++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties @@ -75,4 +75,25 @@ CONSOLE_FRAMEWORK_IS_LAUNCHED_MESSAGE = "Framework is launched." CONSOLE_FRAMEWORK_IS_SHUTDOWN_MESSAGE = "Framework is shutdown." CONSOLE_BUNDLE_LOCATION_MESSAGE = "Bundle Location" CONSOLE_STATE_BUNDLE_FILE_NAME_HEADER = "State Bundle File Name" -CONSOLE_REGISTERED_SERVICES_MESSAGE = "Registered Services"
\ No newline at end of file +CONSOLE_REGISTERED_SERVICES_MESSAGE = "Registered Services" +CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE=No unresolved constraints [PlatformAdmin service is not registered]. +CONSOLE_CANNOT_FIND_BUNDLE_ERROR=Cannot find bundle {0}. +CONSOLE_NO_CONSTRAINTS=No unresolved constraints. +CONSOLE_DIRECT_CONSTRAINTS=Direct constraints which are unresolved: +CONSOLE_LEAF_CONSTRAINTS=Leaf constraints in the dependency chain which are unresolved: +CONSOLE_MISSING_IMPORTED_PACKAGE=Missing imported package {0}. +CONSOLE_MISSING_OPTIONAL_IMPORTED_PACKAGE=Missing optionally imported package {0}. +CONSOLE_MISSING_DYNAMIC_IMPORTED_PACKAGE=Missing dynamically imported package {0}. +CONSOLE_MISSING_OPTIONAL_REQUIRED_BUNDLE=Missing optionally required bundle {0}. +CONSOLE_MISSING_REQUIRED_BUNDLE=Missing required bundle {0}. +CONSOLE_MISSING_HOST=Missing host {0}. +CONSOLE_MISSING_NATIVECODE=Missing native code match {0}. +CONSOLE_MISSING_REQUIRED_CAPABILITY=Missing required capability {0}. +CONSOLE_MISSING_REQUIREMENT=Missing the requirement {0}. +CONSOLE_CONSOLE_BUNDLE_DISABLED_MESSAGE=Bundle disabled at console +CONSOLE_CANNOT_ENABLE_NO_PLATFORM_ADMIN_MESSAGE=Cannot enable bundle(s) [PlatformAdmin service is not registered]. +CONSOLE_CANNOT_DISABLE_NO_PLATFORM_ADMIN_MESSAGE=Cannot disable bundle(s) [PlatformAdmin service is not registered]. +CONSOLE_CANNOT_LIST_DISABLED_NO_PLATFORM_ADMIN_MESSAGE=Cannot list disabled bundle(s) [PlatformAdmin service is not registered]. +CONSOLE_DISABLED_COUNT_MESSAGE={0} disabled bundle(s) in the system +CONSOLE_DISABLED_BUNDLE_HEADER=Bundle :\t{0} (id={1}) +CONSOLE_DISABLED_BUNDLE_REASON=Reason(s):\t{0} (policy={1}) diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java index e58b82df6..2bd57514c 100755 --- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java +++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java @@ -75,6 +75,27 @@ public class ConsoleMsg extends NLS { public static String CONSOLE_THREADTYPE_TITLE; public static String CONSOLE_REQUIRES_MESSAGE; public static String CONSOLE_CANNOT_ACCESS_SYSTEM_PROPERTIES; + public static String CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE; + public static String CONSOLE_CANNOT_FIND_BUNDLE_ERROR; + public static String CONSOLE_NO_CONSTRAINTS; + public static String CONSOLE_DIRECT_CONSTRAINTS; + public static String CONSOLE_LEAF_CONSTRAINTS; + public static String CONSOLE_MISSING_IMPORTED_PACKAGE; + public static String CONSOLE_MISSING_OPTIONAL_IMPORTED_PACKAGE; + public static String CONSOLE_MISSING_DYNAMIC_IMPORTED_PACKAGE; + public static String CONSOLE_MISSING_OPTIONAL_REQUIRED_BUNDLE; + public static String CONSOLE_MISSING_REQUIRED_BUNDLE; + public static String CONSOLE_MISSING_HOST; + public static String CONSOLE_MISSING_NATIVECODE; + public static String CONSOLE_MISSING_REQUIRED_CAPABILITY; + public static String CONSOLE_MISSING_REQUIREMENT; + public static String CONSOLE_CONSOLE_BUNDLE_DISABLED_MESSAGE; + public static String CONSOLE_CANNOT_ENABLE_NO_PLATFORM_ADMIN_MESSAGE; + public static String CONSOLE_CANNOT_DISABLE_NO_PLATFORM_ADMIN_MESSAGE; + public static String CONSOLE_CANNOT_LIST_DISABLED_NO_PLATFORM_ADMIN_MESSAGE; + public static String CONSOLE_DISABLED_COUNT_MESSAGE; + public static String CONSOLE_DISABLED_BUNDLE_HEADER; + public static String CONSOLE_DISABLED_BUNDLE_REASON; public static String STARTLEVEL_FRAMEWORK_ACTIVE_STARTLEVEL; public static String STARTLEVEL_BUNDLE_STARTLEVEL; @@ -140,9 +161,16 @@ public class ConsoleMsg extends NLS { public static final String CONSOLE_HELP_VISIBLE_PACKAGES_COMMAND_ARGUMENTS_DESCRIPTION = "bundle to list the visible packages"; public static final String CONSOLE_HELP_GETPROP_COMMAND_DESCRIPTION = "displays the system properties with the given name, or all of them"; public static final String CONSOLE_HELP_GETPROP_COMMAND_ARGUMENT_DESCRIPTION = "name of system property to dispaly"; + public static final String CONSOLE_HELP_DIAG_COMMAND_DESCRIPTION = "Displays unsatisfied constraints for the specified bundle(s)"; + public static final String CONSOLE_HELP_DIAG_COMMAND_ARGUMENT_DESCRIPTION = "IDs of bundle(s), for which to display unsatisfied constraints"; + public static final String CONSOLE_HELP_ENABLE_COMMAND_DESCRIPTION="Enable the specified bundle(s)"; + public static final String CONSOLE_HELP_ENABLE_COMMAND_ARGUMENT_DESCRIPTION="IDs of bundle(s) to enable"; + public static final String CONSOLE_HELP_DISABLE_COMMAND_DESCRIPTION="Disable the specified bundle(s)"; + public static final String CONSOLE_HELP_DISABLE_COMMAND_ARGUMENT_DESCRIPTION="IDs of bundle(s) to disable"; + public static final String CONSOLE_HELP_LD_COMMAND_DESCRIPTION="List disabled bundles in the system"; static { // initialize resource bundles NLS.initializeMessages(BUNDLE_NAME, ConsoleMsg.class); } -}
\ No newline at end of file +} diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java index b6d452751..a01091bf4 100755 --- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java +++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java @@ -33,12 +33,18 @@ import org.apache.felix.service.command.Parameter; import org.eclipse.equinox.console.command.adapter.Activator; import org.eclipse.osgi.service.environment.EnvironmentInfo; import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.osgi.service.resolver.BundleSpecification; import org.eclipse.osgi.service.resolver.DisabledInfo; import org.eclipse.osgi.service.resolver.ExportPackageDescription; +import org.eclipse.osgi.service.resolver.GenericSpecification; +import org.eclipse.osgi.service.resolver.HostSpecification; import org.eclipse.osgi.service.resolver.ImportPackageSpecification; +import org.eclipse.osgi.service.resolver.NativeCodeSpecification; import org.eclipse.osgi.service.resolver.PlatformAdmin; +import org.eclipse.osgi.service.resolver.ResolverError; import org.eclipse.osgi.service.resolver.State; import org.eclipse.osgi.service.resolver.StateHelper; +import org.eclipse.osgi.service.resolver.VersionConstraint; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -99,7 +105,11 @@ import org.osgi.service.startlevel.StartLevel; setfwsl <start level> - set the framework start level setbsl <start level> (<id>|<location>) - set the start level for the bundle(s) setibsl <start level> - set the initial bundle start level - + ---Eclipse Runtime commands--- + diag - Displays unsatisfied constraints for the specified bundle(s) + enableBundle - Enable the specified bundle(s) + disableBundle - Disable the specified bundle(s) + disabledBundles - List disabled bundles in the system */ public class EquinoxCommandProvider implements SynchronousBundleListener { @@ -123,7 +133,10 @@ public class EquinoxCommandProvider implements SynchronousBundleListener { "install", "up", "up", "up", "update", "update", "update", "un", "uninstall", "s", "status", "se", "services", "p", "p", "packages", "packages", "bundles", "b", "bundle", "gc", "init", "close", "r", "refresh", "exec", "fork", "h", "headers", "pr", "props", "setp", "setprop", "ss", "t", "threads", "sl", "setfwsl", "setbsl", - "setibsl", "requiredBundles", "classSpaces", "profilelog", "getPackages", "getprop"}; + "setibsl", "requiredBundles", "classSpaces", "profilelog", "getPackages", "getprop", "diag", "enableBundle", + "disableBundle", "disabledBundles"}; + + private static final String POLICY_CONSOLE = "org.eclipse.equinox.console"; //$NON-NLS-1$ /** * Constructor. @@ -1794,6 +1807,193 @@ public class EquinoxCommandProvider implements SynchronousBundleListener { } } } + + @Descriptor(ConsoleMsg.CONSOLE_HELP_DIAG_COMMAND_DESCRIPTION) + public void diag(@Descriptor(ConsoleMsg.CONSOLE_HELP_DIAG_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception { + if (bundleIds.length == 0) { + System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR); + return; + } + + PlatformAdmin platformAdmin = activator.getPlatformAdmin(); + if (platformAdmin == null) { + System.out.println(ConsoleMsg.CONSOLE_NO_CONSTRAINTS_NO_PLATFORM_ADMIN_MESSAGE); + return; + } + + State systemState = platformAdmin.getState(false); + for (long bundleId : bundleIds) { + BundleDescription bundle = systemState.getBundle(bundleId); + if (bundle == null) { + System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId)); + continue; + } + System.out.println(bundle.getLocation() + " [" + bundle.getBundleId() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + VersionConstraint[] unsatisfied = platformAdmin.getStateHelper().getUnsatisfiedConstraints(bundle); + ResolverError[] resolverErrors = platformAdmin.getState(false).getResolverErrors(bundle); + for (int i = 0; i < resolverErrors.length; i++) { + if ((resolverErrors[i].getType() & (ResolverError.MISSING_FRAGMENT_HOST | ResolverError.MISSING_GENERIC_CAPABILITY | ResolverError.MISSING_IMPORT_PACKAGE | ResolverError.MISSING_REQUIRE_BUNDLE)) != 0) + continue; + System.out.print(" "); //$NON-NLS-1$ + System.out.println(resolverErrors[i].toString()); + } + + if (unsatisfied.length == 0 && resolverErrors.length == 0) { + System.out.print(" "); //$NON-NLS-1$ + System.out.println(ConsoleMsg.CONSOLE_NO_CONSTRAINTS); + } + if (unsatisfied.length > 0) { + System.out.print(" "); //$NON-NLS-1$ + System.out.println(ConsoleMsg.CONSOLE_DIRECT_CONSTRAINTS); + } + for (int i = 0; i < unsatisfied.length; i++) { + System.out.print(" "); //$NON-NLS-1$ + System.out.println(getResolutionFailureMessage(unsatisfied[i])); + } + VersionConstraint[] unsatisfiedLeaves = platformAdmin.getStateHelper().getUnsatisfiedLeaves(new BundleDescription[] {bundle}); + boolean foundLeaf = false; + for (int i = 0; i < unsatisfiedLeaves.length; i++) { + if (unsatisfiedLeaves[i].getBundle() == bundle) + continue; + if (!foundLeaf) { + foundLeaf = true; + System.out.print(" "); //$NON-NLS-1$ + System.out.println(ConsoleMsg.CONSOLE_LEAF_CONSTRAINTS); + } + System.out.print(" "); //$NON-NLS-1$ + System.out.println(unsatisfiedLeaves[i].getBundle().getLocation() + " [" + unsatisfiedLeaves[i].getBundle().getBundleId() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + System.out.print(" "); //$NON-NLS-1$ + System.out.println(getResolutionFailureMessage(unsatisfiedLeaves[i])); + } + } + } + + @Descriptor(ConsoleMsg.CONSOLE_HELP_ENABLE_COMMAND_DESCRIPTION) + public void enableBundle(@Descriptor(ConsoleMsg.CONSOLE_HELP_ENABLE_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception { + if (bundleIds.length == 0) { + System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR); + return; + } + + PlatformAdmin platformAdmin = activator.getPlatformAdmin(); + if (platformAdmin == null) { + System.out.println(ConsoleMsg.CONSOLE_CANNOT_ENABLE_NO_PLATFORM_ADMIN_MESSAGE); + return; + } + + + State systemState = platformAdmin.getState(false); + for (long bundleId : bundleIds) { + BundleDescription bundle = systemState.getBundle(bundleId); + if (bundle == null) { + System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId)); + continue; + } + + DisabledInfo[] infos = systemState.getDisabledInfos(bundle); + for (int i = 0; i < infos.length; i++) { + platformAdmin.removeDisabledInfo(infos[i]); + } + } + + } + + @Descriptor(ConsoleMsg.CONSOLE_HELP_DISABLE_COMMAND_DESCRIPTION) + public void disableBundle(@Descriptor(ConsoleMsg.CONSOLE_HELP_DISABLE_COMMAND_ARGUMENT_DESCRIPTION) long[] bundleIds) throws Exception { + if (bundleIds.length == 0) { + System.out.println(ConsoleMsg.CONSOLE_NO_BUNDLE_SPECIFIED_ERROR); + return; + } + + PlatformAdmin platformAdmin = activator.getPlatformAdmin(); + if (platformAdmin == null) { + System.out.println(ConsoleMsg.CONSOLE_CANNOT_DISABLE_NO_PLATFORM_ADMIN_MESSAGE); + return; + } + + + State systemState = platformAdmin.getState(false); + for (long bundleId : bundleIds) { + BundleDescription bundle = systemState.getBundle(bundleId); + if (bundle == null) { + System.out.println(NLS.bind(ConsoleMsg.CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleId)); + continue; + } + DisabledInfo info = new DisabledInfo(POLICY_CONSOLE, ConsoleMsg.CONSOLE_CONSOLE_BUNDLE_DISABLED_MESSAGE, bundle); + platformAdmin.addDisabledInfo(info); + } + } + + @Descriptor(ConsoleMsg.CONSOLE_HELP_LD_COMMAND_DESCRIPTION) + public void disabledBundles() throws Exception { + + PlatformAdmin platformAdmin = activator.getPlatformAdmin(); + if (platformAdmin == null) { + System.out.println(ConsoleMsg.CONSOLE_CANNOT_LIST_DISABLED_NO_PLATFORM_ADMIN_MESSAGE); + return; + } + + State systemState = platformAdmin.getState(false); + BundleDescription[] disabledBundles = systemState.getDisabledBundles(); + + System.out.println(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_COUNT_MESSAGE, String.valueOf(disabledBundles.length))); + + if (disabledBundles.length > 0) { + System.out.println(); + } + for (int i = 0; i < disabledBundles.length; i++) { + DisabledInfo[] disabledInfos = systemState.getDisabledInfos(disabledBundles[i]); + + System.out.println(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_HEADER, formatBundleName(disabledBundles[i]), String.valueOf(disabledBundles[i].getBundleId()))); + System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_REASON, disabledInfos[0].getMessage(), disabledInfos[0].getPolicyName())); + + for (int j = 1; j < disabledInfos.length; j++) { + System.out.print(NLS.bind(ConsoleMsg.CONSOLE_DISABLED_BUNDLE_REASON, disabledInfos[j].getMessage(), String.valueOf(disabledInfos[j].getPolicyName()))); + } + + System.out.println(); + } + } + + private String formatBundleName(BundleDescription b) { + String label = b.getSymbolicName(); + if (label == null || label.length() == 0) + label = b.toString(); + else + label = label + "_" + b.getVersion(); //$NON-NLS-1$ + + return label; + } + + private String getResolutionFailureMessage(VersionConstraint unsatisfied) { + if (unsatisfied.isResolved()) + throw new IllegalArgumentException(); + if (unsatisfied instanceof ImportPackageSpecification) { + if (ImportPackageSpecification.RESOLUTION_OPTIONAL.equals(((ImportPackageSpecification) unsatisfied).getDirective(Constants.RESOLUTION_DIRECTIVE))) + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_OPTIONAL_IMPORTED_PACKAGE, versionToString(unsatisfied)); + if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(((ImportPackageSpecification) unsatisfied).getDirective(Constants.RESOLUTION_DIRECTIVE))) + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_DYNAMIC_IMPORTED_PACKAGE, versionToString(unsatisfied)); + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_IMPORTED_PACKAGE, versionToString(unsatisfied)); + } else if (unsatisfied instanceof BundleSpecification) { + if (((BundleSpecification) unsatisfied).isOptional()) + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_OPTIONAL_REQUIRED_BUNDLE, versionToString(unsatisfied)); + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIRED_BUNDLE, versionToString(unsatisfied)); + } else if (unsatisfied instanceof HostSpecification) { + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_HOST, versionToString(unsatisfied)); + } else if (unsatisfied instanceof NativeCodeSpecification) { + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_NATIVECODE, unsatisfied.toString()); + } else if (unsatisfied instanceof GenericSpecification) { + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIRED_CAPABILITY, unsatisfied.toString()); + } + return NLS.bind(ConsoleMsg.CONSOLE_MISSING_REQUIREMENT, unsatisfied.toString()); + } + + private static String versionToString(VersionConstraint constraint) { + org.eclipse.osgi.service.resolver.VersionRange versionRange = constraint.getVersionRange(); + if (versionRange == null) + return constraint.getName(); + return constraint.getName() + '_' + versionRange; + } /** * This is used to track lazily activated bundles. @@ -1817,3 +2017,4 @@ public class EquinoxCommandProvider implements SynchronousBundleListener { } } + |
