Fixed FELIX-3594 Service should be sorted by ID in service configuration printer
https://issues.apache.org/jira/browse/FELIX-3594

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1360540 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
index 60f43c7..be41582 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
@@ -20,6 +20,8 @@
 

 import java.io.PrintWriter;

 import java.text.MessageFormat;

+import java.util.Arrays;

+import java.util.Comparator;

 import java.util.Locale;

 

 import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;

@@ -28,6 +30,7 @@
 import org.osgi.framework.Constants;

 import org.osgi.framework.InvalidSyntaxException;

 import org.osgi.framework.ServiceReference;

+import org.osgi.service.packageadmin.ExportedPackage;

 

 /**

  * ServicesConfigurationPrinter provides a configuration printer for inspecting the 

@@ -136,7 +139,50 @@
         }

 

         // no services or invalid filter syntax (unlikely)

-        return refs != null ? refs : NO_REFS;

+        if (refs != null)

+        {

+            Arrays.sort(refs, new ServiceReferenceComparator());

+        }

+        else

+        {

+            refs = NO_REFS;

+        }

+        return refs;

     }

 

 }

+

+class ServiceReferenceComparator implements Comparator

+{

+    private static final Long ZERO = new Long(0);

+

+    public int compare(ServiceReference p1, ServiceReference p2)

+    {

+        Long id1 = null;

+        if (p1 != null)

+        {

+            id1 = (Long) p1.getProperty(Constants.SERVICE_ID);

+        }

+        if (id1 == null)

+        {

+            id1 = ZERO;

+        }

+

+        Long id2 = null;

+        if (p2 != null)

+        {

+            id2 = (Long) p2.getProperty(Constants.SERVICE_ID);

+        }

+        if (id2 == null)

+        {

+            id2 = ZERO;

+        }

+

+        return id1.compareTo(id2);

+    }

+

+    public int compare(Object o1, Object o2)

+    {

+        return compare((ServiceReference) o1, (ServiceReference) o2);

+    }

+}