Author: cziegeler
Date: Wed Jan 12 13:06:38 2011
New Revision: 1058119

URL: http://svn.apache.org/viewvc?rev=1058119&view=rev
Log:
SLING-1922 : Allow resource transformer for processing installable resources

Modified:
    
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/ResourceTransformer.java
    
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
    
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceComparatorTest.java
    
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceTest.java
    
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java

Modified: 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/ResourceTransformer.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/ResourceTransformer.java?rev=1058119&r1=1058118&r2=1058119&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/ResourceTransformer.java
 (original)
+++ 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/ResourceTransformer.java
 Wed Jan 12 13:06:38 2011
@@ -30,7 +30,7 @@ public interface ResourceTransformer {
      * resource, it should return <code>null</code>
      *
      * @param resource The resource
-     * @return A transformation result or <code>null</code>
+     * @return An array of transformation results or <code>null</code>
      */
-    TransformationResult transform(RegisteredResource resource);
+    TransformationResult[] transform(RegisteredResource resource);
 }

Modified: 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java?rev=1058119&r1=1058118&r2=1058119&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
 (original)
+++ 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/DefaultTransformer.java
 Wed Jan 12 13:06:38 2011
@@ -64,7 +64,7 @@ public class DefaultTransformer
     /**
      * @see 
org.apache.sling.installer.api.tasks.ResourceTransformer#transform(org.apache.sling.installer.api.tasks.RegisteredResource)
      */
-    public TransformationResult transform(final RegisteredResource resource) {
+    public TransformationResult[] transform(final RegisteredResource resource) 
{
         if ( resource.getType().equals(InstallableResource.TYPE_FILE) ) {
             return checkBundle(resource);
         } else if ( 
resource.getType().equals(InstallableResource.TYPE_PROPERTIES) ) {
@@ -77,7 +77,7 @@ public class DefaultTransformer
      * Check if the registered resource is a bundle.
      * @return
      */
-    private TransformationResult checkBundle(final RegisteredResource 
resource) {
+    private TransformationResult[] checkBundle(final RegisteredResource 
resource) {
         try {
             final Manifest m = getManifest(resource.getInputStream());
             if (m != null) {
@@ -92,7 +92,7 @@ public class DefaultTransformer
                         tr.setId(sn);
                         tr.setResourceType(InstallableResource.TYPE_BUNDLE);
 
-                        return tr;
+                        return new TransformationResult[] {tr};
                     }
                 }
             }
@@ -106,7 +106,7 @@ public class DefaultTransformer
      * Check if the registered resource is a configuration
      * @param resource The resource
      */
-    private TransformationResult checkConfiguration(final RegisteredResource 
resource) {
+    private TransformationResult[] checkConfiguration(final RegisteredResource 
resource) {
         final String url = resource.getURL();
         String lastIdPart = url;
         final int pos = lastIdPart.lastIndexOf('/');
@@ -150,7 +150,7 @@ public class DefaultTransformer
         tr.setId(id);
         tr.setResourceType(InstallableResource.TYPE_CONFIG);
 
-        return tr;
+        return new TransformationResult[] {tr};
     }
 
     /**

Modified: 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1058119&r1=1058118&r2=1058119&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
 (original)
+++ 
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
 Wed Jan 12 13:06:38 2011
@@ -176,15 +176,18 @@ public class OsgiInstallerImpl
 
             // if we don't have any tasks, we go to sleep
             if (!tasksCreated) {
-                // No tasks to execute - wait until new resources are
-                // registered
-                logger.debug("No tasks to process, going idle");
                 synchronized ( this.resourcesLock ) {
-                    try {
-                        this.resourcesLock.wait();
-                    } catch (InterruptedException ignore) {}
+                           // before we go to sleep, check if new resources 
arrived in the meantime
+                    if ( !this.hasNewResources()) {
+                        // No tasks to execute - wait until new resources are
+                        // registered
+                        logger.debug("No tasks to process, going idle");
+                        try {
+                            this.resourcesLock.wait();
+                        } catch (InterruptedException ignore) {}
+                        logger.debug("Notified of new resources, back to 
work");
+                    }
                 }
-                logger.debug("Notified of new resources, back to work");
                 sleep = false;
             }
             if ( sleep ) {
@@ -198,6 +201,14 @@ public class OsgiInstallerImpl
     }
 
     /**
+     * Checks if new resources are available.
+     * This method should only be invoked from within a synchronized 
(newResources) block!
+     */
+    private boolean hasNewResources() {
+        return !this.newResources.isEmpty() || 
!this.newResourcesSchemes.isEmpty() || !this.urlsToRemove.isEmpty();
+    }
+
+    /**
      * Check the scheme
      * @throws IllegalArgumentException
      */
@@ -535,9 +546,10 @@ public class OsgiInstallerImpl
                     if ( services[i] instanceof ResourceTransformer ) {
                         final ResourceTransformer transformer = 
(ResourceTransformer)services[i];
 
-                        final TransformationResult tr = 
transformer.transform(resource);
-                        if ( tr != null ) {
-                            this.persistentList.transform(resource, tr);
+                        final TransformationResult[] result = 
transformer.transform(resource);
+                        if ( result != null && result.length > 0 ) {
+                            // TODO: for now we support just one result
+                            this.persistentList.transform(resource, result[0]);
                             changed = true;
                             index--;
                             break;

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=1058119&r1=1058118&r2=1058119&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 12 13:06:38 2011
@@ -58,7 +58,7 @@ public class RegisteredResourceComparato
         final InstallableResource r = new InstallableResource(url, null, data, 
digest, null, priority);
         final InternalResource internal = InternalResource.create("test", r);
         final RegisteredResourceImpl rr = 
RegisteredResourceImpl.create(internal);
-        rr.update(new DefaultTransformer().transform(rr));
+        rr.update(new DefaultTransformer().transform(rr)[0]);
 
         return rr;
     }

Modified: 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceTest.java?rev=1058119&r1=1058118&r2=1058119&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceTest.java
 (original)
+++ 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/RegisteredResourceTest.java
 Wed Jan 12 13:06:38 2011
@@ -166,9 +166,9 @@ public class RegisteredResourceTest {
         new FileDataStore(new MockBundleContext());
         final InternalResource internal = InternalResource.create("test", is);
         final RegisteredResourceImpl rr = 
RegisteredResourceImpl.create(internal);
-        final TransformationResult tr = new DefaultTransformer().transform(rr);
+        final TransformationResult[] tr = new 
DefaultTransformer().transform(rr);
         if ( tr != null ) {
-            rr.update(tr);
+            rr.update(tr[0]);
         }
         return rr;
     }

Modified: 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java?rev=1058119&r1=1058118&r2=1058119&view=diff
==============================================================================
--- 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
 (original)
+++ 
sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
 Wed Jan 12 13:06:38 2011
@@ -54,7 +54,7 @@ public class TaskOrderingTest {
         final InternalResource internal = InternalResource.create("test",
                 new InstallableResource(url, null, new Hashtable<String, 
Object>(), null, null, null));
         final RegisteredResourceImpl rr = 
RegisteredResourceImpl.create(internal);
-        rr.update(new DefaultTransformer().transform(rr));
+        rr.update(new DefaultTransformer().transform(rr)[0]);
 
         final EntityResourceList erl = new EntityResourceList();
            erl.addOrUpdate(rr);


Reply via email to