FELIX-2119 Prevent ClassDefNotFoundException if OBR API is not available: Refactoring the BaseUpdateInstallHelper class to not extend the Thread class any more.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@918442 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
index c0687e6..d43d224 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
@@ -32,21 +32,28 @@
 import org.osgi.service.packageadmin.PackageAdmin;
 
 
-abstract class BaseUpdateInstallHelper extends Thread
+abstract class BaseUpdateInstallHelper
 {
 
     private final File bundleFile;
 
     private final boolean refreshPackages;
 
+    private Thread updateThread;
+
 
     BaseUpdateInstallHelper( String name, File bundleFile, boolean refreshPackages )
     {
-        super( name );
-        setDaemon( true );
-
         this.bundleFile = bundleFile;
         this.refreshPackages = refreshPackages;
+        this.updateThread = new Thread( name )
+        {
+            public void run()
+            {
+                BaseUpdateInstallHelper.this.run();
+            };
+        };
+        this.updateThread.setDaemon( true );
     }
 
 
@@ -83,11 +90,19 @@
         {
             IOUtils.closeQuietly( bundleStream );
         }
-
     }
 
 
-    public void run()
+    final void start()
+    {
+        if ( updateThread != null )
+        {
+            updateThread.start();
+        }
+    }
+
+
+    void run()
     {
         // wait some time for the request to settle
         sleepSilently( 500L );
@@ -126,6 +141,9 @@
             {
                 bundleFile.delete();
             }
+
+            // release update thread for GC
+            updateThread = null;
         }
     }
 
@@ -134,7 +152,7 @@
     {
         try
         {
-            sleep( msecs );
+            Thread.sleep( msecs );
         }
         catch ( InterruptedException ie )
         {
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 1a5a3bb..45c4ca0 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -95,7 +95,7 @@
     private boolean[] bootPkgWildcards;
 
     private ServiceRegistration configurationPrinter;
-    
+
     // templates
     private final String TEMPLATE_MAIN;
     private final String TEMPLATE_UPLOAD;
@@ -106,8 +106,8 @@
         super(NAME, TITLE, CSS);
 
         // load templates
-        TEMPLATE_MAIN = readTemplateFile( "/templates/bundles.html" ); 
-        TEMPLATE_UPLOAD = readTemplateFile( "/templates/bundles_upload.html" ); 
+        TEMPLATE_MAIN = readTemplateFile( "/templates/bundles.html" );
+        TEMPLATE_UPLOAD = readTemplateFile( "/templates/bundles_upload.html" );
     }
 
     /**
@@ -446,7 +446,7 @@
             StringWriter w = new StringWriter();
             writeJSON(w, reqInfo.bundle, pluginRoot, servicesRoot, request.getLocale() );
             vars.put( "__bundles__", w.toString());
-            
+
             response.getWriter().print(TEMPLATE_MAIN);
         }
     }
@@ -487,11 +487,11 @@
 
             jw.key( "status" );
             jw.value( statusLine );
-            
+
             // add raw status
             jw.key( "s" );
             jw.array();
-            for ( int i = 0; i < 5; i++ ) jw.value(status[i]); 
+            for ( int i = 0; i < 5; i++ ) jw.value(status[i]);
             jw.endArray();
 
             jw.key( "data" );
@@ -1279,7 +1279,7 @@
 
     private void update( final Bundle bundle )
     {
-        Thread t = new UpdateHelper( bundle, false )
+        UpdateHelper t = new UpdateHelper( bundle, false )
         {
             protected Logger getLog()
             {
@@ -1347,17 +1347,17 @@
     {
         return (RequestInfo)request.getAttribute( BundlesServlet.class.getName() );
     }
-    
+
     private final PackageAdmin getPackageAdmin()
     {
         return ( PackageAdmin ) getService( PackageAdmin.class.getName() );
     }
-    
+
     private final StartLevel getStartLevel()
     {
         return ( StartLevel ) getService( StartLevel.class.getName() );
     }
-    
+
     // TODO: may remove later, when BaseWebConsolePlugin is made to extend SimpleWebConsolePlugin
     private Logger log;
     Logger getLog()
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
index b3b4847..76f2aea 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
@@ -274,7 +274,8 @@
         final boolean doStart, final boolean refreshPackages )
     {
 
-        Thread t = new InstallHelper( getBundleContext(), bundleFile, location, startlevel, doStart, refreshPackages )
+        InstallHelper t = new InstallHelper( getBundleContext(), bundleFile, location, startlevel, doStart,
+            refreshPackages )
         {
             protected Logger getLog()
             {
@@ -303,7 +304,7 @@
 
     private void updateBackground( final Bundle bundle, final File bundleFile, final boolean refreshPackages )
     {
-        Thread t = new UpdateHelper( bundle, bundleFile, refreshPackages )
+        UpdateHelper t = new UpdateHelper( bundle, bundleFile, refreshPackages )
         {
             protected Logger getLog()
             {