incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r711237 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ main/java/org/apache/sling/jcr/jcrinstall/osgi/ main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ test/java/org/apache/sli...
Date Tue, 04 Nov 2008 12:17:39 GMT
Author: bdelacretaz
Date: Tue Nov  4 04:17:38 2008
New Revision: 711237

URL: http://svn.apache.org/viewvc?rev=711237&view=rev
Log:
SLING-719 - provide for non-file data via InstallableData

Added:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
  (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
  (with props)
Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileDataProvider.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiResourceProcessor.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileDataProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileDataProvider.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileDataProvider.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileDataProvider.java
Tue Nov  4 04:17:38 2008
@@ -23,11 +23,13 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
+
 /** Provides data (InputStream, last modified data) about
  * 	JCR nodes which are files.
  * 	TODO: Yes, this should be a generic JCR utility.
  */
-class FileDataProvider {
+class FileDataProvider implements InstallableData {
     /**
      * The relative path of the data and last modified date of an nt:file node
      */
@@ -37,13 +39,13 @@
     public static final String JCR_CONTENT_LAST_MODIFIED = JCR_CONTENT + "/" + JCR_LAST_MODIFIED;
     
     private final InputStream inputStream;
-    private final long lastModified;
+    private final String digest;
     
 	FileDataProvider(Node n) throws RepositoryException {
         if (n.hasProperty(JCR_CONTENT_LAST_MODIFIED)) {
-        	lastModified = n.getProperty(JCR_CONTENT_LAST_MODIFIED).getDate().getTimeInMillis();
+        	digest = String.valueOf(n.getProperty(JCR_CONTENT_LAST_MODIFIED).getDate().getTimeInMillis());
         } else {
-        	lastModified = -1;
+        	digest = null;
 	    }
 	    
         if(n.hasProperty(JCR_CONTENT_DATA)) {
@@ -54,14 +56,22 @@
 	}
 	
 	boolean isFile() {
-		return inputStream != null && lastModified != -1;
+		return inputStream != null && digest != null;
 	}
 
 	InputStream getInputStream() {
 		return inputStream;
 	}
 
-	long getLastModified() {
-		return lastModified;
+    @SuppressWarnings("unchecked")
+	public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+		if(type.equals(InputStream.class)) {
+			return (AdapterType)inputStream;
+		}
+		return null;
+	}
+
+	public String getDigest() {
+		return digest;
 	}
-}
+}
\ No newline at end of file

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
Tue Nov  4 04:17:38 2008
@@ -158,20 +158,10 @@
         	    }
         	} else {
         		// a single failure must not block the whole thing (SLING-655)
-        	    InputStream is = null;
         		try {
-        		    is = dp.getInputStream();
-        			installOrUpdate(n.getPath(), is, dp.getLastModified());
+        			installOrUpdate(n.getPath(), dp);
         		} catch(JcrInstallException jie) {
         			log.warn("Failed to install resource " + n.getPath(), jie);
-        		} finally {
-        		    if(is != null) {
-        		        try {
-        		            is.close();
-        		        } catch(IOException ioe) {
-        		            log.warn("IOException while closing stream of node " + n.getPath(),
ioe);
-        		        }
-        		    }
         		}
         	}
         }
@@ -196,14 +186,14 @@
     }
     
     /** Install or update the given resource, as needed */ 
