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 2019/03/14 09:11:17 UTC
[sling-org-apache-sling-installer-factory-configuration] branch
master updated: SLING-8315 : Wrong calculation of factory config id in some
cases
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-configuration.git
The following commit(s) were added to refs/heads/master by this push:
new f0caf01 SLING-8315 : Wrong calculation of factory config id in some cases
f0caf01 is described below
commit f0caf01e7edf172a483ecefb0c95d2e5e17b7636
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Mar 14 10:10:29 2019 +0100
SLING-8315 : Wrong calculation of factory config id in some cases
---
.../configuration/impl/ConfigUpdateHandler.java | 23 +++++++---
.../impl/ConfigUpdateHandlerTest.java | 50 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
index 0a27403..b011329 100644
--- a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
+++ b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
@@ -83,18 +83,31 @@ public class ConfigUpdateHandler implements ResourceUpdater {
}
}
- private void updateFactoryConfig(final UpdatableResourceGroup group) {
- final String alias = group.getAlias();
- final String oldId = group.getId();
-
- // change group id
+ 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--;
+ }
+
final String factoryPid = alias.substring(0, pos - 1);
final String pid = oldId.substring(factoryPid.length() + 1);
+ return new String[] { factoryPid, pid };
+ }
+
+ private void updateFactoryConfig(final UpdatableResourceGroup group) {
+ final String alias = group.getAlias();
+ final String oldId = group.getId();
+
+ // change group id
+ final String[] result = getFactoryPidAndPid(alias, oldId);
+
+ final String factoryPid = result[0];
+ final String pid = result[1];
+
final String newId = ConfigUtil.getPIDOfFactoryPID(factoryPid, pid);
group.setId(newId);
// clear alias
diff --git a/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
new file mode 100644
index 0000000..bbabb7d
--- /dev/null
+++ b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.installer.factories.configuration.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ConfigUpdateHandlerTest {
+
+ private void checkFactoryPid(final String alias, final String oldId, final String factoryId, final String pid) {
+ final ConfigUpdateHandler cuh = new ConfigUpdateHandler(null, null);
+ final String[] result = cuh.getFactoryPidAndPid(alias, oldId);
+ assertEquals(factoryId, result[0]);
+ assertEquals(pid, result[1]);
+ }
+
+ @Test public void testGettingFactoryPid() {
+ // normal conversion
+ checkFactoryPid("org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment.org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment.43e4778d-3e72-460a-9da9-bca80558f1f7",
+ "org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment.my-platform",
+ "org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment", "my-platform");
+ // case where the pid starts with the same characters as the factory pid : "c"
+ checkFactoryPid(
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.08f330fd-63d2-4175-ad3c-79efa3c69e2f",
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.cloud",
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup", "cloud");
+ // case where the pid starts with the same characters as the factory pid : "co"
+ checkFactoryPid(
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.3ba307f5-a5d0-40a4-98b6-8616b7a1d1e8",
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup.contentpackages",
+ "com.apache.sling.upgrades.cleanup.impl.UpgradeContentCleanup", "contentpackages");
+ }
+}