From 0f9257b8265404c82ccdfae6aafce940f20a2947 Mon Sep 17 00:00:00 2001 From: Dmitry Puzikov Date: Wed, 13 Nov 2019 15:14:52 +0100 Subject: Fixing sonar issue Constant is used instead of repeated literal. Change-Id: I540c09f8ba596398257b34ff3189b1a3ce5ab416 Issue-ID: SDC-2654 Signed-off-by: Dmitry Puzikov --- .../java/org/onap/config/ConfigurationUtils.java | 60 ++++++++++++++++------ 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java index 6adeb2db10..32adf55af4 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java @@ -89,6 +89,10 @@ public class ConfigurationUtils { private static final Map ARRAY_CLASS_MAP; + private static final String CONFIG_REGEX_TPL_OPT_1 = "CONFIG(-\\w*){0,1}(-(%s|%s|%s)){0,1}\\.(%s|%s|%s|%s)$"; + + private static final String CONFIG_REGEX_TPL_OPT_2 = "CONFIG(.)*\\.(%s|%s|%s|%s)$"; + static { Map arrayTypes = new HashMap<>(); arrayTypes.put(Byte.class, Byte[].class); @@ -148,12 +152,25 @@ public class ConfigurationUtils { file = file.toUpperCase().substring(file.lastIndexOf('!') + 1); file = file.substring(file.lastIndexOf('/') + 1); return file.matches( - "CONFIG(-\\w*){0,1}(-" + "(" + ConfigurationMode.OVERRIDE + "|" + ConfigurationMode.MERGE + "|" - + ConfigurationMode.UNION + ")){0,1}" + "\\.(" + ConfigurationType.PROPERTIES.name() + "|" - + ConfigurationType.XML.name() + "|" + ConfigurationType.JSON.name() + "|" - + ConfigurationType.YAML.name() + ")$") || file.matches( - "CONFIG(.)*\\.(" + ConfigurationType.PROPERTIES.name() + "|" + ConfigurationType.XML.name() + "|" - + ConfigurationType.JSON.name() + "|" + ConfigurationType.YAML.name() + ")$"); + String.format( + CONFIG_REGEX_TPL_OPT_1, + ConfigurationMode.OVERRIDE, + ConfigurationMode.MERGE, + ConfigurationMode.UNION, + ConfigurationType.PROPERTIES.name(), + ConfigurationType.XML.name(), + ConfigurationType.JSON.name(), + ConfigurationType.YAML.name() + ) + ) || file.matches( + String.format( + CONFIG_REGEX_TPL_OPT_2, + ConfigurationType.PROPERTIES.name(), + ConfigurationType.XML.name(), + ConfigurationType.JSON.name(), + ConfigurationType.YAML.name() + ) + ); } public static boolean isConfig(File file) { @@ -188,12 +205,18 @@ public class ConfigurationUtils { file = file.toUpperCase().substring(file.lastIndexOf('!') + 1); file = file.substring(file.lastIndexOf('/') + 1); - Pattern pattern = Pattern.compile( - "CONFIG(-\\w*){0,1}(-" + "(" + ConfigurationMode.OVERRIDE + "|" + ConfigurationMode.MERGE + "|" - + ConfigurationMode.UNION + ")){0,1}" + "\\.(" + ConfigurationType.PROPERTIES.name() + "|" - + ConfigurationType.XML.name() + "|" + ConfigurationType.JSON.name() + "|" - + ConfigurationType.YAML.name() + ")$"); + String.format( + CONFIG_REGEX_TPL_OPT_1, + ConfigurationMode.OVERRIDE, + ConfigurationMode.MERGE, + ConfigurationMode.UNION, + ConfigurationType.PROPERTIES.name(), + ConfigurationType.XML.name(), + ConfigurationType.JSON.name(), + ConfigurationType.YAML.name() + ) + ); Matcher matcher = pattern.matcher(file); boolean b1 = matcher.matches(); if (b1) { @@ -571,10 +594,17 @@ public class ConfigurationUtils { file = file.toUpperCase().substring(file.lastIndexOf('!') + 1); file = file.substring(file.lastIndexOf('/') + 1); Pattern pattern = Pattern.compile( - "CONFIG(-\\w*){0,1}(-" + "(" + ConfigurationMode.OVERRIDE + "|" + ConfigurationMode.MERGE + "|" - + ConfigurationMode.UNION + ")){0,1}" + "\\.(" + ConfigurationType.PROPERTIES.name() + "|" - + ConfigurationType.XML.name() + "|" + ConfigurationType.JSON.name() + "|" - + ConfigurationType.YAML.name() + ")$"); + String.format( + CONFIG_REGEX_TPL_OPT_1, + ConfigurationMode.OVERRIDE, + ConfigurationMode.MERGE, + ConfigurationMode.UNION, + ConfigurationType.PROPERTIES.name(), + ConfigurationType.XML.name(), + ConfigurationType.JSON.name(), + ConfigurationType.YAML.name() + ) + ); Matcher matcher = pattern.matcher(file); boolean b1 = matcher.matches(); if (b1) { -- cgit 1.2.3-korg