From d4e0f7cb740ecde0ba312c9a1f05b8de14632dd8 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Fri, 1 Dec 2023 20:22:28 -0500 Subject: [PATCH] [configuration] Migrate to commons configuration2 and expose duplicate keys per original logic with version 2 they don't expose that condition but one test wants it so wrote it such that can occur. Not sure that is wanted or not but seems existing behaviour. --- pom.xml | 11 +++++--- .../masterthought/cucumber/ReportParser.java | 27 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index d81cef887..5870f4e29 100644 --- a/pom.xml +++ b/pom.xml @@ -302,9 +302,14 @@ test - commons-configuration - commons-configuration - 1.10 + org.apache.commons + commons-configuration2 + 2.9.0 + + + commons-beanutils + commons-beanutils + 1.9.4 org.apache.commons diff --git a/src/main/java/net/masterthought/cucumber/ReportParser.java b/src/main/java/net/masterthought/cucumber/ReportParser.java index 3e2da4a25..37eb33d94 100755 --- a/src/main/java/net/masterthought/cucumber/ReportParser.java +++ b/src/main/java/net/masterthought/cucumber/ReportParser.java @@ -8,7 +8,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.logging.Level; @@ -21,8 +20,10 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import net.masterthought.cucumber.json.Feature; import net.masterthought.cucumber.reducers.ReducingMethod; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Parameters; +import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.ArrayUtils; @@ -135,14 +136,20 @@ public void parseClassificationsFiles(List propertiesFiles) { } private void processClassificationFile(String file) { + FileBasedConfigurationBuilder builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) + .configure(new Parameters().properties().setFile(new File(file)) + .setThrowExceptionOnMissing(true)); try { - PropertiesConfiguration config = new PropertiesConfiguration(file); - Iterator keys = config.getKeys(); - while (keys.hasNext()) { - String key = keys.next(); - String value = config.getProperty(key).toString(); - this.configuration.addClassifications(key, value); - } + PropertiesConfiguration config = builder.getConfiguration(); + + config.getKeys().forEachRemaining(key -> { + if (config.getStringArray(key).length > 1) { + // Duplicate keys + this.configuration.addClassifications(key, Arrays.toString(config.getStringArray(key))); + } else { + this.configuration.addClassifications(key,config.getString(key)); + } + }); } catch (ConfigurationException e) { throw new ValidationException(String.format("File '%s' doesn't exist or the properties file is invalid!", file), e); }