Author: bdelacretaz
Date: Wed Aug 26 13:04:25 2009
New Revision: 807989

URL: http://svn.apache.org/viewvc?rev=807989&view=rev
Log:
SLING-1078 - use empty InstallableResource for resource removal (as data is not 
available anymore ;-)

Modified:
    
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java
    
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.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/OsgiInstaller.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigPrioritiesTest.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java

Modified: 
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java
 (original)
+++ 
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java
 Wed Aug 26 13:04:25 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.jcr.jcrinstall.impl;
 
-import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -153,9 +152,8 @@
         
         // Resources left in the digests map have been deleted since last 
scan, 
         // need to be removed from OsgiInstaller
-        final ByteArrayInputStream emptyStream = new 
ByteArrayInputStream("".getBytes());
         for(Map.Entry<String, String> e : digests.entrySet()) {
-            InstallableResource r = new InstallableResource(e.getKey(), 
emptyStream, e.getValue());
+            InstallableResource r = new InstallableResource(e.getKey());
             result.toRemove.add(r);
         }
         

Modified: 
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
 (original)
+++ 
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
 Wed Aug 26 13:04:25 2009
@@ -68,6 +68,9 @@
     }
 
     public void removeResource(InstallableResource d) throws IOException {
+       if(!d.isEmpty()) {
+               throw new IllegalArgumentException("InstallableResource must be 
empty for removeResource call");
+       }
        urls.remove(d.getUrl());
         recordCall("remove", d);
     }

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=807989&r1=807988&r2=807989&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
 Wed Aug 26 13:04:25 2009
@@ -38,6 +38,7 @@
        private final InputStream inputStream;
        private final Dictionary<String, Object> dictionary;
        private int priority;
+       private final boolean empty;
     public static final String DIGEST_TYPE = "MD5";
        
        /** Default resource priority */
@@ -51,6 +52,7 @@
                this.dictionary = null;
                this.digest = null;
                this.priority = DEFAULT_PRIORITY;
+               this.empty = true;
        }
        
        /** Create a data object that wraps an InputStream 
@@ -69,6 +71,7 @@
                this.dictionary = null;
                this.digest = digest;
         this.priority = DEFAULT_PRIORITY;
+        this.empty = false;
        }
        
        /** Create a data object that wraps a Dictionary. Digest will be 
computed
@@ -91,6 +94,7 @@
                    throw new IllegalStateException("Unexpected Exception while 
computing digest", e);
                }
         this.priority = DEFAULT_PRIORITY;
+        this.empty = false;
        }
 
        @Override
@@ -166,4 +170,8 @@
         d.update(bos.toByteArray());
         return digestToString(d);
     }
+    
+    public boolean isEmpty() {
+       return empty;
+    }
 }
\ No newline at end of file

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
 Wed Aug 26 13:04:25 2009
@@ -50,10 +50,11 @@
        /** Inform the installer that a resource is available for installation.
         *      also called if the resource has been modified since it was 
registered.
         */
-       void addResource(InstallableResource d) throws IOException;
+       void addResource(InstallableResource r) throws IOException;
        
-       /** Inform the installer that a resource is no longer available */
-       void removeResource(InstallableResource d) throws IOException;
+       /** Inform the installer that a resource is no longer available 
+        *      @param r an empty InstallableResource, isEmpty() must return 
true */
+       void removeResource(InstallableResource r) throws IOException;
        
        /** Return counters used for statistics, console display, testing, etc. 
*/
        long [] getCounters();

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
 Wed Aug 26 13:04:25 2009
@@ -110,10 +110,8 @@
        }
 
        public void removeResource(InstallableResource r) throws IOException {
-               final RegisteredResource rr = new 
RegisteredResourceImpl(bundleContext, r);
-               rr.setInstallable(false);
         synchronized (installerThread) {
-            installerThread.addNewResource(rr);
+            installerThread.removeResource(r);
         }
        }
 

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
 Wed Aug 26 13:04:25 2009
@@ -54,7 +54,8 @@
     private final SortedSet<OsgiInstallerTask> tasks = new 
TreeSet<OsgiInstallerTask>();
     private final SortedSet<OsgiInstallerTask> tasksForNextCycle = new 
TreeSet<OsgiInstallerTask>();
     private final List<SortedSet<RegisteredResource>> newResourcesSets = new 
ArrayList<SortedSet<RegisteredResource>>();
-    private final Set<String> newResourcesSchemes = new HashSet<String>(); 
+    private final Set<String> newResourcesSchemes = new HashSet<String>();
+    private final Set<String> urlsToRemove = new HashSet<String>();
     private boolean active = true;
     
     /** Group our RegisteredResource by OSGi entity */ 
@@ -137,6 +138,21 @@
         }
     }
     
