Update already installed bundles. (FELIX-1446)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@801308 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/main/src/main/java/org/apache/felix/main/AutoActivator.java b/main/src/main/java/org/apache/felix/main/AutoActivator.java
index 2947fbe..10baab5 100644
--- a/main/src/main/java/org/apache/felix/main/AutoActivator.java
+++ b/main/src/main/java/org/apache/felix/main/AutoActivator.java
@@ -19,18 +19,9 @@
 package org.apache.felix.main;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.service.startlevel.StartLevel;
+import java.util.*;
+import org.osgi.framework.*;
+import org.osgi.service.startlevel.*;
 
 public class AutoActivator implements BundleActivator
 {
@@ -96,6 +87,14 @@
         enabled = (enabled == null) ? Boolean.TRUE.toString() : enabled;
         if (Boolean.valueOf(enabled).booleanValue())
         {
+            // Get list of already installed bundles as a map.
+            Map bundleMap = new HashMap();
+            Bundle[] bundles = context.getBundles();
+            for (int i = 0; i < bundles.length; i++)
+            {
+                bundleMap.put(bundles[i].getLocation(), bundles[i]);
+            }
+
             // Get the auto deploy directory.
             String autoDir = (String) m_configMap.get(AUTO_DEPLOY_DIR_PROPERY);
             autoDir = (autoDir == null) ? AUTO_DEPLOY_DIR_VALUE : autoDir;
@@ -118,10 +117,19 @@
                 final List installedList = new ArrayList();
                 for (int i = 0; i < bundleList.size(); i++)
                 {
+                    Bundle b = (Bundle) bundleMap.get(
+                        ((File) bundleList.get(i)).toURI().toString());
                     try
                     {
-                        Bundle b = context.installBundle(
-                            ((File) bundleList.get(i)).toURI().toString());
+                        if (b == null)
+                        {
+                            b = context.installBundle(
+                                ((File) bundleList.get(i)).toURI().toString());
+                        }
+                        else
+                        {
+                            b.update();
+                        }
                         installedList.add(b);
                     }
                     catch (BundleException ex)