/** * Build the table of plug-in dependencies. Iterate over all the plug-ins in the plug-in registry * and the cycle through the list of pre-requisites and create the parent/child relationships in * the nodes. */ private Map getDependencyGraph() { if (dependencyGraph != null) return dependencyGraph; // Build up the dependency graph (see PluginDependencyGraphNode) so // we have the information readily available for any plug-in. State state = Platform.getPlatformAdmin().getState(false); BundleDescription[] plugins = state.getBundles(); dependencyGraph = new HashMap(); for (int i = 0; i < plugins.length; i++) { BundleDescription descriptor = plugins[i]; PluginDependencyGraphNode node = (PluginDependencyGraphNode) dependencyGraph.get(new Long(descriptor.getBundleId())); if (node == null) { node = new PluginDependencyGraphNode(descriptor); dependencyGraph.put(new Long(descriptor.getBundleId()), node); } // Cycle through the prerequisites BundleSpecification[] requires = descriptor.getRequiredBundles(); for (int j = 0; j < requires.length; j++) { BundleDescription childDesc = (BundleDescription) requires[j].getSupplier(); // if the child doesn't exist then move to the next child if (childDesc == null) continue; // if the child entry is not in the table yet then add it PluginDependencyGraphNode childNode = (PluginDependencyGraphNode) dependencyGraph.get(new Long(childDesc.getBundleId())); if (childNode == null) { childNode = new PluginDependencyGraphNode(childDesc); dependencyGraph.put(new Long(childDesc.getBundleId()), childNode); } // Add the child to this node's children and set this node as an ancestor // of the child node node.addChild(childNode); childNode.addAncestor(node); } } return dependencyGraph; }
/** * Diagnose loading of the bundle with the supplied name (ex. org.eclim.core). * * <p>Gleaned from org.eclipse.core.runtime.internal.adaptor.EclipseCommandProvider * * @param bundleName The bundle name to diagnose the loading of. * @return The diagnoses. */ @SuppressWarnings({"unchecked", "rawtypes"}) public String diagnose(String bundleName) { StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); BundleContext context = getDefault().getBundle().getBundleContext(); ServiceReference platformAdminRef = context.getServiceReference(PlatformAdmin.class.getName()); PlatformAdmin platformAdmin = (PlatformAdmin) context.getService(platformAdminRef); State state = platformAdmin.getState(false); BundleDescription bundle = null; BundleDescription[] allBundles = state.getBundles(bundleName); if (allBundles.length == 0) { writer.println( NLS.bind(EclipseAdaptorMsg.ECLIPSE_CONSOLE_CANNOT_FIND_BUNDLE_ERROR, bundleName)); } else { bundle = allBundles[0]; 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; } writer.print(" "); writer.println(resolverErrors[i].toString()); } if (unsatisfied.length == 0 && resolverErrors.length == 0) { writer.print(" "); writer.println(EclipseAdaptorMsg.ECLIPSE_CONSOLE_NO_CONSTRAINTS); } if (unsatisfied.length > 0) { writer.print(" "); writer.println(EclipseAdaptorMsg.ECLIPSE_CONSOLE_DIRECT_CONSTRAINTS); } for (int i = 0; i < unsatisfied.length; i++) { writer.print(" "); writer.println(MessageHelper.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; writer.print(" "); writer.println(EclipseAdaptorMsg.ECLIPSE_CONSOLE_LEAF_CONSTRAINTS); } writer.print(" "); writer.println( unsatisfiedLeaves[i].getBundle().getLocation() + " [" + unsatisfiedLeaves[i].getBundle().getBundleId() + "]"); writer.print(" "); writer.println(MessageHelper.getResolutionFailureMessage(unsatisfiedLeaves[i])); } } return out.toString(); }