+    /** Register a resource for removal, or ignore if we don't have that URL */
+    void removeResource(InstallableResource r) {
+               if(!r.isEmpty()) {
+                       throw new IllegalArgumentException("removeResource() 
got non-empty InstallableResource: " + r);
+               }
+               
+               // Will mark all resources which have r's URL as uninstallable
+               debug("Adding URL " + r.getUrl() + " to urlsToRemove");
+               urlsToRemove.add(r.getUrl());
+               
+        synchronized (newResources) {
+            newResources.notify();
+        }
+    }
+    
     /** Register a single new resource, will be processed on the next cycle */
     void addNewResource(RegisteredResource r) {
         synchronized (newResources) {
@@ -217,6 +233,19 @@
                 t.add(r);
             }
             newResources.clear();
+            
+            // Mark resources for removal according to urlsToRemove
+            if(!urlsToRemove.isEmpty()) {
+                for(SortedSet<RegisteredResource> group : 
registeredResources.values()) {
+                       for(RegisteredResource r : group) {
+                               if(urlsToRemove.contains(r.getUrl())) {
+                                       debug("Marking " + r + " 
uninistallable, URL is included in urlsToRemove");
+                                       r.setInstallable(false);
+                               }
+                       }
+                }
+            }
+            urlsToRemove.clear();
         }
     }
     

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
 Wed Aug 26 13:04:25 2009
@@ -100,17 +100,17 @@
        // Uninstall
        {
             resetCounters();
-            installer.removeResource(getInstallableResource(
+            installer.removeResource(getNonInstallableResource(
                     getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar")));
             
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
             
             resetCounters();
-            installer.removeResource(getInstallableResource(
+            installer.removeResource(getNonInstallableResource(
                     getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
             
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
             
             resetCounters();
-            installer.removeResource(getInstallableResource(
+            installer.removeResource(getNonInstallableResource(
                     getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.2.jar")));
             
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
             

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
 Wed Aug 26 13:04:25 2009
@@ -81,15 +81,15 @@
         assertCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, 3);
        
         resetCounters();
-        
installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME 
+ "-testbundle-1.0.jar")));
+        
installer.removeResource(getNonInstallableResource(getTestBundle(BUNDLE_BASE_NAME
 + "-testbundle-1.0.jar")));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
 
         resetCounters();
-        
installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME 
+ "-testbundle-1.1.jar")));
+        
installer.removeResource(getNonInstallableResource(getTestBundle(BUNDLE_BASE_NAME
 + "-testbundle-1.1.jar")));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         
         resetCounters();
-        
installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME 
+ "-testbundle-1.2.jar")));
+        
installer.removeResource(getNonInstallableResource(getTestBundle(BUNDLE_BASE_NAME
 + "-testbundle-1.2.jar")));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         
         assertNull("testbundle must be gone at end of test", 
findBundle("osgi-installer-testbundle"));

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
 Wed Aug 26 13:04:25 2009
@@ -74,7 +74,7 @@
         assertEquals("Config value must match", "bar", value);
         
         resetCounters();
-        installer.removeResource(r);
+        installer.removeResource(new InstallableResource(r.getUrl()));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         
         waitForConfiguration("After removing", cfgPid, TIMEOUT, false);
@@ -116,7 +116,7 @@
         configAdmin.stop();
         waitForConfigAdmin(false);
         resetCounters();
-        installer.removeResource(r);
+        installer.removeResource(new InstallableResource(r.getUrl()));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         sleep(1000L);
         resetCounters();

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigPrioritiesTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigPrioritiesTest.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigPrioritiesTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigPrioritiesTest.java
 Wed Aug 26 13:04:25 2009
@@ -81,11 +81,11 @@
         installer.addResource(c);
         assertConfigValue(pid, "foo", "c", TIMEOUT);
         installer.addResource(a);
-        installer.removeResource(c);
+        installer.removeResource(new InstallableResource(c.getUrl()));
         assertConfigValue(pid, "foo", "b", TIMEOUT);
-        installer.removeResource(b);
+        installer.removeResource(new InstallableResource(b.getUrl()));
         assertConfigValue(pid, "foo", "a", TIMEOUT);
-        installer.removeResource(a);
+        installer.removeResource(new InstallableResource(a.getUrl()));
         waitForConfiguration("After removing all resources", pid, TIMEOUT, 
false);
     }
 }

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java?rev=807989&r1=807988&r2=807989&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
 Wed Aug 26 13:04:25 2009
@@ -217,6 +217,10 @@
         return getInstallableResource(testBundle, null);
     }
     
+    protected InstallableResource getNonInstallableResource(File testBundle) 
throws IOException {
+       return new InstallableResource(URL_SCHEME + ":" + 
testBundle.getAbsolutePath());
+    }
+    
     protected InstallableResource getInstallableResource(File testBundle, 
String digest) throws IOException {
         return getInstallableResource(testBundle, digest, 
InstallableResource.DEFAULT_PRIORITY);
     }


Reply via email to