incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r897313 - in /incubator/aries/trunk/jmx/jmx-core/src: main/java/org/apache/aries/jmx/codec/ main/java/org/apache/aries/jmx/framework/ main/java/org/apache/aries/jmx/util/ test/java/org/apache/aries/jmx/codec/ test/java/org/apache/aries/jmx/...
Date Fri, 08 Jan 2010 20:07:13 GMT
Author: atk
Date: Fri Jan  8 20:07:12 2010
New Revision: 897313

URL: http://svn.apache.org/viewvc?rev=897313&view=rev
Log:
ARIES-108 NullPointerException thrown resolving imported packages or dependencies

Modified:
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java?rev=897313&r1=897312&r2=897313&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
Fri Jan  8 20:07:12 2010
@@ -71,6 +71,7 @@
 import javax.management.openmbean.TabularDataSupport;
 
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.jmx.framework.BundleStateMBean;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
@@ -190,7 +191,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public BundleData(Bundle bundle, PackageAdmin packageAdmin, StartLevel startLevel) {
+    public BundleData(BundleContext localBundleContext, Bundle bundle, PackageAdmin packageAdmin,
StartLevel startLevel) {
         if (bundle == null) {
             throw new IllegalArgumentException("Argument bundle cannot be null");
         }
@@ -208,14 +209,14 @@
         }
         this.hosts = getHostIds(bundle, packageAdmin);
         this.identifier = bundle.getBundleId();
-        this.importedPackages = getBundleImportedPackages(bundle, packageAdmin);
+        this.importedPackages = getBundleImportedPackages(localBundleContext, bundle, packageAdmin);
         this.lastModified = bundle.getLastModified();
         this.location = bundle.getLocation();
         this.persistentlyStarted = startLevel.isBundlePersistentlyStarted(bundle);
         this.registeredServices = getRegisteredServiceIds(bundle);
         this.removalPending = isBundlePendingRemoval(bundle, packageAdmin);
         this.required = isBundleRequiredByOthers(bundle, packageAdmin);
-        this.requiredBundles = getBundleDependencies(bundle, packageAdmin);
+        this.requiredBundles = getBundleDependencies(localBundleContext, bundle, packageAdmin);
         this.requiringBundles = getDependentBundles(bundle, packageAdmin);
         this.servicesInUse = getServicesInUseByBundle(bundle);
         this.bundleStartLevel = startLevel.getBundleStartLevel(bundle);

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java?rev=897313&r1=897312&r2=897313&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
Fri Jan  8 20:07:12 2010
@@ -140,7 +140,7 @@
      */
     public String[] getImportedPackages(long bundleId) throws IOException, IllegalArgumentException
{
         Bundle bundle = resolveBundle(bundleContext, bundleId);
-        return getBundleImportedPackages(bundle, packageAdmin);
+        return getBundleImportedPackages(bundleContext, bundle, packageAdmin);
     }
 
     /**
@@ -172,7 +172,7 @@
      */
     public long[] getRequiredBundles(long bundleIdentifier) throws IOException, IllegalArgumentException
{
         Bundle bundle = resolveBundle(bundleContext, bundleIdentifier);
-        return getBundleDependencies(bundle, packageAdmin);
+        return getBundleDependencies(bundleContext, bundle, packageAdmin);
     }
 
     /**
@@ -262,7 +262,7 @@
         Bundle[] containerBundles = bundleContext.getBundles();
         List<BundleData> bundleDatas = new ArrayList<BundleData>();
         for (Bundle containerBundle : containerBundles) {
-            bundleDatas.add(new BundleData(containerBundle, packageAdmin, startLevel));
+            bundleDatas.add(new BundleData(bundleContext, containerBundle, packageAdmin,
startLevel));
         }
         TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
         for (BundleData bundleData : bundleDatas) {

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java?rev=897313&r1=897312&r2=897313&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
Fri Jan  8 20:07:12 2010
@@ -210,14 +210,15 @@
 
     /**
      * Returns the resolved package imports for the given bundle
-     * 
-     * @param bundle
+     * @param localBundleContext BundleContext object of this bundle/caller
+     * @param bundle target Bundle object to query imported packages for
      * @param packageAdmin
+     * 
      * @return
      * @throws IllegalArgumentException
      *             if fragment or packageAdmin are null
      */
-    public static String[] getBundleImportedPackages(Bundle bundle, PackageAdmin packageAdmin)
+    public static String[] getBundleImportedPackages(BundleContext localBundleContext, Bundle
bundle, PackageAdmin packageAdmin)
             throws IllegalArgumentException {
         if (bundle == null) {
             throw new IllegalArgumentException("Argument bundle cannot be null");
@@ -228,7 +229,7 @@
         List<String> result = new ArrayList<String>();
         // TODO - Is there an easier way to achieve this? Unable to find a direct way through
Framework
         // API to find the actual package wiring
-        Bundle[] bundles = bundle.getBundleContext().getBundles();
+        Bundle[] bundles = localBundleContext.getBundles();
         for (Bundle candidate : bundles) {
             if (candidate.equals(bundle)) {
                 continue;
@@ -366,14 +367,15 @@
 
     /**
      * Returns an array of ids of bundles the given bundle depends on
-     * 
-     * @param bundle
+     * @param localBundleContext BundleContext object of this bundle/caller 
+     * @param bundle target Bundle object to query dependencies for
      * @param packageAdmin
+     * 
      * @return
      * @throws IllegalArgumentException
      *             if bundle or packageAdmin are null
      */
-    public static long[] getBundleDependencies(Bundle bundle, PackageAdmin packageAdmin)
+    public static long[] getBundleDependencies(BundleContext localBundleContext, Bundle bundle,
PackageAdmin packageAdmin)
             throws IllegalArgumentException {
         if (bundle == null) {
             throw new IllegalArgumentException("Argument bundle cannot be null");
@@ -384,7 +386,7 @@
         List<Bundle> dependencies = new ArrayList<Bundle>();
         // TODO - Is there an easier way to achieve this? Unable to find a direct way through
Framework
         // API to resolve the current dependencies
-        for (Bundle candidate : bundle.getBundleContext().getBundles()) {
+        for (Bundle candidate : localBundleContext.getBundles()) {
             if (candidate.equals(bundle)) {
                 continue;
             }

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java?rev=897313&r1=897312&r2=897313&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
Fri Jan  8 20:07:12 2010
@@ -99,7 +99,6 @@
         when(bundle.getSymbolicName()).thenReturn("test");
         when(bundle.getVersion()).thenReturn(Version.emptyVersion);
         when(bundle.getBundleId()).thenReturn(new Long(1));
-        when(bundle.getBundleContext()).thenReturn(context);
         when(bundle.getLastModified()).thenReturn(new Long(12345));
         when(bundle.getLocation()).thenReturn("location");
         
@@ -154,7 +153,7 @@
         
         when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 });
         
-        BundleData b = new BundleData(bundle, packageAdmin, startLevel);
+        BundleData b = new BundleData(context, bundle, packageAdmin, startLevel);
         CompositeData compositeData = b.toCompositeData();
         
         assertEquals("test", compositeData.get(SYMBOLIC_NAME));

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java?rev=897313&r1=897312&r2=897313&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
Fri Jan  8 20:07:12 2010
@@ -120,7 +120,6 @@
         
         Bundle bundle = mock(Bundle.class);
         BundleContext context = mock(BundleContext.class);
-        when(bundle.getBundleContext()).thenReturn(context);
         
         Bundle b1 = mock(Bundle.class);
         Bundle b2 = mock(Bundle.class);
@@ -143,7 +142,7 @@
         when(admin.getExportedPackages(b3)).thenReturn(null);
         
         assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"}

-                    , getBundleImportedPackages(bundle, admin));
+                    , getBundleImportedPackages(context, bundle, admin));
         
     }
     
@@ -227,8 +226,7 @@
         
         Bundle bundle = mock(Bundle.class);
         BundleContext context = mock(BundleContext.class);
-        when(bundle.getBundleContext()).thenReturn(context);
-        
+       
         Bundle b1 = mock(Bundle.class);
         when(b1.getSymbolicName()).thenReturn("b1");
         when(b1.getBundleId()).thenReturn(new Long(44));
@@ -242,7 +240,7 @@
         when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
         
         PackageAdmin admin = mock(PackageAdmin.class);
-        assertEquals(0, getBundleDependencies(bundle, admin).length);
+        assertEquals(0, getBundleDependencies(context, bundle, admin).length);
         
         RequiredBundle rb1 = mock(RequiredBundle.class);
         when(rb1.getBundle()).thenReturn(b1);
@@ -258,8 +256,10 @@
         when(admin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
         when(admin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
         
-        assertArrayEquals(new long[] { 44, 66 }, getBundleDependencies(bundle, admin));
+        assertArrayEquals(new long[] { 44, 66 }, getBundleDependencies(context, bundle, admin));
         
         
     }
+    
+    
 }



Mime
View raw message