incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r955872 - in /sling/trunk/installer: jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ osgi/in...
Date Fri, 18 Jun 2010 07:37:16 GMT
Author: cziegeler
Date: Fri Jun 18 07:37:15 2010
New Revision: 955872

URL: http://svn.apache.org/viewvc?rev=955872&view=rev
Log:
SLING-1560 : Improve and clean up code
Make DigestUtil private

Added:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
  (contents, props changed)
      - copied, changed from r955699, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/DigestUtil.java
Removed:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/DigestUtil.java
Modified:
    sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/InstallableResourceImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java

Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java?rev=955872&r1=955871&r2=955872&view=diff
==============================================================================
--- sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
(original)
+++ sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
Fri Jun 18 07:37:15 2010
@@ -19,12 +19,16 @@
 package org.apache.sling.jcr.jcrinstall.impl;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.security.NoSuchAlgorithmException;
+import java.io.ObjectOutputStream;
+import java.math.BigInteger;
+import java.security.MessageDigest;
 import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
-import org.apache.sling.osgi.installer.DigestUtil;
 import org.apache.sling.osgi.installer.InstallableResource;
 import org.apache.sling.osgi.installer.InstallableResourceFactory;
 
@@ -85,13 +89,7 @@ public class MockInstallableResource imp
         if ( digest != null ) {
             this.digest = digest;
         } else {
-            try {
-                this.digest = DigestUtil.computeDigest(d);
-            } catch (NoSuchAlgorithmException e) {
-                throw new RuntimeException(e);
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
+            this.digest = computeDigest(d);
         }
         this.d = d;
     }
@@ -128,4 +126,40 @@ public class MockInstallableResource imp
     public String getUrl() {
         return this.uri;
     }
+
+    /** The digest to be used. */
+    private static final String DIGEST_TYPE = "MD5";
+
+    /** convert digest to readable string (http://www.javalobby.org/java/forums/t84420.html)
*/
+    private static String digestToString(MessageDigest d) {
+        final BigInteger bigInt = new BigInteger(1, d.digest());
+        return new String(bigInt.toString(16));
+    }
+
+    /** Compute digest on all keys of supplied data */
+    private static String computeDigest(Dictionary<String, Object> data) {
+        try {
+            final MessageDigest d = MessageDigest.getInstance(DIGEST_TYPE);
+            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            final ObjectOutputStream oos = new ObjectOutputStream(bos);
+
+            final SortedSet<String> sortedKeys = new TreeSet<String>();
+            if(data != null) {
+                for(Enumeration<String> e = data.keys(); e.hasMoreElements(); ) {
+                    final String key = e.nextElement();
+                    sortedKeys.add(key);
+                }
+            }
+            for(String key : sortedKeys) {
+                oos.writeObject(key);
+                oos.writeObject(data.get(key));
+            }
+
+            bos.flush();
+            d.update(bos.toByteArray());
+            return digestToString(d);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=955872&r1=955871&r2=955872&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Fri Jun 18 07:37:15 2010
@@ -43,15 +43,29 @@ public interface InstallableResource {
 	 */
     String getUrl();
 
-	/** Return the type of this resource. */
+	/**
+	 * Return the type of this resource.
+	 * @return The resource type.
+	 */
     Type getType();
 
-	/** Return an input stream with the data of this resource. Null if resource
-	 *  contains a dictionary instead. Caller is responsible for closing the stream.
+	/**
+	 * Return an input stream with the data of this resource.
+	 * Null if resource contains a dictionary instead. Caller is responsible for
+	 * closing the stream.
+	 * If this resource is of type CONFIG it must not return an input stream and
+	 * if this resource is of type BUNDLE it must return an input stream!
+	 * @return The input stream or null.
 	 */
     InputStream getInputStream();
 
-	/** Return this resource's dictionary. Null if resource contains an InputStream instead
*/
+	/**
+	 * Return this resource's dictionary.
+	 * Null if resource contains an InputStream instead. If this resource is of
+	 * type CONFIG it must return a dictionary and if this resource is of type BUNDLE
+	 * it must not return a dictionary!
+	 * @return The resource's dictionary or null.
+	 */
 	Dictionary<String, Object> getDictionary();
 
 	/** Return this resource's digest. Not necessarily an actual md5 or other digest of the

Copied: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
(from r955699, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/DigestUtil.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java?p2=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java&p1=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/DigestUtil.java&r1=955699&r2=955872&rev=955872&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/DigestUtil.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
Fri Jun 18 07:37:15 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.osgi.installer;
+package org.apache.sling.osgi.installer.impl;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DigestUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/InstallableResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/InstallableResourceImpl.java?rev=955872&r1=955871&r2=955872&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/InstallableResourceImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/InstallableResourceImpl.java
Fri Jun 18 07:37:15 2010
@@ -21,7 +21,6 @@ package org.apache.sling.osgi.installer.
 import java.io.InputStream;
 import java.util.Dictionary;
 
-import org.apache.sling.osgi.installer.DigestUtil;
 import org.apache.sling.osgi.installer.InstallableResource;
 import org.apache.sling.osgi.installer.OsgiInstaller;
 

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java?rev=955872&r1=955871&r2=955872&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
Fri Jun 18 07:37:15 2010
@@ -24,7 +24,7 @@ import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.sling.osgi.installer.DigestUtil;
+import org.apache.sling.osgi.installer.impl.DigestUtil;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.service.cm.Configuration;

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java?rev=955872&r1=955871&r2=955872&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
Fri Jun 18 07:37:15 2010
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertTru
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.sling.osgi.installer.DigestUtil;
 
 public class DictionaryDigestTest {
 	private void setTestData(Hashtable<String, Object> d) {



Mime
View raw message