incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1229921 - in /sling/trunk/installer/core/src: main/java/org/apache/sling/installer/core/impl/ main/java/org/apache/sling/installer/core/impl/console/ test/java/org/apache/sling/installer/core/impl/
Date Wed, 11 Jan 2012 07:58:56 GMT
Author: cziegeler
Date: Wed Jan 11 07:58:56 2012
New Revision: 1229921

URL: http://svn.apache.org/viewvc?rev=1229921&view=rev
Log:
SLING-2356 : Correctly sort resources

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleContext.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1229921&r1=1229920&r2=1229921&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
Wed Jan 11 07:58:56 2012
@@ -421,15 +421,17 @@ public class RegisteredResourceImpl
     public static int compare(final TaskResource a, final TaskResource b) {
         // check entity id first
         int result = a.getEntityId().compareTo(b.getEntityId());
+        boolean hasVersion = false;
         if ( result == 0 ) {
             // compare versions
-            boolean isSnapshot = true;
+            boolean isSnapshot = false;
 
             // Order by version
             final Version va = a.getVersion();
             final Version vb = b.getVersion();
 
             if ( va != null && vb != null ) {
+                hasVersion = true;
                 isSnapshot = va.toString().contains("SNAPSHOT");
                 // higher version has more priority, must come first so invert comparison
                 result = vb.compareTo(va);
@@ -446,13 +448,24 @@ public class RegisteredResourceImpl
             }
         }
 
-        if ( result == 0 ) {
+        if ( result == 0 && a.getState() != b.getState() ) {
             if ( a.getState() == ResourceState.INSTALLED ) {
                 return -1;
             } else if ( b.getState() == ResourceState.INSTALLED ) {
                 return 1;
+            } else if ( a.getState() == ResourceState.INSTALL ) {
+                return -1;
+            } else if ( b.getState() == ResourceState.INSTALL ) {
+                return 1;
             }
+        }
+        if ( result == 0 ) {
+            // finally use url and then digest
             result = a.getURL().compareTo(b.getURL());
+            if ( result == 0 && !hasVersion ) {
+                // higher digest has more priority, must come first so invert comparison
+                result = b.getDigest().compareTo(a.getDigest());
+            }
         }
         return result;
     }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1229921&r1=1229920&r2=1229921&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
Wed Jan 11 07:58:56 2012
@@ -143,6 +143,10 @@ public class OsgiInstallerWebConsolePlug
         return rsrc.getURL();
     }
 
+    private String getInfo(final RegisteredResource rsrc) {
+        return rsrc.getDigest() + '/' + String.valueOf(rsrc.getPriority());
+    }
+
     /** Default date format used. */
     private final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSS yyyy-MMM-dd");
 
@@ -178,12 +182,12 @@ public class OsgiInstallerWebConsolePlug
                     pw.printf("<span style='float: left; margin-left: 1em;'>Active
Resources - %s</span>", getType(toActivate));
                     pw.println("</div>");
                     pw.println("<table class='nicetable'><tbody>");
-                    pw.printf("<tr><th>Entity ID</th><th>Digest</th><th>URL
(Version)</th><th>State</th></tr>");
+                    pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL
(Version)</th><th>State</th></tr>");
                     rt = toActivate.getType();
                 }
                 pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
                         getEntityId(toActivate, group.getAlias()),
-                        toActivate.getDigest(),
+                        getInfo(toActivate),
                         getURL(toActivate),
                         toActivate.getState());
             }
@@ -205,13 +209,13 @@ public class OsgiInstallerWebConsolePlug
                         pw.printf("<span style='float: left; margin-left: 1em;'>Processed
Resources - %s</span>", getType(first));
                         pw.println("</div>");
                         pw.println("<table class='nicetable'><tbody>");
-                        pw.printf("<tr><th>Entity ID</th><th>Digest</th><th>URL
(Version)</th><th>State</th></tr>");
+                        pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL
(Version)</th><th>State</th></tr>");
                         rt = first.getType();
                     }
                     pw.print("<tr><td>");
                     pw.print(getEntityId(first, group.getAlias()));
                     pw.print("</td><td>");
-                    pw.print(first.getDigest());
+                    pw.print(getInfo(first));
                     pw.print("</td><td>");
                     pw.print(getURL(first));
                     pw.print("</td><td>");
@@ -228,7 +232,7 @@ public class OsgiInstallerWebConsolePlug
                     while ( iter.hasNext() ) {
                         final TaskResource resource = iter.next();
                         pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>",
-                            resource.getDigest(),
+                            getInfo(resource),
                             getURL(resource),
                             resource.getState());
                     }
@@ -248,12 +252,12 @@ public class OsgiInstallerWebConsolePlug
                     pw.printf("<span style='float: left; margin-left: 1em;'>Untransformed
Resources - %s</span>", getType(registeredResource));
                     pw.println("</div>");
                     pw.println("<table class='nicetable'><tbody>");
-                    pw.printf("<tr><th>Digest</th><th>URL</th></tr>");
+                    pw.printf("<tr><th>Digest/Priority</th><th>URL</th></tr>");
 
                     rt = registeredResource.getType();
                 }
                 pw.printf("<tr><td>%s</td><td>%s</td></tr>",
-                    registeredResource.getDigest(),
+                    getInfo(registeredResource),
                     registeredResource.getURL());
             }
             if ( rt != null ) {
@@ -284,7 +288,7 @@ public class OsgiInstallerWebConsolePlug
                 }
                 pw.printf("- %s: %s, %s, %s%n",
                         getEntityId(toActivate, group.getAlias()),
-                        toActivate.getDigest(),
+                        getInfo(toActivate),
                         getURL(toActivate),
                         toActivate.getState());
             }
