FELIX-2946 Implemented an option to have the tracker track all aspects. Bumped bundle and tracker package versions to 3.1.0.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1101390 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/pom.xml b/dependencymanager/core/pom.xml
index ebbf9f7..1705d37 100644
--- a/dependencymanager/core/pom.xml
+++ b/dependencymanager/core/pom.xml
@@ -30,7 +30,7 @@
     </properties>
     <name>Apache Felix Dependency Manager</name>
     <artifactId>org.apache.felix.dependencymanager</artifactId>
-    <version>3.0.1-SNAPSHOT</version>
+    <version>3.1.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
     <dependencies>
         <dependency>
@@ -85,7 +85,7 @@
                         <Bundle-Name>Apache Felix Dependency Manager</Bundle-Name>
                         <Bundle-Description>Provides dynamic service and component dependency management.</Bundle-Description>
                         <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
-                        <Export-Package>org.apache.felix.dm;version="3.0.0";provide:=true,org.apache.felix.dm.tracker;version="3.0.0";provide:=true</Export-Package>
+                        <Export-Package>org.apache.felix.dm;version="3.0.0";provide:=true,org.apache.felix.dm.tracker;version="3.1.0";provide:=true</Export-Package>
                         <Import-Package>*</Import-Package>
                         <Private-Package>org.apache.felix.dm.impl, org.apache.felix.dm.impl.*</Private-Package>
                         <!-- Uncomment this next line to include source code in the bundle.
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
index c51f8f8..25a1cad 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/tracker/ServiceTracker.java
@@ -133,6 +133,12 @@
 	private static final Version		endMatchVersion	= new Version(1, 5, 0);
 
 	/**
+	 * Flag that gets set when opening the tracker, determines if the tracker should
+	 * track all aspects or just the highest ranked ones.
+	 */
+    public boolean m_trackAllAspects;
+
+	/**
 	 * Create a <code>ServiceTracker</code> on the specified
 	 * <code>ServiceReference</code>.
 	 * 
@@ -300,7 +306,35 @@
 	 *         longer valid.
 	 * @since 1.3
 	 */
-	public void open(boolean trackAllServices) {
+    public void open(boolean trackAllServices) {
+        open(trackAllServices, false);
+    }
+	
+    /**
+     * Open this <code>ServiceTracker</code> and begin tracking services.
+     * 
+     * <p>
+     * Services which match the search criteria specified when this
+     * <code>ServiceTracker</code> was created are now tracked by this
+     * <code>ServiceTracker</code>.
+     * 
+     * @param trackAllServices If <code>true</code>, then this
+     *        <code>ServiceTracker</code> will track all matching services
+     *        regardless of class loader accessibility. If <code>false</code>,
+     *        then this <code>ServiceTracker</code> will only track matching
+     *        services which are class loader accessible to the bundle whose
+     *        <code>BundleContext</code> is used by this
+     *        <code>ServiceTracker</code>.
+     * @param trackAllAspects If <code>true</code> then this
+     *        <code>ServiceTracker</code> will track all aspects regardless
+     *        of their rank. If <code>false</code> only the highest ranked
+     *        aspects (or the original service if there are no aspects) will
+     *        be tracked. The latter is the default.
+     * @throws java.lang.IllegalStateException If the <code>BundleContext</code>
+     *         with which this <code>ServiceTracker</code> was created is no
+     *         longer valid.
+     */
+	public void open(boolean trackAllServices, boolean trackAllAspects) {
 		final Tracked t;
 		synchronized (this) {
 			if (tracked != null) {
@@ -309,6 +343,7 @@
 			if (DEBUG) {
 				System.out.println("ServiceTracker.open: " + filter); 
 			}
+			m_trackAllAspects = trackAllAspects;
 			t = trackAllServices ? new AllTracked() : new Tracked();
 			synchronized (t) {
 				try {
@@ -1051,6 +1086,69 @@
 		 * @param event <code>ServiceEvent</code> object from the framework.
 		 */
 		public void serviceChanged(final ServiceEvent event) {
+		    if (m_trackAllAspects) {
+		        serviceChangedIncludeAspects(event);
+		    }
+		    else {
+		        serviceChangedHideAspects(event);
+		    }
+		}
+		
+        public void serviceChangedIncludeAspects(final ServiceEvent event) {
+            /*
+             * Check if we had a delayed call (which could happen when we
+             * close).
+             */
+            if (closed) {
+                return;
+            }
+            final ServiceReference reference = event.getServiceReference();
+            if (DEBUG) {
+                System.out
+                        .println("ServiceTracker.Tracked.serviceChanged["
+                        + event.getType() + "]: " + reference);  
+            }
+
+            switch (event.getType()) {
+                case ServiceEvent.REGISTERED :
+                case ServiceEvent.MODIFIED :
+                    if (listenerFilter != null) { // service listener added with
+                        // filter
+                        track(reference, event);
+                        /*
+                         * If the customizer throws an unchecked exception, it
+                         * is safe to let it propagate
+                         */
+                    }
+                    else { // service listener added without filter
+                        if (filter.match(reference)) {
+                            track(reference, event);
+                            /*
+                             * If the customizer throws an unchecked exception,
+                             * it is safe to let it propagate
+                             */
+                        }
+                        else {
+                            untrack(reference, event);
+                            /*
+                             * If the customizer throws an unchecked exception,
+                             * it is safe to let it propagate
+                             */
+                        }
+                    }
+                    break;
+                case 8 /* ServiceEvent.MODIFIED_ENDMATCH */ :
+                case ServiceEvent.UNREGISTERING :
+                    untrack(reference, event);
+                    /*
+                     * If the customizer throws an unchecked exception, it is
+                     * safe to let it propagate
+                     */
+                    break;
+            }
+        }
+		
+		public void serviceChangedHideAspects(final ServiceEvent event) {
 			/*
 			 * Check if we had a delayed call (which could happen when we
 			 * close).
diff --git a/dependencymanager/test/pom.xml b/dependencymanager/test/pom.xml
index a10e887..4d473e7 100644
--- a/dependencymanager/test/pom.xml
+++ b/dependencymanager/test/pom.xml
@@ -33,7 +33,7 @@
         <dependency>
             <groupId>${pom.groupId}</groupId>
             <artifactId>org.apache.felix.dependencymanager</artifactId>
-            <version>3.0.1-SNAPSHOT</version>
+            <version>3.1.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>