You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2011/01/28 09:28:56 UTC
svn commit: r1064479 - in /geronimo/server/branches/3.0-M2/framework:
configs/karaf-framework/ configs/karaf-framework/src/main/history/ modules/
modules/geronimo-shell-diagnose/ modules/geronimo-shell-diagnose/src/
modules/geronimo-shell-diagnose/src/...
Author: gawor
Date: Fri Jan 28 08:28:55 2011
New Revision: 1064479
URL: http://svn.apache.org/viewvc?rev=1064479&view=rev
Log:
GERONIMO-5779: Karaf shell command for diagnosing resolver problem (for Equinox only)
Added:
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml (with props)
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java (with props)
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/
geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml (with props)
Modified:
geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/pom.xml
geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/src/main/history/dependencies.xml
geronimo/server/branches/3.0-M2/framework/modules/pom.xml
Modified: geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/pom.xml?rev=1064479&r1=1064478&r2=1064479&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/pom.xml (original)
+++ geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/pom.xml Fri Jan 28 08:28:55 2011
@@ -409,6 +409,11 @@
</dependency>
<dependency>
<groupId>org.apache.geronimo.framework</groupId>
+ <artifactId>geronimo-shell-diagnose</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.framework</groupId>
<artifactId>geronimo-shell</artifactId>
<version>${version}</version>
</dependency>
Modified: geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/src/main/history/dependencies.xml?rev=1064479&r1=1064478&r2=1064479&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/src/main/history/dependencies.xml (original)
+++ geronimo/server/branches/3.0-M2/framework/configs/karaf-framework/src/main/history/dependencies.xml Fri Jan 28 08:28:55 2011
@@ -3,7 +3,7 @@
<module-id>
<groupId>org.apache.geronimo.framework</groupId>
<artifactId>karaf-framework</artifactId>
- <version>3.0-SNAPSHOT</version>
+ <version>3.0-M2-SNAPSHOT</version>
<type>car</type>
</module-id>
<dependency>
@@ -153,6 +153,11 @@
</dependency>
<dependency>
<groupId>org.apache.geronimo.framework</groupId>
+ <artifactId>geronimo-shell-diagnose</artifactId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.framework</groupId>
<artifactId>geronimo-system</artifactId>
<type>jar</type>
</dependency>
Added: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml?rev=1064479&view=auto
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml (added)
+++ geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml Fri Jan 28 08:28:55 2011
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.geronimo.framework</groupId>
+ <artifactId>modules</artifactId>
+ <version>3.0-M2-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.geronimo.framework</groupId>
+ <artifactId>geronimo-shell-diagnose</artifactId>
+ <packaging>bundle</packaging>
+ <version>3.0-M2-SNAPSHOT</version>
+ <name>Geronimo Framework, Modules :: Diagnose Shell Command</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.osgi.service.command;version="0.4.0",
+ org.eclipse.*;resolution:=optional,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java?rev=1064479&view=auto
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java (added)
+++ geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java Fri Jan 28 08:28:55 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<Long> 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<Long> 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/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/java/org/apache/geronimo/shell/diagnose/DiagnoseCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml?rev=1064479&view=auto
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml (added)
+++ geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml Fri Jan 28 08:28:55 2011
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ default-activation="lazy">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+ <command name="osgi/diagnose">
+ <action class="org.apache.geronimo.shell.diagnose.DiagnoseCommand"></action>
+ </command>
+ </command-bundle>
+
+</blueprint>
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/3.0-M2/framework/modules/geronimo-shell-diagnose/src/main/resources/OSGI-INF/blueprint/shell-diagnose.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: geronimo/server/branches/3.0-M2/framework/modules/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/modules/pom.xml?rev=1064479&r1=1064478&r2=1064479&view=diff
==============================================================================
--- geronimo/server/branches/3.0-M2/framework/modules/pom.xml (original)
+++ geronimo/server/branches/3.0-M2/framework/modules/pom.xml Fri Jan 28 08:28:55 2011
@@ -74,6 +74,7 @@
<!-- not needed for car-maven-plugin -->
<module>geronimo-shell</module>
<module>geronimo-shell-base</module>
+ <module>geronimo-shell-diagnose</module>
<module>geronimo-blueprint</module>
<module>geronimo-core</module>
<module>geronimo-deploy-jsr88-bootstrapper</module>