You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2017/02/10 13:09:34 UTC

svn commit: r1782463 - in /felix/trunk/framework/src: main/java/org/apache/felix/framework/Felix.java test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java

Author: pauls
Date: Fri Feb 10 13:09:34 2017
New Revision: 1782463

URL: http://svn.apache.org/viewvc?rev=1782463&view=rev
Log:
Replace some tabs with spaces (urgs).

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1782463&r1=1782462&r2=1782463&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Fri Feb 10 13:09:34 2017
@@ -2215,12 +2215,12 @@ public class Felix extends BundleImpl im
             Throwable rethrow = null;
             try
             {
-	            // Set the bundle's activator.
-	            bundle.setActivator(createBundleActivator(bundle));
+                // Set the bundle's activator.
+                bundle.setActivator(createBundleActivator(bundle));
             }
             catch (Throwable th) 
             {
-            	rethrow = th;
+                rethrow = th;
             }
 
             try
@@ -2230,7 +2230,7 @@ public class Felix extends BundleImpl im
                 
                 if (rethrow != null) 
                 {
-                	throw rethrow;
+                    throw rethrow;
                 }
                 // Activate the bundle if it has an activator.
                 if (bundle.getActivator() != null)
@@ -2333,15 +2333,15 @@ public class Felix extends BundleImpl im
         // in a finally block.
         try
         {
-        	// Check if the bundle is not currently STARTING or STOPPING because if it is
-        	// we are in a loop where the bundle being started or stopped triggered an update
-        	// of itself (either directly or indirectly) which we can not handle.
-        	if ((bundle.getState() & (Bundle.STARTING | Bundle.STOPPING)) != 0) 
-        	{
-        		throw new BundleException("Bundle " + bundle
+            // Check if the bundle is not currently STARTING or STOPPING because if it is
+            // we are in a loop where the bundle being started or stopped triggered an update
+            // of itself (either directly or indirectly) which we can not handle.
+            if ((bundle.getState() & (Bundle.STARTING | Bundle.STOPPING)) != 0) 
+            {
+                throw new BundleException("Bundle " + bundle
                     + " cannot be update, since it is either STARTING or STOPPING.");
-        	}
-        	
+            }
+            
             // Variable to indicate whether bundle is active or not.
             Throwable rethrow = null;
 

Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java?rev=1782463&r1=1782462&r2=1782463&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java (original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/ConcurrentBundleUpdateTest.java Fri Feb 10 13:09:34 2017
@@ -45,9 +45,9 @@ import junit.framework.TestCase;
 
 public class ConcurrentBundleUpdateTest extends TestCase 
 {
-	public void testConcurrentBundleUpdate() throws Exception
-	{
-		Map params = new HashMap();
+    public void testConcurrentBundleUpdate() throws Exception
+    {
+        Map params = new HashMap();
         params.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
             "org.osgi.framework; version=1.4.0,"
             + "org.osgi.service.packageadmin; version=1.2.0,"
@@ -66,146 +66,146 @@ public class ConcurrentBundleUpdateTest
         
         try
         {
-        	Felix felix = new Felix(params);
-        	try
-        	{
-	        	felix.init();
-	        	felix.start();
-	        	
-	        	String mf = "Bundle-SymbolicName: test.concurrent.bundleupdate\n"
-	                    + "Bundle-Version: 1.0.0\n"
-	                    + "Bundle-ManifestVersion: 2\n"
-	                    + "Import-Package: org.osgi.framework\n"
-	                    + "Manifest-Version: 1.0\n"
-	                    + "Bundle-Activator: " + ConcurrentBundleUpdaterActivator.class.getName() + "\n\n";
-	        	
-	        	final BundleImpl updater = (BundleImpl) felix.getBundleContext().installBundle(createBundle(mf, ConcurrentBundleUpdaterActivator.class).toURI().toURL().toString());
-	        	
-	        	final Semaphore step = new Semaphore(0);
-	        	SynchronousBundleListener listenerStarting = new SynchronousBundleListener() 
-	        	{
-					
-					@Override
-					public void bundleChanged(BundleEvent event) 
-					{
-						if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTING)
-						{
-							step.release();
-						}
-					}
-				};
-	        	felix.getBundleContext().addBundleListener(listenerStarting);
-	        	new Thread()
-	        	{
-	        		public void run() 
-	        		{
-	        			try
-	        			{
-	        				updater.start();
-	        			}
-	        			catch (Exception ex) 
-	        			{
-	        				
-	        			}
-	        		}
-	        	}.start();
-	        	
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	
-	        	felix.getBundleContext().removeBundleListener(listenerStarting);
-	        	
-	        	assertEquals(Bundle.STARTING, updater.getState());
-	        	assertEquals(0, step.availablePermits());
-	        	
-	        	new Thread() 
-	        	{
-	        		public void run() 
-	        		{
-			        	try 
-			        	{
-			        		step.release();
-			        		updater.update();
-			        		step.release();
-			        	}
-			        	catch (Exception ex)
-			        	{
-			        	}
-	        		}
-	        	}.start();
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	SynchronousBundleListener listenerStarted = new SynchronousBundleListener() 
-	        	{	
-					@Override
-					public void bundleChanged(BundleEvent event) 
-					{
-						if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTED)
-						{
-							step.release();
-						}
-						if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STOPPING)
-						{
-							step.release();
-						}
-					}
-				};
-	        	felix.getBundleContext().addBundleListener(listenerStarted);
-	        	
-	        	((Runnable) updater.getActivator()).run();
-	        	
-	        	assertTrue(step.tryAcquire(2, 1, TimeUnit.SECONDS));
-	        	
-	        	felix.getBundleContext().removeBundleListener(listenerStarted);
-	        	
-	        	assertEquals(0, step.availablePermits());
-	        	
-	        	assertEquals(Bundle.STOPPING, updater.getState());
-	        	
-	        	felix.getBundleContext().addBundleListener(listenerStarting);
+            Felix felix = new Felix(params);
+            try
+            {
+                felix.init();
+                felix.start();
+                
+                String mf = "Bundle-SymbolicName: test.concurrent.bundleupdate\n"
+                        + "Bundle-Version: 1.0.0\n"
+                        + "Bundle-ManifestVersion: 2\n"
+                        + "Import-Package: org.osgi.framework\n"
+                        + "Manifest-Version: 1.0\n"
+                        + "Bundle-Activator: " + ConcurrentBundleUpdaterActivator.class.getName() + "\n\n";
+                
+                final BundleImpl updater = (BundleImpl) felix.getBundleContext().installBundle(createBundle(mf, ConcurrentBundleUpdaterActivator.class).toURI().toURL().toString());
+                
+                final Semaphore step = new Semaphore(0);
+                SynchronousBundleListener listenerStarting = new SynchronousBundleListener() 
+                {
+                    
+                    @Override
+                    public void bundleChanged(BundleEvent event) 
+                    {
+                        if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTING)
+                        {
+                            step.release();
+                        }
+                    }
+                };
+                felix.getBundleContext().addBundleListener(listenerStarting);
+                new Thread()
+                {
+                    public void run() 
+                    {
+                        try
+                        {
+                            updater.start();
+                        }
+                        catch (Exception ex) 
+                        {
+                            
+                        }
+                    }
+                }.start();
+                
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                
+                felix.getBundleContext().removeBundleListener(listenerStarting);
+                
+                assertEquals(Bundle.STARTING, updater.getState());
+                assertEquals(0, step.availablePermits());
+                
+                new Thread() 
+                {
+                    public void run() 
+                    {
+                        try 
+                        {
+                            step.release();
+                            updater.update();
+                            step.release();
+                        }
+                        catch (Exception ex)
+                        {
+                        }
+                    }
+                }.start();
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                SynchronousBundleListener listenerStarted = new SynchronousBundleListener() 
+                {    
+                    @Override
+                    public void bundleChanged(BundleEvent event) 
+                    {
+                        if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTED)
+                        {
+                            step.release();
+                        }
+                        if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STOPPING)
+                        {
+                            step.release();
+                        }
+                    }
+                };
+                felix.getBundleContext().addBundleListener(listenerStarted);
+                
+                ((Runnable) updater.getActivator()).run();
+                
+                assertTrue(step.tryAcquire(2, 1, TimeUnit.SECONDS));
+                
+                felix.getBundleContext().removeBundleListener(listenerStarted);
+                
+                assertEquals(0, step.availablePermits());
+                
+                assertEquals(Bundle.STOPPING, updater.getState());
+                
+                felix.getBundleContext().addBundleListener(listenerStarting);
 
-	        	((Runnable) updater.getActivator()).run();
-	        
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	
-	        	felix.getBundleContext().removeBundleListener(listenerStarting);
-	        	
-	        	assertEquals(Bundle.STARTING, updater.getState());
-	        	
-	        	((Runnable) updater.getActivator()).run();
-	        	
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	
-	        	assertEquals(Bundle.ACTIVE, updater.getState());
-	        	
-	        	((Runnable) updater.getActivator()).run();
-	        	
-	        	updater.uninstall();
-	        	
-	        	assertEquals(Bundle.UNINSTALLED, updater.getState());
-	        	
-	        	try 
-	        	{
-	        		updater.update();
-	        		fail("Expected exception on update of uninstalled bundle");
-	        	}
-	        	catch (IllegalStateException expected) {
-	        		
-	        	}
-        	}
-        	finally 
-        	{
-        		felix.stop();
-        		felix.waitForStop(1000);
-        	}
+                ((Runnable) updater.getActivator()).run();
+            
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                
+                felix.getBundleContext().removeBundleListener(listenerStarting);
+                
+                assertEquals(Bundle.STARTING, updater.getState());
+                
+                ((Runnable) updater.getActivator()).run();
+                
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                
+                assertEquals(Bundle.ACTIVE, updater.getState());
+                
+                ((Runnable) updater.getActivator()).run();
+                
+                updater.uninstall();
+                
+                assertEquals(Bundle.UNINSTALLED, updater.getState());
+                
+                try 
+                {
+                    updater.update();
+                    fail("Expected exception on update of uninstalled bundle");
+                }
+                catch (IllegalStateException expected) {
+                    
+                }
+            }
+            finally 
+            {
+                felix.stop();
+                felix.waitForStop(1000);
+            }
         } 
         finally
         {
-        	delete(cacheDir);
+            delete(cacheDir);
         }
