incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1075872 - in /sling/trunk/installer: core/ core/src/main/java/org/apache/sling/installer/api/tasks/ core/src/main/java/org/apache/sling/installer/core/impl/ core/src/main/java/org/apache/sling/installer/core/impl/console/ core/src/test/jav...
Date Tue, 01 Mar 2011 16:13:35 GMT
Author: cziegeler
Date: Tue Mar  1 16:13:34 2011
New Revision: 1075872

URL: http://svn.apache.org/viewvc?rev=1075872&view=rev
Log:
SLING-2005 : Don't add alias as a property to factory configurations

Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResourceGroup.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.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/RegisteredResourceTest.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
    sling/trunk/installer/factories/configuration/pom.xml
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/AbstractConfigTask.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Tue Mar  1 16:13:34 2011
@@ -59,14 +59,14 @@
                         </Import-Package>
 						<Export-Package>
 							org.apache.sling.installer.api;version=3.1.0,
-                            org.apache.sling.installer.api.tasks;version=1.0.0
+                            org.apache.sling.installer.api.tasks;version=1.1.0
                         </Export-Package>
 						<Private-Package>
-						    org.apache.sling.installer.core.impl.*,
-                            org.osgi.util.tracker
+						    org.apache.sling.installer.core.impl.*
 						</Private-Package>
                         <Embed-Dependency>
-                            org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*"
+                            org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*",
+                            org.osgi.compendium;inline="org/osgi/util/tracker/*"
                         </Embed-Dependency>
 					</instructions>
 				</configuration>

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallTask.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallTask.java
Tue Mar  1 16:13:34 2011
@@ -76,6 +76,18 @@ public abstract class InstallTask implem
 	    }
 	}
 
+    /**
+     * Set the finished state for the resource and the alias
+     * @param state The new state.
+     * @param alias The new alias
+     * @since 1.1
+     */
+    public void setFinishedState(final ResourceState state, final String alias) {
+        if ( this.resourceGroup != null ) {
+            this.resourceGroup.setFinishState(state, alias);
+        }
+    }
+
     @Override
     public String toString() {
         return getClass().getSimpleName() + ": " + this.getResource();

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResourceGroup.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResourceGroup.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResourceGroup.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/TaskResourceGroup.java
Tue Mar  1 16:13:34 2011
@@ -33,9 +33,26 @@ public interface TaskResourceGroup {
 
 
     /**
-     * Set the finish state for active the resource.
+     * Set the finish state for the active resource.
      * If this resource has been uninstalled, check the next in the list if it needs to
      * be reactivated.
      */
     void setFinishState(ResourceState state);
+
+    /**
+     * Set the finish state for the active resource and register an alias.
+     * This method does the same as {@link #setFinishState(ResourceState)}
+     * but in addition registers an alias id for the resource.
+     *
+     * @see #setFinishState(ResourceState)
+     * @since 1.1
+     */
+    void setFinishState(ResourceState state, String alias);
+
+    /**
+     * Get the current alias for this group.
+     * @return The alias or <code>null</code>
+     * @since 1.1
+     */
+    String getAlias();
 }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
Tue Mar  1 16:13:34 2011
@@ -44,7 +44,7 @@ public class EntityResourceList implemen
     private static final long serialVersionUID = 6L;
 
     /** Serialization version. */
-    private static final int VERSION = 1;
+    private static final int VERSION = 2;
 
     /** Logger. */
     private static final Logger LOGGER = LoggerFactory.getLogger(EntityResourceList.class);
@@ -52,6 +52,15 @@ public class EntityResourceList implemen
     /** The set of registered resources for this entity. */
     private final SortedSet<TaskResource> resources = new TreeSet<TaskResource>();
 
+    /** Alias for this id. */
+    private String alias;
+
+    /** The resource id of this group. */
+    private String resourceId;
+
+    public EntityResourceList(final String resourceId) {
+        this.resourceId = resourceId;
+    }
     /**
      * Serialize the object
      * - write version id
@@ -66,6 +75,8 @@ public class EntityResourceList implemen
         for(final RegisteredResource rr : this.resources) {
             out.writeObject(rr);
         }
+        out.writeObject(this.alias);
+        out.writeObject(this.resourceId);
     }
 
     /**
@@ -76,7 +87,7 @@ public class EntityResourceList implemen
     private void readObject(final java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException {
         final int version = in.readInt();
-        if ( version != VERSION ) {
+        if ( version < 1 || version > VERSION ) {
             throw new ClassNotFoundException(this.getClass().getName());
         }
         Util.setField(this, "resources", new TreeSet<RegisteredResource>());
@@ -85,9 +96,15 @@ public class EntityResourceList implemen
             final TaskResource rr = (TaskResource)in.readObject();
             this.resources.add(rr);
         }
+        if ( version > 1 ) {
+            this.alias = (String)in.readObject();
+            this.resourceId = (String)in.readObject();
+        }
     }
 
-    /** The resource list is empty if it contains no resources. */
+    /**
+     * The resource list is empty if it contains no resources.
+     */
     public boolean isEmpty() {
         return resources.isEmpty();
     }
@@ -117,9 +134,39 @@ public class EntityResourceList implemen
     }
 
     /**
-     * Set the finish state for the resource.
-     * If this resource has been uninstalled, check the next in the list if it needs to
-     * be reactivated.
+     * Get the alias for this group or null
+     */
+    public String getAlias() {
+        return this.alias;
+    }
+
+    /**
+     * Get the alias for this group or null
+     */
+    public String getFullAlias() {
+        if ( this.alias != null ) {
+            final int pos = this.resourceId.indexOf(':');
+            return this.resourceId.substring(0, pos + 1) + this.alias;
+        }
+        return null;
+    }
+
+    /**
+     * Get the resource id.
+     */
+    public String getResourceId() {
+        return this.resourceId;
+    }
+
+    /**
+     * Set the resource id
+     */
+    public void setResourceId(final String id) {
+        this.resourceId = id;
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState)
      */
     public void setFinishState(ResourceState state) {
         final TaskResource toActivate = getActiveResource();
@@ -153,6 +200,14 @@ public class EntityResourceList implemen
         }
     }
 
