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 2011/12/06 06:43:40 UTC

svn commit: r1210789 - /felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java

Author: rickhall
Date: Tue Dec  6 05:43:40 2011
New Revision: 1210789

URL: http://svn.apache.org/viewvc?rev=1210789&view=rev
Log:
Apply patch FELIX-3257 to consider bundle version when selecting between
capabilities from bundles with the same symbolic name.

Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java?rev=1210789&r1=1210788&r2=1210789&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java (original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResolverImpl.java Tue Dec  6 05:43:40 2011
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -453,17 +453,34 @@ public class ResolverImpl implements Res
                         bestVersion = (Version) v;
                     }
                     // If the current resource version is equal to the
-                    // best, then select the one with the greatest
-                    // number of capabilities.
-                    else if ((bestVersion != null) && (bestVersion.compareTo(v) == 0)
-                            && (best.getResource().getCapabilities().length
-                                < current.getResource().getCapabilities().length))
+                    // best
+                    else if ((bestVersion != null) && (bestVersion.compareTo(v) == 0))
                     {
-                        best = current;
-                        bestLocal = isCurrentLocal;
-                        bestVersion = (Version) v;
+                        // If the symbolic name is the same, use the highest
+                        // bundle version.
+                        if ((best.getResource().getSymbolicName() != null)
+                            && best.getResource().getSymbolicName().equals(
+                                current.getResource().getSymbolicName()))
+                        {
+                            if (best.getResource().getVersion().compareTo(
+                                current.getResource().getVersion()) < 0)
+                            {
+                                best = current;
+                                bestLocal = isCurrentLocal;
+                                bestVersion = (Version) v;
+                            }
+                        }
+                        // Otherwise select the one with the greatest
+                        // number of capabilities.
+                        else if (best.getResource().getCapabilities().length
+                            < current.getResource().getCapabilities().length)
+                        {
+                            best = current;
+                            bestLocal = isCurrentLocal;
+                            bestVersion = (Version) v;
+                        }
                     }
-                }   
+                }
             }
         }
 
@@ -559,7 +576,7 @@ public class ResolverImpl implements Res
                             doStartBundle = true;
                             localResource.getBundle().stop();
                         }
-                        
+
                         localResource.getBundle().update(FileUtil.openURL(new URL(deployResources[i].getURI())));
 
                         // If necessary, save the updated bundle to be
@@ -567,7 +584,7 @@ public class ResolverImpl implements Res
                         if (doStartBundle)
                         {
                             Bundle bundle = localResource.getBundle();
-                            if (!isFragmentBundle(bundle)) 
+                            if (!isFragmentBundle(bundle))
                             {
                                 startList.add(bundle);
                             }
@@ -605,9 +622,9 @@ public class ResolverImpl implements Res
                         // started later.
                         if ((flags & START) != 0)
                         {
-                            if (!isFragmentBundle(bundle)) 
+                            if (!isFragmentBundle(bundle))
                             {
-                                startList.add(bundle);    
+                                startList.add(bundle);
                             }
                         }
                     }
@@ -616,7 +633,7 @@ public class ResolverImpl implements Res
                 {
                     m_logger.log(
                         Logger.LOG_ERROR,
-                        "Resolver: Install error - " + deployResources[i].getSymbolicName(), 
+                        "Resolver: Install error - " + deployResources[i].getSymbolicName(),
                         ex);
                     return;
                 }
@@ -641,15 +658,15 @@ public class ResolverImpl implements Res
 
     /**
      * Determines if the given bundle is a fragement bundle.
-     * 
+     *
      * @param bundle bundle to check
      * @return flag indicating if the given bundle is a fragement
      */
-    private boolean isFragmentBundle(Bundle bundle) 
+    private boolean isFragmentBundle(Bundle bundle)
     {
         return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
     }
-    
+
     // TODO: OBR - Think about this again and make sure that deployment ordering
     // won't impact it...we need to update the local state too.
     private LocalResourceImpl findUpdatableLocalResource(Resource resource)