de.monochromata.cucumber.report.config.ConfigurationFactory Maven / Gradle / Ivy
package de.monochromata.cucumber.report.config;
import static java.lang.Boolean.parseBoolean;
import static java.util.Optional.ofNullable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.presentation.PresentationMode;
import net.masterthought.cucumber.reducers.ReducingMethod;
import net.masterthought.cucumber.sorting.SortingMethod;
public class ConfigurationFactory {
private static final String DEFAULT_FILENAME = "cucumber-reporting.properties";
private static final String TAGS_TO_EXCLUDE_FROM_CHART_PATTERN = "^tagsToExcludeFromChart\\.\\d+$";
private static final String PRESENTATION_MODE_PREFIX = "presentationMode.";
private static final String REDUCING_METHOD_PREFIX = "reducingMethod.";
private static final String CLASSIFICATIONS_PREFIX = "classifications.";
public static final String CONFIG_FILE_PROPERTY = "cucumber.reporting.config.file";
public static Configuration getConfiguration(final File outputDir) {
final Properties properties = loadProperties();
final String projectName = properties.getProperty("projectName",
"No Name (add projectName to cucumber-reporting.properties)");
final Configuration configuration = new Configuration(outputDir, projectName);
configureBuildNumber(configuration, properties);
configureSortingMethod(configuration, properties);
configureTagsToExcludeFromChart(configuration, properties);
configureTrendsStatsFile(configuration, properties);
configureRepeatableConfigurationKeys(configuration, properties);
return configuration;
}
protected static void configureBuildNumber(final Configuration configuration, final Properties properties) {
configuration.setBuildNumber(properties.getProperty("buildNumber"));
}
protected static void configureSortingMethod(final Configuration configuration, final Properties properties) {
final String sortingMethod = properties.getProperty("sortingMethod");
if(StringUtils.isNotEmpty(sortingMethod)) {
configuration.setSortingMethod(Enum.valueOf(SortingMethod.class, sortingMethod));
}
}
protected static void configureTagsToExcludeFromChart(final Configuration configuration, final Properties properties) {
final String[] tagsToExclude = getTagsToExcludeFromChart(properties);
configuration.setTagsToExcludeFromChart(tagsToExclude);
}
protected static String[] getTagsToExcludeFromChart(final Properties properties) {
return properties.entrySet().stream()
.filter(entry -> ((String)entry.getKey()).matches(TAGS_TO_EXCLUDE_FROM_CHART_PATTERN))
.map(Entry::getValue)
.toArray(String[]::new);
}
protected static void configureTrendsStatsFile(final Configuration configuration, final Properties properties) {
String trendsStatsFile = properties.getProperty("trendsStatsFile");
if(StringUtils.isNotEmpty(trendsStatsFile)) {
configuration.setTrendsStatsFile(new File(trendsStatsFile));
}
}
protected static void configureRepeatableConfigurationKeys(final Configuration configuration, final Properties properties) {
final Enumeration
© 2015 - 2025 Weber Informatics LLC | Privacy Policy