Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 84559 invoked from network); 28 Jan 2011 08:49:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jan 2011 08:49:19 -0000 Received: (qmail 72435 invoked by uid 500); 28 Jan 2011 08:49:18 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 72311 invoked by uid 500); 28 Jan 2011 08:49:16 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 72304 invoked by uid 99); 28 Jan 2011 08:49:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 08:49:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 08:49:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0406023888DD; Fri, 28 Jan 2011 08:48:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1064489 - in /geronimo/server/trunk/framework: configs/karaf-framework/ configs/karaf-framework/src/main/filtered-resources/etc/ configs/karaf-framework/src/main/history/ modules/ modules/geronimo-shell-diagnose/ modules/geronimo-shell-dia... Date: Fri, 28 Jan 2011 08:48:53 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110128084854.0406023888DD@eris.apache.org> Author: gawor Date: Fri Jan 28 08:48:52 2011 New Revision: 1064489 URL: http://svn.apache.org/viewvc?rev=1064489&view=rev Log: GERONIMO-5779: Karaf shell command for diagnosing resolver problem (for Equinox only) Added: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml (with props) geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java (with props) geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml (with props) Modified: geronimo/server/trunk/framework/configs/karaf-framework/pom.xml geronimo/server/trunk/framework/configs/karaf-framework/src/main/filtered-resources/etc/startup.properties geronimo/server/trunk/framework/configs/karaf-framework/src/main/history/dependencies.xml geronimo/server/trunk/framework/modules/pom.xml Modified: geronimo/server/trunk/framework/configs/karaf-framework/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/pom.xml?rev=1064489&r1=1064488&r2=1064489&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/karaf-framework/pom.xml (original) +++ geronimo/server/trunk/framework/configs/karaf-framework/pom.xml Fri Jan 28 08:48:52 2011 @@ -409,6 +409,11 @@ org.apache.geronimo.framework + geronimo-shell-diagnose + ${project.version} + + + org.apache.geronimo.framework geronimo-shell ${version} Modified: geronimo/server/trunk/framework/configs/karaf-framework/src/main/filtered-resources/etc/startup.properties URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/src/main/filtered-resources/etc/startup.properties?rev=1064489&r1=1064488&r2=1064489&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/karaf-framework/src/main/filtered-resources/etc/startup.properties (original) +++ geronimo/server/trunk/framework/configs/karaf-framework/src/main/filtered-resources/etc/startup.properties Fri Jan 28 08:48:52 2011 @@ -91,4 +91,5 @@ org/apache/geronimo/specs/geronimo-javae org/apache/geronimo/framework/geronimo-deploy-tool/${pom.version}/geronimo-deploy-tool-${pom.version}.jar=40 org/apache/geronimo/framework/geronimo-deploy-config/${pom.version}/geronimo-deploy-config-${pom.version}.jar=40 org/apache/geronimo/framework/geronimo-shell-base/${pom.version}/geronimo-shell-base-${pom.version}.jar=40 +org/apache/geronimo/framework/geronimo-shell-diagnose/${pom.version}/geronimo-shell-diagnose-${pom.version}.jar=40 Modified: geronimo/server/trunk/framework/configs/karaf-framework/src/main/history/dependencies.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/src/main/history/dependencies.xml?rev=1064489&r1=1064488&r2=1064489&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/karaf-framework/src/main/history/dependencies.xml (original) +++ geronimo/server/trunk/framework/configs/karaf-framework/src/main/history/dependencies.xml Fri Jan 28 08:48:52 2011 @@ -153,6 +153,11 @@ org.apache.geronimo.framework + geronimo-shell-diagnose + jar + + + org.apache.geronimo.framework geronimo-system jar Added: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml?rev=1064489&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml (added) +++ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml Fri Jan 28 08:48:52 2011 @@ -0,0 +1,67 @@ + + + + + 4.0.0 + + org.apache.geronimo.framework + modules + 3.0-SNAPSHOT + + + org.apache.geronimo.framework + geronimo-shell-diagnose + bundle + 3.0-SNAPSHOT + Geronimo Framework, Modules :: Diagnose Shell Command + + + + org.apache.karaf.shell + org.apache.karaf.shell.console + + + + org.apache.aries.blueprint + org.apache.aries.blueprint + + + + org.eclipse + osgi + + + + + + + org.apache.felix + maven-bundle-plugin + + + + org.osgi.service.command;version="0.4.0", + org.eclipse.*;resolution:=optional, + * + + + + + + + Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java?rev=1064489&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java (added) +++ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java Fri Jan 28 08:48:52 2011 @@ -0,0 +1,178 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.shell.diagnose; + +import java.util.Iterator; +import java.util.List; + +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.osgi.service.resolver.BundleSpecification; +import org.eclipse.osgi.service.resolver.HostSpecification; +import org.eclipse.osgi.service.resolver.ImportPackageSpecification; +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.service.resolver.VersionRange; +import org.fusesource.jansi.Ansi; +import org.fusesource.jansi.Ansi.Color; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + +@Command(scope = "osgi", name = "diagnose", description = "Diagnose common OSGi resolver problems") +public class DiagnoseCommand extends OsgiCommandSupport { + + @Argument(index = 0, name = "ids", description = "The list of bundle IDs separated by whitespaces", required = true, multiValued = true) + List ids; + + private boolean hasPlatformAdmin() { + try { + bundleContext.getBundle().loadClass("org.eclipse.osgi.service.resolver.PlatformAdmin"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + protected Object doExecute() throws Exception { + if (!hasPlatformAdmin()) { + System.err.println("This command is only supported on Equinox."); + return null; + } + ServiceReference ref = bundleContext.getServiceReference(PlatformAdmin.class.getName()); + PlatformAdmin platformAdmin = (PlatformAdmin) getService(PlatformAdmin.class, ref); + + try { + State systemState = platformAdmin.getState(false); + + Iterator iterator = ids.iterator(); + while (iterator.hasNext()) { + Long id = iterator.next(); + BundleDescription bundle = systemState.getBundle(id); + if (bundle == null) { + System.err.println("Bundle ID" + id + " is invalid"); + continue; + } + diagnose(bundle, platformAdmin); + if (iterator.hasNext()) { + System.out.println(); + } + } + + } finally { + bundleContext.ungetService(ref); + } + + return null; + } + + private void diagnose(BundleDescription bundle, PlatformAdmin platformAdmin) { + System.out.println(bundle.getLocation() + " [" + bundle.getBundleId() + "]"); + + StateHelper stateHelper = platformAdmin.getStateHelper(); + VersionConstraint[] unsatisfied = stateHelper.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(" "); + System.out.println(resolverErrors[i].toString()); + } + + if (unsatisfied.length == 0 && resolverErrors.length == 0) { + System.out.print(" "); + System.out.println("No unresolved constraints."); + } + if (unsatisfied.length > 0) { + System.out.print(" "); + System.out.println("Unresolved direct constraints:"); + for (int i = 0; i < unsatisfied.length; i++) { + System.out.print(" "); + System.out.println(getResolutionFailureMessage(unsatisfied[i])); + } + } + + VersionConstraint[] unsatisfiedLeaves = stateHelper.getUnsatisfiedLeaves(new BundleDescription[] { bundle }); + boolean foundLeaf = false; + for (int i = 0; i < unsatisfiedLeaves.length; i++) { + BundleDescription leafBundle = unsatisfiedLeaves[i].getBundle(); + if (leafBundle == bundle) { + continue; + } + if (!foundLeaf) { + foundLeaf = true; + System.out.print(" "); + System.out.println("Unresolved constraints in dependency chain:"); + } + System.out.print(" "); + System.out.println(leafBundle.getLocation() + " [" + leafBundle.getBundleId() + "]"); + System.out.print(" "); + System.out.println(getResolutionFailureMessage(unsatisfiedLeaves[i])); + } + } + + public static String getResolutionFailureMessage(VersionConstraint unsatisfied) { + if (unsatisfied.isResolved()) + throw new IllegalArgumentException(); + if (unsatisfied instanceof ImportPackageSpecification) { + String resolution = (String) ((ImportPackageSpecification) unsatisfied).getDirective(Constants.RESOLUTION_DIRECTIVE); + if (ImportPackageSpecification.RESOLUTION_OPTIONAL.equals(resolution)) { + return warning("Missing optionally imported package " + toString(unsatisfied)); + } else if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(resolution)) { + return warning("Missing dynamically imported package " + toString(unsatisfied)); + } else { + return error("Missing imported package " + toString(unsatisfied)); + } + } else if (unsatisfied instanceof BundleSpecification) { + if (((BundleSpecification) unsatisfied).isOptional()) { + return warning("Missing optionally required bundle" + toString(unsatisfied)); + } else { + return error("Missing required bundle" + toString(unsatisfied)); + } + } else if (unsatisfied instanceof HostSpecification) { + return error("Missing host bundle " + toString(unsatisfied)); + } else { + return error("Unknown problem"); + } + } + + private static String toString(VersionConstraint constraint) { + VersionRange versionRange = constraint.getVersionRange(); + if (versionRange == null) { + return constraint.getName(); + } else { + return constraint.getName() + '_' + versionRange; + } + } + + private static String error(String msg) { + return Ansi.ansi().fg(Color.RED).a(msg).reset().toString(); + } + + private static String warning(String msg) { + return Ansi.ansi().fg(Color.YELLOW).a(msg).reset().toString(); + } +} Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml?rev=1064489&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml (added) +++ geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml Fri Jan 28 08:48:52 2011 @@ -0,0 +1,29 @@ + + + + + + + + + + + Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: geronimo/server/trunk/framework/modules/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/pom.xml?rev=1064489&r1=1064488&r2=1064489&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/pom.xml (original) +++ geronimo/server/trunk/framework/modules/pom.xml Fri Jan 28 08:48:52 2011 @@ -74,6 +74,7 @@ geronimo-shell geronimo-shell-base + geronimo-shell-diagnose geronimo-blueprint geronimo-core geronimo-deploy-jsr88-bootstrapper