You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/03/30 02:08:57 UTC

svn commit: r1307172 - in /sling/trunk/installer: core/src/main/java/org/apache/sling/installer/api/ core/src/main/java/org/apache/sling/installer/core/impl/ factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/...

Author: cziegeler
Date: Fri Mar 30 00:08:56 2012
New Revision: 1307172

URL: http://svn.apache.org/viewvc?rev=1307172&view=rev
Log:
SLING-2450 : JcrInstaller generates incorrect node name in /apps/system/config (or else the installer doesn't process the nodename properly)

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
    sling/trunk/installer/providers/jcr/pom.xml
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java?rev=1307172&r1=1307171&r2=1307172&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/InstallableResource.java Fri Mar 30 00:08:56 2012
@@ -105,6 +105,9 @@ public class InstallableResource {
      * It is only evaluated if the resource type is either unknown (null) or
      * {@link #TYPE_FILE} and a digest for the resource is delivered.
      * The value of this property is a string.
+     * This property might also be set for an {@link UpdateHandler} in order
+     * to give a hint for the (file) name the resource or dictionary should
+     * have.
      * @since 3.2.2
      */
     public static final String RESOURCE_URI_HINT = "resource.uri.hint";

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=1307172&r1=1307171&r2=1307172&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 Fri Mar 30 00:08:56 2012
@@ -358,6 +358,7 @@ public class OsgiInstallerImpl
             this.closeInputStreams(resources);
         }
     }
+
     /**
      * @see org.apache.sling.installer.api.OsgiInstaller#registerResources(java.lang.String, org.apache.sling.installer.api.InstallableResource[])
      */
@@ -776,7 +777,9 @@ public class OsgiInstallerImpl
                                             null);
                                     final RegisteredResource rr = this.persistentList.addOrUpdate(internalResource);
                                     final TransformationResult transRes = new TransformationResult();
-                                    transRes.setId(entityId);
+                                    // use the old entity id
+                                    final int pos = erl.getResourceId().indexOf(':');
+                                    transRes.setId(erl.getResourceId().substring(pos + 1));
                                     transRes.setResourceType(resourceType);
                                     if ( attributes != null ) {
                                         transRes.setAttributes(attributes);

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=1307172&r1=1307171&r2=1307172&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 Fri Mar 30 00:08:56 2012
@@ -91,7 +91,16 @@ public class ConfigTaskCreator
     @SuppressWarnings("unchecked")
     public void configurationEvent(final ConfigurationEvent event) {
         synchronized ( ConfigTaskCreator.getLock() ) {
-            final String id = (event.getFactoryPid() == null ? "" : event.getFactoryPid() + ".") + event.getPid();
+            final String id;
+            final String pid;
+            if (event.getFactoryPid() == null ) {
+                id = event.getPid();
+                pid = id;
+            } else {
+                pid = (event.getPid().startsWith(event.getFactoryPid() + '.') ?
+                        event.getPid().substring(event.getFactoryPid().length() + 1) : event.getPid());
+                id = event.getFactoryPid() + '.' + event.getPid();
+            }
             if ( event.getType() == ConfigurationEvent.CM_DELETED ) {
                 this.changeListener.resourceRemoved(InstallableResource.TYPE_CONFIG, id);
             } else {
@@ -113,10 +122,15 @@ public class ConfigTaskCreator
                         }
                         if ( persist ) {
                             final Map<String, Object> attrs = new HashMap<String, Object>();
+                            attrs.put(Constants.SERVICE_PID, event.getPid());
+                            if ( event.getFactoryPid() == null ) {
+                                attrs.put(InstallableResource.RESOURCE_URI_HINT, pid);
+                            } else {
+                                attrs.put(InstallableResource.RESOURCE_URI_HINT, event.getFactoryPid() + '-' + pid);
+                            }
                             if ( config.getBundleLocation() != null ) {
                                 attrs.put(InstallableResource.INSTALLATION_HINT, config.getBundleLocation());
                             }
-                            attrs.put(Constants.SERVICE_PID, event.getPid());
                             // Factory?
                             if (event.getFactoryPid() != null) {
                                 attrs.put(ConfigurationAdmin.SERVICE_FACTORYPID, event.getFactoryPid());

Modified: sling/trunk/installer/providers/jcr/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/pom.xml?rev=1307172&r1=1307171&r2=1307172&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/pom.xml (original)
+++ sling/trunk/installer/providers/jcr/pom.xml Fri Mar 30 00:08:56 2012
@@ -87,7 +87,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.installer.core</artifactId>
-            <version>3.2.0</version>
+            <version>3.2.2</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1307172&r1=1307171&r2=1307172&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java (original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java Fri Mar 30 00:08:56 2012
@@ -467,7 +467,9 @@ public class JcrInstaller implements Eve
         }
     }
 
-    /** Add WatchedFolder to our list if it doesn't exist yet */
+    /**
+     * Add WatchedFolder to our list if it doesn't exist yet.
+     */
     private void addWatchedFolder(final WatchedFolder toAdd)
     throws RepositoryException {
         WatchedFolder existing = null;
@@ -511,7 +513,7 @@ public class JcrInstaller implements Eve
                 toRemove.add(wf);
             }
         }
-        for(WatchedFolder wf : toRemove) {
+        for(final WatchedFolder wf : toRemove) {
             logger.info("Deleting {}, path does not exist anymore", wf);
             watchedFolders.remove(wf);
         }
@@ -519,7 +521,10 @@ public class JcrInstaller implements Eve
         return result;
     }
 
-    public void onEvent(EventIterator it) {
+    /**
+     * @see javax.jcr.observation.EventListener#onEvent(javax.jcr.observation.EventIterator)
+     */
+    public void onEvent(final EventIterator it) {
         // Got a DELETE or ADD on root - schedule folders rescan if one
         // of our root folders is impacted
         try {
@@ -539,7 +544,9 @@ public class JcrInstaller implements Eve
         }
     }
 
-    /** Run periodic scans of our watched folders, and watch for folders creations/deletions */
+    /**
+     * Run periodic scans of our watched folders, and watch for folders creations/deletions.
+     */
     public void runOneCycle() {
         logger.debug("Running watch cycle.");
 
@@ -595,6 +602,7 @@ public class JcrInstaller implements Eve
         } catch (final Exception e) {
             logger.warn("Exception in runOneCycle()", e);
         }
+
         try {
             Thread.sleep(RUN_LOOP_DELAY_MSEC);
         } catch (final InterruptedException ignore) {
@@ -731,7 +739,22 @@ public class JcrInstaller implements Eve
                 // update
                 final int pos = url.indexOf(':');
                 final String oldPath = url.substring(pos + 1);
-                final String nodePath = getPathWithHighestPrio(url.startsWith(URL_SCHEME + ':') ? oldPath : this.newConfigPath + id + ".config");
+
+                // calculate the new node path
+                final String nodePath;
+                if ( url.startsWith(URL_SCHEME + ':') ) {
+                    nodePath = getPathWithHighestPrio(oldPath);
+                } else {
+                    final int lastSlash = url.lastIndexOf('/');
+                    final int lastPos = url.lastIndexOf('.');
+                    final String name;
+                    if ( lastSlash == -1 || lastPos < lastSlash ) {
+                        name = id;
+                    } else {
+                        name = url.substring(lastSlash + 1, lastPos);
+                    }
+                    nodePath = getPathWithHighestPrio(this.newConfigPath + name + ".config");
+                }
                 // ensure extension 'config'
                 if ( !nodePath.endsWith(".config") ) {
                     if ( session.itemExists(nodePath) ) {
@@ -741,11 +764,18 @@ public class JcrInstaller implements Eve
                 } else {
                     path = nodePath;
                 }
+
                 resourceIsMoved = nodePath.equals(oldPath);
                 logger.debug("Update of {} at {}", resourceType, path);
             } else {
                 // add
-                path = this.newConfigPath + id + ".config";
+                final String name;
+                if ( attributes != null && attributes.get(InstallableResource.RESOURCE_URI_HINT) != null ) {
+                    name = (String)attributes.get(InstallableResource.RESOURCE_URI_HINT);
+                } else {
+                    name = id;
+                }
+                path = this.newConfigPath + name + ".config";
                 logger.debug("Add of {} at {}", resourceType, path);
             }