All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sitture.envconfig.EnvConfigFileList Maven / Gradle / Ivy

Go to download

A simple utility to manage environment configs in Java-based projects by merging *.properties files with environment variables overrides.

There is a newer version: 1.13.1
Show newest version
package com.github.sitture.envconfig;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

class EnvConfigFileList {

    protected final Path configPath;

    EnvConfigFileList(final Path configPath) {
        this.configPath = configPath;
    }

    public List listFiles() {
        final File configDir = configPath.toFile();
        if (!configDir.exists() || !configDir.isDirectory()) {
            throw new EnvConfigException(
                "'" + configPath + "' does not exist or not a valid config directory!");
        }
        return getConfigProperties(configDir);
    }

    protected List getConfigProperties(final File configDir) {
        final List files = Arrays.asList(Objects.requireNonNull(configDir.listFiles(new EnvConfigFileFilter())));
        if (files.isEmpty()) {
            throw new EnvConfigException("No property files found under '" + configDir.getPath() + "'");
        }
        return files;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy