SLING-10780 - AbstractConfigurationEntryHandler - sonar findings
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 @@
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 @@
// 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 @@
}
}
+ @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 @@
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 @@
@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 @@
@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]));