-	}
-	
-	public void testConcurrentBundleCycleUpdate() throws Exception
-	{
-		Map params = new HashMap();
+    }
+    
+    public void testConcurrentBundleCycleUpdate() throws Exception
+    {
+        Map params = new HashMap();
         params.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
             "org.osgi.framework; version=1.4.0,"
             + "org.osgi.service.packageadmin; version=1.2.0,"
@@ -224,155 +224,155 @@ public class ConcurrentBundleUpdateTest
         
         try
         {
-        	Felix felix = new Felix(params);
-        	try
-        	{
-	        	felix.init();
-	        	felix.start();
-	        	
-	        	String mf = "Bundle-SymbolicName: test.concurrent.bundleupdate\n"
-	                    + "Bundle-Version: 1.0.0\n"
-	                    + "Bundle-ManifestVersion: 2\n"
-	                    + "Import-Package: org.osgi.framework\n"
-	                    + "Manifest-Version: 1.0\n"
-	                    + "Bundle-Activator: " + ConcurrentBundleUpdaterCycleActivator.class.getName() + "\n\n";
-	        	
-	        	final BundleImpl updater = (BundleImpl) felix.getBundleContext().installBundle(createBundle(mf, ConcurrentBundleUpdaterCycleActivator.class).toURI().toURL().toString());
-	        	
-	        	final Semaphore step = new Semaphore(0);
-	        	SynchronousBundleListener listenerStarting = new SynchronousBundleListener() 
-	        	{
-					@Override
-					public void bundleChanged(BundleEvent event) 
-					{
-						if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTING)
-						{
-							step.release();
-						}
-					}
-				};
-	        	felix.getBundleContext().addBundleListener(listenerStarting);
-	        	new Thread()
-	        	{
-	        		public void run() 
-	        		{
-	        			try 
-	        			{
-	        				updater.start();
-	        			} 
-	        			catch (Exception ex)
-	        			{
-	        				step.release();
-	        			}
-	        		}
-	        	}.start();
-	        	
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	
-	        	felix.getBundleContext().removeBundleListener(listenerStarting);
-	        	
-	        	assertEquals(Bundle.STARTING, updater.getState());
-	        	assertEquals(0, step.availablePermits());
+            Felix felix = new Felix(params);
+            try
+            {
+                felix.init();
+                felix.start();
+                
+                String mf = "Bundle-SymbolicName: test.concurrent.bundleupdate\n"
+                        + "Bundle-Version: 1.0.0\n"
+                        + "Bundle-ManifestVersion: 2\n"
+                        + "Import-Package: org.osgi.framework\n"
+                        + "Manifest-Version: 1.0\n"
+                        + "Bundle-Activator: " + ConcurrentBundleUpdaterCycleActivator.class.getName() + "\n\n";
+                
+                final BundleImpl updater = (BundleImpl) felix.getBundleContext().installBundle(createBundle(mf, ConcurrentBundleUpdaterCycleActivator.class).toURI().toURL().toString());
+                
+                final Semaphore step = new Semaphore(0);
+                SynchronousBundleListener listenerStarting = new SynchronousBundleListener() 
+                {
+                    @Override
+                    public void bundleChanged(BundleEvent event) 
+                    {
+                        if (event.getBundle().equals(updater) && event.getType() == BundleEvent.STARTING)
+                        {
+                            step.release();
+                        }
+                    }
+                };
+                felix.getBundleContext().addBundleListener(listenerStarting);
+                new Thread()
+                {
+                    public void run() 
+                    {
+                        try 
+                        {
+                            updater.start();
+                        } 
+                        catch (Exception ex)
+                        {
+                            step.release();
+                        }
+                    }
+                }.start();
+                
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                
+                felix.getBundleContext().removeBundleListener(listenerStarting);
+                
+                assertEquals(Bundle.STARTING, updater.getState());
+                assertEquals(0, step.availablePermits());
 
-	        	((Runnable) updater.getActivator()).run();
-	        	
-	        	assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
-	        	assertEquals(Bundle.RESOLVED, updater.getState());
-	        	
-	        	updater.uninstall();
-	        	
-	        	assertEquals(Bundle.UNINSTALLED, updater.getState());
-	        	
-	        	try 
-	        	{
-	        		updater.update();
-	        		fail("Expected exception on update of uninstalled bundle");
-	        	}
-	        	catch (IllegalStateException expected) {
-	        		
-	        	}
-        	}
-        	finally 
-        	{
-        		felix.stop();
-        		felix.waitForStop(1000);
-        	}
+                ((Runnable) updater.getActivator()).run();
+                
+                assertTrue(step.tryAcquire(1, TimeUnit.SECONDS));
+                assertEquals(Bundle.RESOLVED, updater.getState());
+                
+                updater.uninstall();
+                
+                assertEquals(Bundle.UNINSTALLED, updater.getState());
+                
+                try 
+                {
+                    updater.update();
+                    fail("Expected exception on update of uninstalled bundle");
+                }
+                catch (IllegalStateException expected) {
+                    
+                }
+            }
+            finally 
+            {
+                felix.stop();
+                felix.waitForStop(1000);
+            }
         } 
         finally
         {
-        	delete(cacheDir);
+            delete(cacheDir);
+        }
+    }
+    
+    public static final class ConcurrentBundleUpdaterActivator implements BundleActivator, Runnable 
+    {
+        Semaphore semaphore = new Semaphore(0);
+        
+        private BundleContext context;
+        
+        @Override
+        public void start(BundleContext context) throws Exception 
+        {
+            this.context = context;
+            if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
+            {
+                throw new BundleException("Timeout");
+            }
         }
-	}
-	
-	public static final class ConcurrentBundleUpdaterActivator implements BundleActivator, Runnable 
-	{
-		Semaphore semaphore = new Semaphore(0);
-		
-		private BundleContext context;
-		
-		@Override
-		public void start(BundleContext context) throws Exception 
-		{
-			this.context = context;
-			if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
-			{
-				throw new BundleException("Timeout");
-			}
-		}
 
-		@Override
-		public void stop(BundleContext context) throws Exception 
-		{
-			this.context = context;
-			if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
-			{
-				throw new BundleException("Timeout");
-			}
-		}
+        @Override
+        public void stop(BundleContext context) throws Exception 
+        {
+            this.context = context;
+            if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
+            {
+                throw new BundleException("Timeout");
+            }
+        }
 
-		@Override
-		public void run() 
-		{
-			semaphore.release();
-		}
-		
-	}
-	
-	public static final class ConcurrentBundleUpdaterCycleActivator implements BundleActivator, Runnable 
-	{
-		Semaphore semaphore = new Semaphore(0);
-		
-		private BundleContext context;
-		
-		@Override
-		public void start(BundleContext context) throws Exception 
-		{
-			this.context = context;
-			if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
-			{
-				throw new BundleException("Timeout");
-			}
-			context.getBundle().update();
-		}
+        @Override
+        public void run() 
+        {
+            semaphore.release();
+        }
+        
+    }
+    
+    public static final class ConcurrentBundleUpdaterCycleActivator implements BundleActivator, Runnable 
+    {
+        Semaphore semaphore = new Semaphore(0);
+        
+        private BundleContext context;
+        
+        @Override
+        public void start(BundleContext context) throws Exception 
+        {
+            this.context = context;
+            if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
+            {
+                throw new BundleException("Timeout");
+            }
+            context.getBundle().update();
+        }
 
-		@Override
-		public void stop(BundleContext context) throws Exception {
-			this.context = context;
-			if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
-			{
-				throw new BundleException("Timeout");
-			}
-		}
+        @Override
+        public void stop(BundleContext context) throws Exception {
+            this.context = context;
+            if (!semaphore.tryAcquire(1, TimeUnit.SECONDS))
+            {
+                throw new BundleException("Timeout");
+            }
+        }
 
-		@Override
-		public void run() 
-		{
-			semaphore.release();
-		}
-		
-	}
-	
-	private static File createBundle(String manifest, Class... classes) throws IOException
+        @Override
+        public void run() 
+        {
+            semaphore.release();
+        }
+        
+    }
+    
+    private static File createBundle(String manifest, Class... classes) throws IOException
     {
         File f = File.createTempFile("felix-bundle", ".jar");
         f.deleteOnExit();
@@ -397,14 +397,14 @@ public class ConcurrentBundleUpdateTest
         os.close();
         return f;
     }
-	
-	private static void delete(File file) throws IOException
+    
+    private static void delete(File file) throws IOException
     {
         if (file.isDirectory())
         {
             for (File child : file.listFiles())
             {
-            	delete(child);
+                delete(child);
             }
         }
         file.delete();