FELIX-1666 add helper method for deciding whether a bundle is considered
active or not. Currently we allow ACTIVE and STARTING states. For the
STARTING state though, we should actually be checking whether the
bundle is really a lazily activated one or not ...

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@824884 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 5f60315..e9e7630 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -194,7 +194,7 @@
         for ( int i = 0; i < bundles.length; i++ )
         {
             Bundle bundle = bundles[i];
-            if ( bundle.getState() == Bundle.ACTIVE )
+            if ( ComponentRegistry.isBundleActive( bundle ) )
             {
                 loadComponents( bundle );
             }
@@ -225,7 +225,7 @@
         if ( m_componentBundles.containsKey( new Long( bundle.getBundleId() ) ) )
         {
             log( LogService.LOG_DEBUG, m_context.getBundle(), "Components for bundle  " + bundle.getSymbolicName()
-                + "/" + bundle.getBundleId() + " already loaded. Nothing to do", null );
+                + "/" + bundle.getBundleId() + " already loaded. Nothing to do.", null );
             return;
         }
 
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentActivatorTask.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentActivatorTask.java
index 9cce9ec..bb341bc 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentActivatorTask.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentActivatorTask.java
@@ -21,7 +21,6 @@
 
 import org.apache.felix.scr.Component;
 import org.apache.felix.scr.impl.manager.AbstractComponentManager;
-import org.osgi.framework.Bundle;
 import org.osgi.service.log.LogService;
 
 
@@ -58,7 +57,7 @@
             Activator.log( LogService.LOG_WARNING, null, "Cannot run task '" + this
                 + "': Component has already been destroyed", null );
         }
-        else if ( component.getBundle().getState() != Bundle.ACTIVE )
+        else if ( !ComponentRegistry.isBundleActive( component.getBundle() ) )
         {
             Activator.log( LogService.LOG_WARNING, component.getBundle(), "Cannot run task '" + this
                 + "': Declaring bundle is not active", null );
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
index 31771c6..8a84071 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
@@ -324,4 +324,24 @@
         return new UnconfiguredComponentHolder( activator, metadata );
     }
 
+
+    //---------- Helper method
+
+    static boolean isBundleActive( Bundle bundle )
+    {
+        if ( bundle.getState() == Bundle.ACTIVE )
+        {
+            return true;
+        }
+
+        if ( bundle.getState() == Bundle.STARTING )
+        {
+            // might want to check lazy start setting
+
+            return true;
+        }
+
+        // fall back: bundle is not considered active
+        return false;
+    }
 }
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
index 6401852..028843c 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
@@ -136,7 +136,7 @@
                     err.println( "Missing bundle with ID " + bundleId );
                     return;
                 }
-                if ( bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STARTING )
+                if ( ComponentRegistry.isBundleActive( bundle ) )
                 {
                     components = scrService.getComponents( bundle );
                     if ( components == null )