+    /**
+     * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState,
java.lang.String)
+     */
+    public void setFinishState(final ResourceState state, final String alias) {
+        this.setFinishState(state);
+        this.alias = alias;
+    }
+
     private void cleanup(final RegisteredResource rr) {
         if ( rr instanceof RegisteredResourceImpl ) {
             ((RegisteredResourceImpl)rr).cleanup();

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=1075872&r1=1075871&r2=1075872&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
Tue Mar  1 16:13:34 2011
@@ -663,14 +663,18 @@ public class OsgiInstallerImpl
      * @see org.apache.sling.installer.api.ResourceChangeListener#resourceAddedOrUpdated(java.lang.String,
java.lang.String, java.io.InputStream, java.util.Dictionary)
      */
     public void resourceAddedOrUpdated(final String resourceType,
-            final String resourceId,
+            String resourceId,
             final InputStream is,
             final Dictionary<String, Object> dict) {
-        final String key = resourceType + ':' + resourceId;
+        String key = resourceType + ':' + resourceId;
         try {
             final ResourceData data = ResourceData.create(is, dict);
             synchronized ( this.resourcesLock ) {
                 final EntityResourceList erl = this.persistentList.getEntityResourceList(key);
+                if ( erl != null ) {
+                    resourceId = erl.getResourceId();
+                    key = resourceType + ':' + resourceId;
+                }
                 logger.info("Added or updated {}:{}: {}", new Object[] {resourceType, resourceId,
erl});
 
                 // we first check for update
@@ -783,13 +787,15 @@ public class OsgiInstallerImpl
     /**
      * @see org.apache.sling.installer.api.ResourceChangeListener#resourceRemoved(java.lang.String,
java.lang.String)
      */
-    public void resourceRemoved(final String resourceType, final String resourceId) {
-        final String key = resourceType + ':' + resourceId;
+    public void resourceRemoved(final String resourceType, String resourceId) {
+        String key = resourceType + ':' + resourceId;
         synchronized ( this.resourcesLock ) {
             final EntityResourceList erl = this.persistentList.getEntityResourceList(key);
             logger.info("Removed {}:{}: {}", new Object[] {resourceType, resourceId, erl});
             // if this is not registered at all, we can simply ignore this
             if ( erl != null ) {
+                resourceId = erl.getResourceId();
+                key = resourceType + ':' + resourceId;
                 final TaskResource tr = erl.getFirstResource();
                 if ( tr != null ) {
                     if ( tr.getState() != ResourceState.IGNORED ) {

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
Tue Mar  1 16:13:34 2011
@@ -103,6 +103,11 @@ public class PersistentResourceList {
         this.untransformedResources = unknownList != null ? unknownList : new ArrayList<RegisteredResource>();
 
         this.updateCache();
+
+        // update resource ids
+        for(final Map.Entry<String, EntityResourceList> entry : this.data.entrySet())
{
+            entry.getValue().setResourceId(entry.getKey());
+        }
     }
 
     /**
@@ -179,7 +184,7 @@ public class PersistentResourceList {
 
             EntityResourceList t = this.data.get(input.getEntityId());
             if (t == null) {
-                t = new EntityResourceList();
+                t = new EntityResourceList(input.getEntityId());
                 this.data.put(input.getEntityId(), t);
             }
 
@@ -236,7 +241,16 @@ public class PersistentResourceList {
      * Get the resource group for an entity id.
      */
     public EntityResourceList getEntityResourceList(final String entityId) {
-        return this.data.get(entityId);
+        EntityResourceList erl = this.data.get(entityId);
+        if ( erl == null ) {
+            for(final EntityResourceList group : this.data.values()) {
+                if ( entityId.equals(group.getFullAlias()) ) {
+                    erl = group;
+                    break;
+                }
+            }
+        }
+        return erl;
     }
 
     /**

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=1075872&r1=1075871&r2=1075872&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
Tue Mar  1 16:13:34 2011
@@ -148,13 +148,13 @@ public class OsgiInstallerWebConsolePlug
         return type;
     }
 
-    private String getEntityId(final RegisteredResource rsrc) {
+    private String getEntityId(final RegisteredResource rsrc, String alias) {
         String id = rsrc.getEntityId();
         final int pos = id.indexOf(':');
         if ( pos != -1 ) {
             id = id.substring(pos + 1);
         }
-        return id;
+        return (alias == null ? id : id + '\n' + alias);
     }
 
     /** Default date format used. */
@@ -196,7 +196,7 @@ public class OsgiInstallerWebConsolePlug
                     rt = toActivate.getType();
                 }
                 pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
-                        getEntityId(toActivate),
+                        getEntityId(toActivate, group.getAlias()),
                         toActivate.getDigest(),
                         toActivate.getURL(),
                         toActivate.getState());
@@ -223,7 +223,7 @@ public class OsgiInstallerWebConsolePlug
                         rt = first.getType();
                     }
                     pw.print("<tr><td>");
-                    pw.print(getEntityId(first));
+                    pw.print(getEntityId(first, group.getAlias()));
                     pw.print("</td><td>");
                     pw.print(first.getDigest());
                     pw.print("</td><td>");
@@ -297,7 +297,7 @@ public class OsgiInstallerWebConsolePlug
                     rt = toActivate.getType();
                 }
                 pw.printf("- %s: %s, %s, %s%n",
-                        getEntityId(toActivate),
+                        getEntityId(toActivate, group.getAlias()),
                         toActivate.getDigest(),
                         toActivate.getURL(),
                         toActivate.getState());
@@ -317,7 +317,7 @@ public class OsgiInstallerWebConsolePlug
                         rt = first.getType();
                     }
                     pw.printf("* %s: %s, %s, %s%n",
-                            getEntityId(first),
+                            getEntityId(first, group.getAlias()),
                             first.getDigest(),
                             first.getURL(),
                             first.getState());

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=1075872&r1=1075871&r2=1075872&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
Tue Mar  1 16:13:34 2011
@@ -19,7 +19,6 @@
 package org.apache.sling.installer.core.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -131,8 +130,8 @@ public class RegisteredResourceTest {
         final Dictionary<String, Object> data = new Hashtable<String, Object>();
         final InstallableResource rA = new InstallableResource("test:urlA", null, data, null,
null, null);
         final InstallableResource rB = new InstallableResource("test:urlB", null, data, null,
null, null);
-        assertFalse(
-                "Expecting configs with same data but different URLs to have different digests",
+        assertTrue(
+                "Expecting configs with same data but different URLs to have same digests",
                 create(rA).getDigest().equals(create(rB).getDigest()));
     }
 

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=1075872&r1=1075871&r2=1075872&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
Tue Mar  1 16:13:34 2011
@@ -54,7 +54,7 @@ public class TaskOrderingTest {
         RegisteredResourceImpl rr = RegisteredResourceImpl.create(internal);
         rr = (RegisteredResourceImpl)rr.clone(new DefaultTransformer().transform(rr)[0]);
 
-        final EntityResourceList erl = new EntityResourceList();
+        final EntityResourceList erl = new EntityResourceList("test");
 	    erl.addOrUpdate(rr);
 	    return erl;
 	}

Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
(original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
Tue Mar  1 16:13:34 2011
@@ -44,7 +44,7 @@ public class BundleTaskCreatorTest {
 	    }
 		final SortedSet<InstallTask> tasks = new TreeSet<InstallTask>();
         for(final TaskResource r : sortedResources) {
-            final EntityResourceList erl = new EntityResourceList();
+            final EntityResourceList erl = new EntityResourceList(r.getEntityId());
             erl.addOrUpdate(r);
   		    tasks.add(btc.createTask(erl));
         }

Modified: sling/trunk/installer/factories/configuration/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/pom.xml?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/pom.xml (original)
+++ sling/trunk/installer/factories/configuration/pom.xml Tue Mar  1 16:13:34 2011
@@ -29,7 +29,7 @@
     <version>0.9.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
-    <name>Apache Sling Configuration Admin Installer</name>
+    <name>Apache Sling Installer Configuration Admin Support</name>
     <description> 
         Provides support for configurations to the Apache Sling OSGi installer
     </description>

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/AbstractConfigTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/AbstractConfigTask.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/AbstractConfigTask.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/AbstractConfigTask.java
Tue Mar  1 16:13:34 2011
@@ -20,8 +20,6 @@ package org.apache.sling.installer.facto
 
 import java.io.IOException;
 import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
 
 import org.apache.sling.installer.api.tasks.InstallTask;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
@@ -43,6 +41,9 @@ abstract class AbstractConfigTask extend
     /** Factory PID or null */
     protected final String factoryPid;
 
+    /** Alias factory pid or null. */
+    protected String aliasPid;
+
     /** Configuration admin. */
     private final ConfigurationAdmin configAdmin;
 
@@ -53,6 +54,11 @@ abstract class AbstractConfigTask extend
         this.configAdmin = configAdmin;
         this.configPid = (String)getResource().getAttribute(Constants.SERVICE_PID);
         this.factoryPid = (String)getResource().getAttribute(ConfigurationAdmin.SERVICE_FACTORYPID);
+        if ( r.getAlias() != null ) {
+            this.aliasPid = r.getAlias().substring(this.factoryPid.length() + 1);
+        } else {
+            this.aliasPid = null;
+        }
     }
 
     protected Logger getLogger() {
@@ -70,30 +76,20 @@ abstract class AbstractConfigTask extend
         return (factoryPid == null ? "" : factoryPid + ".") + configPid;
     }
 
-    protected Dictionary<String, Object> getDictionary() {
-        // Copy dictionary and add pseudo-properties
-        final Dictionary<String, Object> d = this.getResource().getDictionary();
-        if ( d == null ) {
+    protected String getCompositeAliasPid() {
+        if ( this.aliasPid == null || this.factoryPid == null ) {
             return null;
         }
+        return factoryPid + "." + this.aliasPid;
+    }
 
-        final Dictionary<String, Object> result = new Hashtable<String, Object>();
-        final Enumeration<String> e = d.keys();
-        while(e.hasMoreElements()) {
-            final String key = e.nextElement();
-            result.put(key, d.get(key));
-        }
-
-        if ( this.factoryPid != null ) {
-            result.put(ConfigTaskCreator.ALIAS_KEY, configPid);
-        }
-
-        return result;
+    protected Dictionary<String, Object> getDictionary() {
+        return this.getResource().getDictionary();
     }
 
     protected Configuration getConfiguration(final ConfigurationAdmin ca,
                                              final boolean createIfNeeded)
     throws IOException, InvalidSyntaxException {
-        return ConfigUtil.getConfiguration(ca, this.factoryPid, this.configPid, createIfNeeded,
true);
+        return ConfigUtil.getConfiguration(ca, this.factoryPid, (this.factoryPid != null
? this.aliasPid : this.configPid), createIfNeeded);
     }
 }

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigInstallTask.java
Tue Mar  1 16:13:34 2011
@@ -67,12 +67,15 @@ public class ConfigInstallTask extends A
                 }
                 config.update(getDictionary());
                 ctx.log("Installed configuration {} from resource {}", config.getPid(), getResource());
-                this.setFinishedState(ResourceState.INSTALLED);
+                if ( this.factoryPid != null ) {
+                    this.aliasPid = config.getPid();
+                }
+                this.setFinishedState(ResourceState.INSTALLED, this.getCompositeAliasPid());
                 this.getLogger().debug("Configuration " + config.getPid()
                             + " " + (created ? "created" : "updated")
                             + " from " + getResource());
             } else {
-                this.setFinishedState(ResourceState.IGNORED);
+                this.setFinishedState(ResourceState.IGNORED, this.getCompositeAliasPid());
             }
         } catch (Exception e) {
             this.getLogger().debug("Exception during installation of config " + this.getResource()
+ " : " + e.getMessage() + ". Retrying later.", e);

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
Tue Mar  1 16:13:34 2011
@@ -44,8 +44,6 @@ import org.osgi.service.cm.Configuration
 public class ConfigTaskCreator
     implements InstallTaskFactory, ConfigurationListener, ResourceTransformer {
 
-    public static final String ALIAS_KEY = "org.apache.sling.installer.osgi.factoryaliaspid";
-
     /** Configuration admin. */
     private ConfigurationAdmin configAdmin;
 
@@ -90,7 +88,7 @@ public class ConfigTaskCreator
                 final Configuration config = ConfigUtil.getConfiguration(configAdmin,
                         event.getFactoryPid(),
                         event.getPid(),
-                        false, false);
+                        false);
                 if ( config != null ) {
                     final Dictionary<String, Object> dict = ConfigUtil.cleanConfiguration(config.getProperties());
                     this.changeListener.resourceAddedOrUpdated(InstallableResource.TYPE_CONFIG,
id, null, dict);

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java?rev=1075872&r1=1075871&r2=1075872&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java
(original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java
Tue Mar  1 16:13:34 2011
@@ -19,6 +19,7 @@
 package org.apache.sling.installer.factories.configuration.impl;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashSet;
@@ -41,12 +42,19 @@ abstract class ConfigUtil {
      */
     private static final String CONFIG_PATH_KEY = "org.apache.sling.installer.osgi.path";
 
+    /**
+     * This property has been used in older versions to keep track of factory
+     * configurations.
+     */
+    private static final String ALIAS_KEY = "org.apache.sling.installer.osgi.factoryaliaspid";
+
     /** Configuration properties to ignore when comparing configs */
     private static final Set<String> IGNORED_PROPERTIES = new HashSet<String>();
     static {
         IGNORED_PROPERTIES.add(Constants.SERVICE_PID);
         IGNORED_PROPERTIES.add(CONFIG_PATH_KEY);
-        IGNORED_PROPERTIES.add(ConfigTaskCreator.ALIAS_KEY);
+        IGNORED_PROPERTIES.add(ALIAS_KEY);
+        IGNORED_PROPERTIES.add(ConfigurationAdmin.SERVICE_FACTORYPID);
     }
 
     private static Set<String> collectKeys(final Dictionary<String, Object>a)
{
@@ -69,8 +77,25 @@ abstract class ConfigUtil {
             final Set<String> keysB = collectKeys(b);
             if ( keysA.size() == keysB.size() && keysA.containsAll(keysB) ) {
                 for(final String key : keysA ) {
-                    if ( !a.get(key).equals(b.get(key)) ) {
-                        return result;
+                    final Object valA = a.get(key);
+                    final Object valB = b.get(key);
+                    if ( valA.getClass().isArray() ) {
+                        if ( !Arrays.equals((Object[])valA, (Object[])valB) ) {
+                            return result;
+                        }
+                    } else if ( valA instanceof Number ) {
+                        // JCR only supports Long but not Integer
+                        // therefore we have to add a special case here!
+                        if ( ! (valB instanceof Number) ) {
+                            return result;
+                        }
+                        if ( !(String.valueOf(valA).equals(String.valueOf(valB))) ) {
+                            return result;
+                        }
+                    } else {
+                        if ( !a.get(key).equals(b.get(key)) ) {
+                            return result;
+                        }
                     }
                 }
                 result = true;
@@ -98,8 +123,7 @@ abstract class ConfigUtil {
     public static Configuration getConfiguration(final ConfigurationAdmin ca,
             final String factoryPid,
             final String configPid,
-            final boolean createIfNeeded,
-            final boolean useAliasForFactory)
+            final boolean createIfNeeded)
     throws IOException, InvalidSyntaxException {
         Configuration result = null;
 
@@ -115,11 +139,13 @@ abstract class ConfigUtil {
                 }
             }
         } else {
-            Configuration configs[] = ca.listConfigurations("(&("
-                    + ConfigurationAdmin.SERVICE_FACTORYPID + "=" + factoryPid
-                    + ")(" + (useAliasForFactory ? ConfigTaskCreator.ALIAS_KEY : Constants.SERVICE_PID)
+ "=" + configPid
-                    + "))");
-
+            Configuration configs[] = null;
+            if ( configPid != null ) {
+                configs = ca.listConfigurations("(&("
+                        + ConfigurationAdmin.SERVICE_FACTORYPID + "=" + factoryPid
+                        + ")(" + Constants.SERVICE_PID + "=" + configPid
+                        + "))");
+            }
             if (configs == null || configs.length == 0) {
                 if (createIfNeeded) {
                     result = ca.createFactoryConfiguration(factoryPid, null);



Mime
View raw message