You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/05/05 23:20:11 UTC
svn commit: r941496 - in
/felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands:
Activator.java Basic.java
Author: rickhall
Date: Wed May 5 21:20:10 2010
New Revision: 941496
URL: http://svn.apache.org/viewvc?rev=941496&view=rev
Log:
Add a "which" command to determine from where a bundle gets a class. (FELIX-2042)
Modified:
felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Activator.java
felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Basic.java
Modified: felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Activator.java?rev=941496&r1=941495&r2=941496&view=diff
==============================================================================
--- felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Activator.java (original)
+++ felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Activator.java Wed May 5 21:20:10 2010
@@ -31,7 +31,7 @@ public class Activator implements Bundle
props.put("osgi.command.function", new String[] {
"bundlelevel", "frameworklevel", "headers", "help",
"install", "lb", "refresh", "resolve", "start",
- "stop", "uninstall", "update" });
+ "stop", "uninstall", "update", "which" });
bc.registerService(
Basic.class.getName(), new Basic(bc), props);
Modified: felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Basic.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Basic.java?rev=941496&r1=941495&r2=941496&view=diff
==============================================================================
--- felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Basic.java (original)
+++ felix/trunk/gogo/felixcommands/src/main/java/org/apache/felix/gogo/felixcommands/Basic.java Wed May 5 21:20:10 2010
@@ -37,6 +37,7 @@ import java.util.TreeMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleReference;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -213,11 +214,11 @@ public class Basic
Descriptor d = m.getAnnotation(Descriptor.class);
if (d == null)
{
- System.out.println(m.getName());
+ System.out.println("\n" + m.getName());
}
else
{
- System.out.println(m.getName() + " - " + d.description());
+ System.out.println("\n" + m.getName() + " - " + d.description());
}
// Get flags and options.
@@ -288,7 +289,6 @@ public class Basic
System.out.println(" " + it.next() + " " + it.next());
}
}
- System.out.println("");
}
}
}
@@ -734,6 +734,40 @@ public class Basic
}
}
+ @Descriptor(description="determines from where a bundle loads a class")
+ public void which(
+ @Descriptor(description="target bundle identifier") Long id,
+ @Descriptor(description="target class name") String className)
+ {
+ Bundle bundle = getBundle(m_bc, id);
+ if (bundle == null)
+ {
+ return;
+ }
+ Class clazz = null;
+ try
+ {
+ clazz = bundle.loadClass(className);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ System.out.println("Class not found");
+ }
+ if (clazz.getClassLoader() == null)
+ {
+ System.out.println("Loaded from: boot class loader");
+ }
+ else if (clazz.getClassLoader() instanceof BundleReference)
+ {
+ Bundle p = ((BundleReference) clazz.getClassLoader()).getBundle();
+ System.out.println("Loaded from: " + p);
+ }
+ else
+ {
+ System.out.println("Loaded from: " + clazz.getClassLoader());
+ }
+ }
+
private static void printBundleList(
Bundle[] bundles, StartLevel startLevel, PrintStream out, boolean showLoc,
boolean showSymbolic, boolean showUpdate)