You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/09/02 06:39:03 UTC
[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-10780 -
AbstractConfigurationEntryHandler - sonar findings
This is an automated email from the ASF dual-hosted git repository.
angela pushed a commit to branch SLING-10780
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
commit 2e609dfffc63c87a0ca3527037ea0e18c7914b62
Author: angela <an...@adobe.com>
AuthorDate: Thu Sep 2 08:38:51 2021 +0200
SLING-10780 - AbstractConfigurationEntryHandler - sonar findings
---
.../AbstractConfigurationEntryHandler.java | 49 ++++++++++++----------
.../handlers/DefaultEntryHandlersManager.java | 2 +-
.../handlers/ConfigEntryHandlerTest.java | 4 +-
3 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
index 2d2daf8..4b61ecc 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
@@ -34,12 +34,12 @@ abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandl
private boolean enforceConfigurationBelowConfigFolder;
- // SLING-10469 - regexp to catch configs and poetential sibling .dir folders that would carry the node properties from an export that would need to be ignored as well
- public AbstractConfigurationEntryHandler(@NotNull String extension) {
+ // SLING-10469 - regexp to catch configs and potential sibling .dir folders that would carry the node properties from an export that would need to be ignored as well
+ AbstractConfigurationEntryHandler(@NotNull String extension) {
super("/jcr_root/(?:apps|libs)/.+/(?<foldername>config|install)(\\.(?<runmode>[^/]+))?(.*)/(?<pid>[^\\/]*)\\." + extension + ("(?<dir>.dir(/\\.content\\.xml)?)?$"));
}
- void setEnforceConfgurationBelowConfigFolder(boolean enforceConfigurationBelowConfigFolder) {
+ void setEnforceConfigurationBelowConfigFolder(boolean enforceConfigurationBelowConfigFolder) {
this.enforceConfigurationBelowConfigFolder = enforceConfigurationBelowConfigFolder;
}
@@ -55,25 +55,7 @@ abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandl
// SLING-10469 - preventing invalid results as the corresponding configuration will be stripped from the resulting package causing the constraints of nt:file not to be satisfied (missing binary)
logger.info("{} is only a dir folder next to config - removing.", path);
} else {
- String pid = matcher.group("pid");
-
- int idx = pid.lastIndexOf('/');
- if (idx != -1) {
- pid = pid.substring(idx + 1);
- }
- String factoryPid = null;
- String id;
- int n = pid.indexOf('~');
- if (n == -1) {
- n = pid.indexOf('-');
- }
- if (n > 0) {
- factoryPid = pid.substring(0, n);
- id = factoryPid.concat("~").concat(pid.substring(n + 1));
- } else {
- id = pid;
- }
-
+ String id = extractId(matcher);
logger.info("Processing configuration '{}'.", id);
Dictionary<String, Object> configurationProperties;
@@ -106,6 +88,29 @@ abstract class AbstractConfigurationEntryHandler extends AbstractRegexEntryHandl
}
}
+ @NotNull
+ private static String extractId(@NotNull Matcher matcher) {
+ String pid = matcher.group("pid");
+
+ int idx = pid.lastIndexOf('/');
+ if (idx != -1) {
+ pid = pid.substring(idx + 1);
+ }
+
+ String id;
+ int n = pid.indexOf('~');
+ if (n == -1) {
+ n = pid.indexOf('-');
+ }
+ if (n > 0) {
+ String factoryPid = pid.substring(0, n);
+ id = factoryPid.concat("~").concat(pid.substring(n + 1));
+ } else {
+ id = pid;
+ }
+ return id;
+ }
+
protected abstract @Nullable Dictionary<String, Object> parseConfiguration(@NotNull String name, @NotNull InputStream input) throws IOException, ConverterException;
}
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
index f84043d..4491625 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
@@ -43,7 +43,7 @@ public class DefaultEntryHandlersManager implements EntryHandlersManager {
entryHandler = entryHandler.withConfig(configs.get(entryHandler.getClass().getName()));
}
if (entryHandler instanceof AbstractConfigurationEntryHandler) {
- ((AbstractConfigurationEntryHandler) entryHandler).setEnforceConfgurationBelowConfigFolder(enforceConfigurationsAndBundlesBelowProperFolder);
+ ((AbstractConfigurationEntryHandler) entryHandler).setEnforceConfigurationBelowConfigFolder(enforceConfigurationsAndBundlesBelowProperFolder);
} else if (entryHandler instanceof BundleEntryHandler) {
((BundleEntryHandler) entryHandler).setEnforceBundlesBelowInstallFolder(enforceConfigurationsAndBundlesBelowProperFolder);
((BundleEntryHandler) entryHandler).setSlingInitialContentPolicy(slingInitialContentPolicy);
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
index 004b15f..ba877df 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigEntryHandlerTest.java
@@ -127,7 +127,7 @@ public class ConfigEntryHandlerTest {
@Test
public void testConfigPathBelowInstallFolder() throws Exception {
ConfigurationEntryHandler handler = new ConfigurationEntryHandler();
- handler.setEnforceConfgurationBelowConfigFolder(true);
+ handler.setEnforceConfigurationBelowConfigFolder(true);
Archive archive = Mockito.mock(Archive.class);
Entry entry = Mockito.mock(Entry.class);
Mockito.when(archive.openInputStream(entry)).thenReturn(new ByteArrayInputStream(new byte[0]));
@@ -139,7 +139,7 @@ public class ConfigEntryHandlerTest {
@Test
public void testConfigPathNoneConfigBelowInstallFolder() throws Exception {
XmlConfigurationEntryHandler handler = new XmlConfigurationEntryHandler();
- handler.setEnforceConfgurationBelowConfigFolder(true);
+ handler.setEnforceConfigurationBelowConfigFolder(true);
Archive archive = Mockito.mock(Archive.class);
Entry entry = Mockito.mock(Entry.class);
Mockito.when(archive.openInputStream(entry)).thenReturn(new ByteArrayInputStream(new byte[0]));