You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2019/06/22 09:17:45 UTC

[GitHub] [sling-org-apache-sling-installer-factory-configuration] cziegeler commented on a change in pull request #4: SLING-8523 : Duplicate OSGI configs after upgrade

cziegeler commented on a change in pull request #4: SLING-8523 : Duplicate OSGI configs after upgrade
URL: https://github.com/apache/sling-org-apache-sling-installer-factory-configuration/pull/4#discussion_r296439795
 
 

 ##########
 File path: src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
 ##########
 @@ -77,27 +77,57 @@ public void update(final Collection<UpdatableResourceGroup> groups) {
     private void update(final UpdatableResourceGroup group) {
         if ( this.activator.isActive() ) {
             // check if the group handles configurations and has an alias (aka factory config)
-            if ( InstallableResource.TYPE_CONFIG.equals(group.getResourceType()) && group.getAlias() != null ) {
+            if ( InstallableResource.TYPE_CONFIG.equals(group.getResourceType()) && ( group.getAlias() != null || group.getId().contains("-") )) {
+                this.logger.debug("Configuration going under updation is : {} with alias : {}", group.getId(), group.getAlias());
                 this.updateFactoryConfig(group);
             }
         }
     }
 
     protected String[] getFactoryPidAndPid(final String alias, final String oldId) {
         int pos = 0;
-        while ( alias.charAt(pos) == oldId.charAt(pos) ) {
-            pos++;
-        }
-        while (alias.charAt(pos - 1) != '.') {
-            pos--;
-        }
+        String factoryPid;
+        String pid;
+        if(alias != null) {
+
+            while (alias.charAt(pos) == oldId.charAt(pos)) {
+                pos++;
+            }
+            while (alias.charAt(pos - 1) != '.') {
+                pos--;
+            }
+
+            factoryPid = alias.substring(0, pos - 1);
+            pid = oldId.substring(factoryPid.length() + 1);
+        } else {
+            // extract factory id for these cases where alias is not available and factoryId and pid need to be separated from the old id string itself
+            //format assumption ::: "factory_pid.factory_pid.pid"
+            // split pid with lastIndexOf('.') then remove the duplicate factory_pid part from the remaining string using the middle dot split index
 
-        final String factoryPid = alias.substring(0, pos - 1);
-        final String pid = oldId.substring(factoryPid.length() + 1);
+            String factoryIdString = oldId.substring(0,oldId.lastIndexOf('.')+1); // keep it +1 to have last dot intact so that we always have even dots in the string
 
 Review comment:
   you could store lastIndexOf in an int variable and reuse it below

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services