@@ -304,13 +308,13 @@ public class OsgiInstallerWebConsolePlug
                     }
                     pw.printf("* %s: %s, %s, %s%n",
                             getEntityId(first, group.getAlias()),
-                            first.getDigest(),
+                            getInfo(first),
                             getURL(first),
                             first.getState());
                     while ( iter.hasNext() ) {
                         final TaskResource resource = iter.next();
                         pw.printf("  - %s, %s, %s%n",
-                            resource.getDigest(),
+                            getInfo(resource),
                             getURL(resource),
                             resource.getState());
                     }
@@ -327,7 +331,7 @@ public class OsgiInstallerWebConsolePlug
                     rt = registeredResource.getType();
                 }
                 pw.printf("- %s, %s%n",
-                        registeredResource.getDigest(),
+                        getInfo(registeredResource),
                         registeredResource.getURL());
             }
         }

Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleContext.java?rev=1229921&r1=1229920&r2=1229921&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleContext.java
(original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/MockBundleContext.java
Wed Jan 11 07:58:56 2012
@@ -173,6 +173,7 @@ public class MockBundleContext implement
 
             }
 
+            @SuppressWarnings("rawtypes")
             public Dictionary getHeaders() {
                 // TODO Auto-generated method stub
                 return null;
@@ -208,6 +209,7 @@ public class MockBundleContext implement
                 return null;
             }
 
+            @SuppressWarnings("rawtypes")
             public Dictionary getHeaders(String locale) {
                 // TODO Auto-generated method stub
                 return null;
@@ -217,16 +219,19 @@ public class MockBundleContext implement
                 return "test-bundle";
             }
 
+            @SuppressWarnings("rawtypes")
             public Class loadClass(String name) throws ClassNotFoundException {
                 // TODO Auto-generated method stub
                 return null;
             }
 
+            @SuppressWarnings("rawtypes")
             public Enumeration getResources(String name) throws IOException {
                 // TODO Auto-generated method stub
                 return null;
             }
 
+            @SuppressWarnings("rawtypes")
             public Enumeration getEntryPaths(String path) {
                 // TODO Auto-generated method stub
                 return null;
@@ -242,6 +247,7 @@ public class MockBundleContext implement
                 return 0;
             }
 
+            @SuppressWarnings("rawtypes")
             public Enumeration findEntries(String path, String filePattern,
                     boolean recurse) {
                 // TODO Auto-generated method stub
@@ -253,6 +259,7 @@ public class MockBundleContext implement
                 return null;
             }
 
+            @SuppressWarnings("rawtypes")
             public Map getSignerCertificates(int signersType) {
                 // TODO Auto-generated method stub
                 return null;

Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java?rev=1229921&r1=1229920&r2=1229921&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java
(original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java
Wed Jan 11 07:58:56 2012
@@ -31,17 +31,18 @@ import java.util.TreeSet;
 
 import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.tasks.RegisteredResource;
+import org.apache.sling.installer.api.tasks.ResourceState;
 import org.apache.sling.installer.api.tasks.TransformationResult;
 import org.junit.Test;
 
 public class RegisteredResourceComparatorTest {
 
-    private void assertOrder(Set<RegisteredResource> toTest, RegisteredResource[] inOrder)
{
+    private void assertOrder(final Set<RegisteredResource> toTest, final RegisteredResource[]
inOrder) {
         assertEquals("Expected sizes to match", toTest.size(), inOrder.length);
         int i = 0;
-        for(RegisteredResource r : toTest) {
+        for(final RegisteredResource r : toTest) {
             final RegisteredResource ref = inOrder[i];
-            assertSame("At index " + i + ", expected toTest and ref to match", ref, r);
+            assertSame("At index " + i + ", expected toTest and ref to match.", ref, r);
             i++;
         }
     }
@@ -51,7 +52,11 @@ public class RegisteredResourceComparato
     }
 
     private RegisteredResourceImpl getConfig(String url, Dictionary<String, Object>
data, int priority, String digest) throws IOException {
-        if(data == null) {
+        return getConfig(url, data, priority, digest, null);
+    }
+
+    private RegisteredResourceImpl getConfig(String url, Dictionary<String, Object>
data, int priority, String digest, ResourceState state) throws IOException {
+        if (data == null) {
             data = new Hashtable<String, Object>();
             data.put("foo", "bar");
         }
@@ -68,7 +73,11 @@ public class RegisteredResourceComparato
                       result
             };
         }
-        return (RegisteredResourceImpl)rr.clone(tr[0]);
+        final RegisteredResourceImpl result = (RegisteredResourceImpl)rr.clone(tr[0]);
+        if ( state != null ) {
+            result.setState(state);
+        }
+        return result;
     }
 
     private void assertOrder(RegisteredResource[] inOrder) {
@@ -192,4 +201,12 @@ public class RegisteredResourceComparato
         inOrder[3] = getConfig("pidB", null, 0);
         assertOrder(inOrder);
     }
+
+    @Test
+    public void testConfigState() throws IOException {
+        final RegisteredResource [] inOrder = new RegisteredResource [2];
+        inOrder[0] = getConfig("pidA", null, 100, "a", ResourceState.INSTALLED);
+        inOrder[1] = getConfig("pidA", null, 100, "b", ResourceState.INSTALL);
+        assertOrder(inOrder);
+    }
 }
\ No newline at end of file



Mime
View raw message