aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>2019-11-13 15:14:52 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-11-17 14:17:26 +0000
commit0f9257b8265404c82ccdfae6aafce940f20a2947 (patch)
treed2c93d843e3b8f68fa27aa614b24e1627cbc2853 /common
parentf9b702bbe6cc958b16aaaf983cdd4d6d93b818fd (diff)
Fixing sonar issue
Constant is used instead of repeated literal. Change-Id: I540c09f8ba596398257b34ff3189b1a3ce5ab416 Issue-ID: SDC-2654 Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
Diffstat (limited to 'common')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java60
1 files 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<Class, Class> 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<Class, Class> 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) {