-    protected void installOrUpdate(String path, InputStream data, Long lastModified) throws
IOException, JcrInstallException {
-    	final long currentLastModified = controller.getLastModified(path);
-    	if(currentLastModified == -1) {
+    protected void installOrUpdate(String path, FileDataProvider fdp) throws IOException,
JcrInstallException {
+    	final String digest = controller.getDigest(path);
+    	if(digest == null) {
     		log.info("Resource {} was not installed yet, installing in OsgiController", path);
-    		controller.installOrUpdate(path, lastModified, data);
-    	} else if(currentLastModified < lastModified) {
+    		controller.installOrUpdate(path, fdp);
+    	} else if(!digest.equals(fdp.getDigest())) {
     		log.info("Resource {} has been updated, updating in OsgiController", path);
-    		controller.installOrUpdate(path, lastModified, data);
+    		controller.installOrUpdate(path, fdp);
     	} else {
     		log.info("Resource {} not modified, ignoring", path);
     	}

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java?rev=711237&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
Tue Nov  4 04:17:38 2008
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.jcrinstall.osgi;
+
+/** A piece of data that can be installed by
+ * 	the OSGi controller.
+ */
+public interface InstallableData {
+	/** String that must change if the underlying data
+	 * 	changes. Stored by the OsgiController when installing
+	 * 	the data, meant to be used by the OsgiController client
+	 * 	when deciding if the data needs to be updated.
+	 */
+	String getDigest();
+	
+	/** Adapt the underlying data to the provided type.
+	 *	@return null if cannot be adapted */
+	<AdapterType> AdapterType adaptTo(Class<AdapterType> type);
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/InstallableData.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
Tue Nov  4 04:17:38 2008
@@ -19,7 +19,6 @@
 package org.apache.sling.jcr.jcrinstall.osgi;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Set;
 
 /** jcrinstall component that installs/updates/removes 
@@ -30,14 +29,12 @@
     
     /** Install or update supplied resource 
      *  @param uri Unique identifier for the resource
-     *  @param lastModified if the resource is installed, this is stored
-     *      and can be retrieved using getLastModified().
-     *  @param data resource contents
+     *  @param data The data to install
      *  @return one of the {@link InstallResultCode} result codes. 
      */
-    int installOrUpdate(String uri, long lastModified, InputStream data) throws IOException,
JcrInstallException;
+    int installOrUpdate(String uri, InstallableData data) throws IOException, JcrInstallException;
     
-    /** Uninstall the resource that was installed via given uri
+    /** Uninstall the data that was installed via given uri
      *  @param uri Unique identifier for the resource
      *  @param attributes metadata stored by the OsgiController, will be
      *      removed after calling this method
@@ -53,5 +50,5 @@
      *  to by that uri was installed.
      *  @return -1 if we don't have info for given uri
      */
-    long getLastModified(String uri);
+    String getDigest(String uri);
 }

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiResourceProcessor.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiResourceProcessor.java
Tue Nov  4 04:17:38 2008
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.jcr.jcrinstall.osgi;
 
-import java.io.InputStream;
 import java.util.Map;
 
 
@@ -34,10 +33,10 @@
      *  @param uri Unique identifier for the resource
      *  @param attributes metadata stored by the OsgiController, can be used to
      *      store additional information
-     *  @param data resource contents
+     *  @param data The data to install
      *  @return one of the {@link InstallResultCode} result codes. 
      */
-    int installOrUpdate(String uri, Map<String, Object> attributes, InputStream data)
throws Exception;
+    int installOrUpdate(String uri, Map<String, Object> attributes, InstallableData
data) throws Exception;
     
     /** Uninstall the resource that was installed via given uri
      *  @param uri Unique identifier for the resource

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessor.java
Tue Nov  4 04:17:38 2008
@@ -35,6 +35,7 @@
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -126,7 +127,13 @@
      *      java.util.Map, java.io.InputStream)
      */
     public int installOrUpdate(String uri, Map<String, Object> attributes,
-            InputStream data) throws BundleException, IOException {
+            InstallableData installableData) throws BundleException, IOException {
+    	
+    	InputStream data = installableData.adaptTo(InputStream.class);
+    	if(data == null) {
+    		throw new IOException("InstallableData does not adapt to an InputStream: " + uri);
+    	}
+    	
         // Update if we already have a bundle id, else install
         Bundle b = null;
         boolean updated = false;

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
Tue Nov  4 04:17:38 2008
@@ -26,6 +26,8 @@
 import java.util.Dictionary;
 import java.util.Map;
 
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
+import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -55,10 +57,22 @@
     }
 
     @SuppressWarnings("unchecked")
-    public int installOrUpdate(String uri, Map<String, Object> attributes, InputStream
data) throws Exception {
+    public int installOrUpdate(String uri, Map<String, Object> attributes, 
+    		InstallableData installableData) throws Exception {
         
-        // Load configuration properties
-        final Dictionary dict = reader.load(data);
+    	// Convert data to a configuration Dictionary
+    	Dictionary dict = installableData.adaptTo(Dictionary.class);
+    	if(dict == null) {
+	    	InputStream data = installableData.adaptTo(InputStream.class);
+	    	if(data == null) {
+	    		throw new IOException("InstallableData does not adapt to an InputStream: " + uri);
+	    	}
+	    	dict = reader.load(data);
+    	}
+    	
+    	if(dict == null) {
+    		throw new JcrInstallException("Null Dictionary for uri=" + uri);
+    	}
         
         // Get pids from node name
         final ConfigurationPid pid = new ConfigurationPid(uri);

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
Tue Nov  4 04:17:38 2008
@@ -27,6 +27,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
@@ -72,8 +73,8 @@
     /** @scr.reference */
     private PackageAdmin packageAdmin;
 
-    /** Storage key: last modified as a Long */
-    public static final String KEY_LAST_MODIFIED = "last.modified";
+    /** Storage key: digest of an InstallableData */
+    public static final String KEY_DIGEST = "data.digest";
 
     /** Default value for getLastModified() */
     public static final long LAST_MODIFIED_NOT_FOUND = -1;
@@ -113,7 +114,7 @@
         processors = null;
     }
     
-    public int installOrUpdate(String uri, long lastModified, InputStream data) throws IOException,
JcrInstallException {
+    public int installOrUpdate(String uri, InstallableData data) throws IOException, JcrInstallException
{
         int result = IGNORED;
         final OsgiResourceProcessor p = getProcessor(uri);
         if (p != null) {
@@ -121,7 +122,7 @@
                 final Map<String, Object> map = storage.getMap(uri);
                 result = p.installOrUpdate(uri, map, data);
                 if (result != IGNORED) {
-                    map.put(KEY_LAST_MODIFIED, new Long(lastModified));
+                    map.put(KEY_DIGEST, data.getDigest());
                 }
                 storage.saveToFile();
             } catch(IOException ioe) {
@@ -151,17 +152,14 @@
     }
 
     /** {@inheritDoc}
-     *  @return LAST_MODIFIED_NOT_FOUND if uri not found
+     *  @return null if uri not found
      */
-    public long getLastModified(String uri) {
-        long result = LAST_MODIFIED_NOT_FOUND;
+    public String getDigest(String uri) {
+        String result = null;
 
         if(storage.contains(uri)) {
             final Map<String, Object> uriData = storage.getMap(uri);
-            final Long lastMod = (Long)uriData.get(KEY_LAST_MODIFIED);
-            if(lastMod != null) {
-                result = lastMod.longValue();
-            }
+            result = (String)uriData.get(KEY_DIGEST);
         }
         return result;
     }

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java
Tue Nov  4 04:17:38 2008
@@ -25,6 +25,8 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.sling.jcr.jcrinstall.osgi.impl.MockInstallableData;
+
 class ContentHelper {
     public static final String NT_FOLDER = "nt:folder";
     public static final String NT_FILE = "nt:file";
@@ -84,6 +86,10 @@
         session.save();
     }
     
+    void createOrUpdateFile(String path, MockInstallableData d) throws RepositoryException
{
+    	createOrUpdateFile(path, d.adaptTo(InputStream.class), d.getLastModified());
+    }
+    
     void createOrUpdateFile(String path, InputStream data, long lastModified) throws RepositoryException
{
         final String relPath = path.substring(1);
         Node f = null;

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
Tue Nov  4 04:17:38 2008
@@ -31,13 +31,13 @@
 
 import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.apache.sling.jcr.jcrinstall.osgi.impl.MockInstallableData;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.Sequence;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.ComponentContext;
 
 /** Test that added/updated/removed resources are
  * 	correctly translated to OsgiController calls.
@@ -85,8 +85,8 @@
         
         final String dummyJar = "/libs/foo/bar/install/dummy.jar";
         final InputStream data = new ByteArrayInputStream(dummyJar.getBytes());
-        final long lastModifiedA = System.currentTimeMillis();
-        final long lastModifiedB = lastModifiedA + 1;
+        final MockInstallableData da = new MockInstallableData("a");
+        final MockInstallableData db = new MockInstallableData("b");
         final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
         
@@ -95,23 +95,23 @@
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
             
-            one(c).getLastModified("phase1"); 
+            one(c).getDigest("phase1"); 
             inSequence(sequence);
-            one(c).getLastModified(dummyJar); will(returnValue(-1L));
+            one(c).getDigest(dummyJar); will(returnValue(null));
             inSequence(sequence);
-            one(c).installOrUpdate(with(equal(dummyJar)), with(equal(lastModifiedA)), with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(dummyJar)), with(any(InstallableData.class)));
             inSequence(sequence);
             
-            one(c).getLastModified("phase2"); 
+            one(c).getDigest("phase2"); 
             inSequence(sequence);
-            one(c).getLastModified(dummyJar); will(returnValue(lastModifiedA));
+            one(c).getDigest(dummyJar); will(returnValue(da.getDigest()));
             inSequence(sequence);
             
-            one(c).getLastModified("phase3"); 
+            one(c).getDigest("phase3"); 
             inSequence(sequence);
-            one(c).getLastModified(dummyJar); will(returnValue(lastModifiedA));
+            one(c).getDigest(dummyJar); will(returnValue(da.getDigest()));
             inSequence(sequence);
-            one(c).installOrUpdate(with(equal(dummyJar)), with(equal(lastModifiedB)), with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(dummyJar)), with(any(InstallableData.class)));
             inSequence(sequence);
         }});
         
@@ -119,21 +119,21 @@
         ro.activate(null);
         
         // Add two files, run one cycle must install the bundles
-        c.getLastModified("phase1");
-        contentHelper.createOrUpdateFile(dummyJar, data, lastModifiedA);
+        c.getDigest("phase1");
+        contentHelper.createOrUpdateFile(dummyJar, da);
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
         installedUri.add(dummyJar);
         
         // Updating with the same timestamp must not call install again
-        c.getLastModified("phase2");
-        contentHelper.createOrUpdateFile(dummyJar, data, lastModifiedA);
+        c.getDigest("phase2");
+        contentHelper.createOrUpdateFile(dummyJar, da);
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
         
         // Updating with a new timestamp must call install again
-        c.getLastModified("phase3");
-        contentHelper.createOrUpdateFile(dummyJar, data, lastModifiedB);
+        c.getDigest("phase3");
+        contentHelper.createOrUpdateFile(dummyJar, db);
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
         
@@ -149,17 +149,17 @@
                 "/libs/foo/bar/install/dummy.dp"
         };
         final InputStream data = new ByteArrayInputStream("hello".getBytes());
-        final long lastModifiedA = System.currentTimeMillis();
+        final MockInstallableData da = new MockInstallableData("a");
         final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
         
         // Define the whole sequence of calls to OsgiController,
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

-            one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
+            one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[1])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[2])), with(any(InstallableData.class)));
         }});
         
         final RepositoryObserver ro = new MockRepositoryObserver(repo, c);
@@ -167,7 +167,7 @@
         
         // Add files, run one cycle must install the bundles
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
@@ -191,26 +191,26 @@
         };
         
         final InputStream data = new ByteArrayInputStream("hello".getBytes());
-        final long lastModifiedA = System.currentTimeMillis();
+        final MockInstallableData da = new MockInstallableData("a");
         final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
         
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

-            one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
+            one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[1])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[2])), with(any(InstallableData.class)));
         }});
         
         final RepositoryObserver ro = new MockRepositoryObserver(repo, c);
         ro.activate(null);
         
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         for(String file : ignored) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         eventHelper.waitForEvents(5000L);
         
@@ -231,7 +231,7 @@
         
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
             one(c).uninstall("/libs/foo/bar/install/dummy.jar");
             one(c).uninstall("/libs/foo/bar/install/dummy.cfg");
             one(c).uninstall("/libs/watchfolder-is-gone/install/gone.cfg");
@@ -255,7 +255,7 @@
         
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
             one(c).uninstall("/libs/foo/bar/install/dummy.cfg");
             inSequence(sequence);
             one(c).uninstall("/libs/foo/bar/install/dummy.dp");
@@ -281,18 +281,18 @@
                 "/libs/foo/bar/install/dummy.dp"
         };
         final InputStream data = new ByteArrayInputStream("hello".getBytes());
-        final long lastModifiedA = System.currentTimeMillis();
+        final MockInstallableData da = new MockInstallableData("a");
         final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
         
         // Define the whole sequence of calls to OsgiController,
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

-            one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
+            one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[1])), with(any(InstallableData.class)));
             will(throwException(new JcrInstallException("Fake BundleException for testing")));
-            one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(resources[2])), with(any(InstallableData.class)));
         }});
         
         final RepositoryObserver ro = new MockRepositoryObserver(repo, c);
@@ -300,7 +300,7 @@
         
         // Add files, run one cycle must install the bundles
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
@@ -321,11 +321,10 @@
                 "/libs/foo/wii/install/more.cfg",
         };
         
-        final InputStream data = new ByteArrayInputStream("hello".getBytes());
-        final long lastModifiedA = System.currentTimeMillis();
+        final MockInstallableData da = new MockInstallableData("a");
 
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         
         final Set<String> installedUri = new HashSet<String>();
@@ -335,9 +334,9 @@
         // Test with first regexp
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

-            one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
+            one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[2])), with(any(InstallableData.class)));
         }});
         
         final MockRepositoryObserver ro = new MockRepositoryObserver(repo, c, serviceDataFile);
@@ -346,7 +345,7 @@
         ro.activate(null);
         ro.handleInitialUninstalls();
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
@@ -357,18 +356,18 @@
         // Test with a different regexp, install.A resources must be uninstalled
         mockery.checking(new Expectations() {{
             allowing(c).getInstalledUris(); will(returnValue(installedUri));
-            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

+            allowing(c).getDigest(with(any(String.class))); will(returnValue(null)); 
             one(c).uninstall(resources[0]);
             one(c).uninstall(resources[2]);
-            one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
-            one(c).installOrUpdate(with(equal(resources[3])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(resources[1])), with(any(InstallableData.class)));
+            one(c).installOrUpdate(with(equal(resources[3])), with(any(InstallableData.class)));
         }});
         
         props.setProperty(RepositoryObserver.FOLDER_NAME_REGEXP_PROPERTY, ".*foo/wii/install$");
         ro.activate(null);
         ro.handleInitialUninstalls();
         for(String file : resources) {
-            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+            contentHelper.createOrUpdateFile(file, da);
         }
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java?rev=711237&r1=711236&r2=711237&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
Tue Nov  4 04:17:38 2008
@@ -25,13 +25,11 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
 
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.Sequence;
@@ -75,8 +73,8 @@
         final Bundle b = mockery.mock(Bundle.class);
         final long bundleId = 1234;
         final String uri = "/test/bundle.jar";
-        final InputStream data = new ByteArrayInputStream(uri.getBytes());
-        long lastModified = System.currentTimeMillis();
+        final MockInstallableData data = new MockInstallableData(uri);
+        final InputStream is = data.adaptTo(InputStream.class);
 
         // We'll try installing a bundle, re-installing to cause
         // it to be updated, and removing
@@ -87,7 +85,7 @@
             will(returnValue(bundleId));
             allowing(bc).addFrameworkListener(with(any(FrameworkListener.class)));
 
-            one(bc).installBundle(OsgiControllerImpl.getResourceLocation(uri), data);
+            one(bc).installBundle(OsgiControllerImpl.getResourceLocation(uri), is);
             inSequence(sequence);
             will(returnValue(b));
 
@@ -98,7 +96,7 @@
             one(b).stop();
             inSequence(sequence);
             
-            one(b).update(data);
+            one(b).update(is);
             inSequence(sequence);
 
             one(b).uninstall();
@@ -110,25 +108,25 @@
         Utilities.setProcessors(c, p);
         assertFalse("Before install, uri must not be in list", c.getInstalledUris().contains(uri));
 
-        assertEquals("First install returns INSTALLED", INSTALLED, c.installOrUpdate(uri,
lastModified, data));
+        assertEquals("First install returns INSTALLED", INSTALLED, c.installOrUpdate(uri,
data));
         assertTrue("After install, uri must be in list", c.getInstalledUris().contains(uri));
-        assertEquals("LastModified must have been stored", lastModified, c.getLastModified(uri));
+        assertEquals("Digest must have been stored", data.getDigest(), c.getDigest(uri));
         assertEquals("Storage data has been saved during install", 1, s.saveCounter);
 
-        lastModified = System.currentTimeMillis();
-        assertEquals("Second install returns UPDATED", UPDATED, c.installOrUpdate(uri, lastModified,
data));
+        data.setDigest("digest is now different");
+        assertEquals("Second install returns UPDATED", UPDATED, c.installOrUpdate(uri, data));
         assertTrue("After update, uri must be in list", c.getInstalledUris().contains(uri));
-        assertEquals("LastModified must have been updated", lastModified, c.getLastModified(uri));
+        assertEquals("Digest must have been updated", data.getDigest(), c.getDigest(uri));
         assertEquals("Storage data has been saved during update", 2, s.saveCounter);
 
         c.uninstall(uri);
         assertFalse("After uninstall, uri must not be in list", c.getInstalledUris().contains(uri));
-        assertEquals("LastModified must be gone", -1, c.getLastModified(uri));
+        assertEquals("Digest must be gone", null, c.getDigest(uri));
         assertFalse("After getLastModified, uri must not be in list", c.getInstalledUris().contains(uri));
         assertEquals("Storage data has been saved during uninstall", 3, s.saveCounter);
 
         final String nonJarUri = "no_jar_extension";
-        assertEquals(nonJarUri + " must be ignored", c.installOrUpdate("", lastModified,
data), IGNORED);
+        assertEquals(nonJarUri + " must be ignored", c.installOrUpdate("", data), IGNORED);
 
         // And verify expectations
         mockery.assertIsSatisfied();

Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java?rev=711237&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
Tue Nov  4 04:17:38 2008
@@ -0,0 +1,55 @@
+package org.apache.sling.jcr.jcrinstall.osgi.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
+
+public class MockInstallableData implements InstallableData {
+
+	private final InputStream inputStream;
+	private long lastModified;
+	private String digest;
+	private static int counter;
+	
+	public MockInstallableData(String uri) {
+        inputStream = new ByteArrayInputStream(uri.getBytes());
+        lastModified = System.currentTimeMillis() + counter;
+        counter++;
+        digest = String.valueOf(lastModified);
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		if(obj instanceof MockInstallableData) {
+			final MockInstallableData other = (MockInstallableData)obj;
+			return digest.equals(other.digest);
+		}
+		return false;
+	}
+	
+	public long getLastModified() {
+		return lastModified;
+	}
+
+	@Override
+	public int hashCode() {
+		return digest.hashCode();
+	}
+
+	@SuppressWarnings("unchecked")
+	public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+		if(type.equals(InputStream.class)) {
+			return (AdapterType)inputStream;
+		}
+		return null;
+	}
+
+	void setDigest(String d) {
+		digest = d;
+	}
+	
+	public String getDigest() {
+		return digest;
+	}
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/MockInstallableData.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message