org.flywaydb.commandline.configuration.ConfigurationManagerImpl Maven / Gradle / Ivy
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flywaydb.commandline.configuration;
import lombok.CustomLog;
import org.flywaydb.commandline.Main;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.configuration.ConfigUtils;
import org.flywaydb.core.internal.util.ClassUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static org.flywaydb.commandline.configuration.CommandLineConfigurationUtils.getTomlConfigFilePaths;
@CustomLog
public class ConfigurationManagerImpl implements ConfigurationManager {
public Configuration getConfiguration(CommandLineArguments commandLineArguments) {
ConfigurationManager configurationManager;
if(useModernConfig(commandLineArguments)) {
configurationManager = new ModernConfigurationManager();
} else {
configurationManager = new LegacyConfigurationManager();
}
return configurationManager.getConfiguration(commandLineArguments);
}
private boolean useModernConfig(CommandLineArguments commandLineArguments) {
List tomlFiles = new ArrayList<>();
tomlFiles.addAll(ConfigUtils.getDefaultTomlConfigFileLocations(new File(ClassUtils.getInstallDir(Main.class))));
tomlFiles.addAll(getTomlConfigFilePaths());
tomlFiles.addAll(commandLineArguments.getConfigFiles().stream()
.filter(f -> f.endsWith(".toml"))
.map(File::new)
.collect(Collectors.toList()));
return tomlFiles.stream().anyMatch(File::exists);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy