Skip to content

Commit

Permalink
[configuration] Migrate to commons configuration2 and expose duplicat…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
hazendaz committed Dec 26, 2023
1 parent 9c2f398 commit d4e0f7c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/net/masterthought/cucumber/ReportParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -135,14 +136,20 @@ public void parseClassificationsFiles(List<String> propertiesFiles) {
}

private void processClassificationFile(String file) {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
.configure(new Parameters().properties().setFile(new File(file))
.setThrowExceptionOnMissing(true));
try {
PropertiesConfiguration config = new PropertiesConfiguration(file);
Iterator<String> 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);
}
Expand Down

0 comments on commit d4e0f7c

Please sign in to comment.